github.com/kiali/kiali@v1.84.0/kubernetes/cache/proxy_status.go (about)

     1  package cache
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/kiali/kiali/kubernetes"
     7  )
     8  
     9  func proxyStatusKey(cluster, namespace, pod string) string {
    10  	return cluster + namespace + pod
    11  }
    12  
    13  type ProxyStatusCache interface {
    14  	SetPodProxyStatus([]*kubernetes.ProxyStatus)
    15  	GetPodProxyStatus(cluster, namespace, pod string) *kubernetes.ProxyStatus
    16  }
    17  
    18  func (c *kialiCacheImpl) SetPodProxyStatus(proxyStatus []*kubernetes.ProxyStatus) {
    19  	podProxyByID := make(map[string]*kubernetes.ProxyStatus)
    20  	for _, ps := range proxyStatus {
    21  		if ps != nil {
    22  			// Expected format <pod-name>.<namespace>
    23  			// "proxy": "control-7bcc64d69d-qzsdk.travel-control"
    24  			podId := strings.Split(ps.ProxyID, ".")
    25  			if len(podId) == 2 {
    26  				pod := podId[0]
    27  				ns := podId[1]
    28  				cluster := ps.ClusterID
    29  				key := proxyStatusKey(cluster, ns, pod)
    30  				podProxyByID[key] = ps
    31  			}
    32  		}
    33  	}
    34  	c.proxyStatusStore.Replace(podProxyByID)
    35  }
    36  
    37  func (c *kialiCacheImpl) GetPodProxyStatus(cluster, namespace, pod string) *kubernetes.ProxyStatus {
    38  	key := proxyStatusKey(cluster, namespace, pod)
    39  	proxyStatus, found := c.proxyStatusStore.Get(key)
    40  	if !found {
    41  		return nil
    42  	}
    43  	return proxyStatus
    44  }