github.com/kiali/kiali@v1.84.0/graph/telemetry/istio/appender/ambient.go (about)

     1  package appender
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/kiali/kiali/config"
     7  	"github.com/kiali/kiali/graph"
     8  	"github.com/kiali/kiali/log"
     9  )
    10  
    11  const AmbientAppenderName = "ambient"
    12  const WaypointSuffix = "-istio-waypoint"
    13  
    14  type AmbientAppender struct {
    15  	Waypoints bool
    16  }
    17  
    18  // Name implements Appender
    19  func (a AmbientAppender) Name() string {
    20  	return AmbientAppenderName
    21  }
    22  
    23  // IsFinalizer implements Appender
    24  func (a AmbientAppender) IsFinalizer() bool {
    25  	return true
    26  }
    27  
    28  // AppendGraph implements Appender
    29  func (a AmbientAppender) AppendGraph(trafficMap graph.TrafficMap, globalInfo *graph.AppenderGlobalInfo, namespaceInfo *graph.AppenderNamespaceInfo) {
    30  	if len(trafficMap) == 0 {
    31  		return
    32  	}
    33  
    34  	log.Trace("Running ambient appender")
    35  
    36  	a.handleWaypoints(trafficMap, globalInfo, !a.Waypoints)
    37  }
    38  
    39  func (a AmbientAppender) handleWaypoints(trafficMap graph.TrafficMap, globalInfo *graph.AppenderGlobalInfo, remove bool) {
    40  
    41  	for name, n := range trafficMap {
    42  
    43  		// It could be a waypoint proxy
    44  		if strings.HasSuffix(name, WaypointSuffix) {
    45  			var workloadName string
    46  			if n.Workload != "" {
    47  				workloadName = n.Workload
    48  			} else {
    49  				workloadName = n.App
    50  			}
    51  			workload, found := getWorkload(n.Cluster, n.Namespace, workloadName, globalInfo)
    52  			if !found {
    53  				log.Errorf("Error getting waypoint proxy: Workload %s was not found", n.Workload)
    54  				continue
    55  			}
    56  			for k, l := range workload.Labels {
    57  				if k == config.WaypointLabel && l == config.WaypointLabelValue {
    58  					if remove {
    59  						delete(trafficMap, n.ID)
    60  						break
    61  					} else {
    62  						n.Metadata[graph.IsWaypoint] = true
    63  						n.Metadata[graph.IsOutOfMesh] = false
    64  						break
    65  					}
    66  				}
    67  			}
    68  		}
    69  	}
    70  }