github.com/kiali/kiali@v1.84.0/business/checkers/gateways/selector_checker.go (about) 1 package gateways 2 3 import ( 4 networking_v1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1" 5 "k8s.io/apimachinery/pkg/labels" 6 7 "github.com/kiali/kiali/models" 8 ) 9 10 type SelectorChecker struct { 11 WorkloadsPerNamespace map[string]models.WorkloadList 12 Gateway *networking_v1beta1.Gateway 13 IsGatewayToNamespace bool 14 } 15 16 // Check verifies that the Gateway's selector's labels do match a known service inside the same namespace as recommended/required by the docs 17 func (s SelectorChecker) Check() ([]*models.IstioCheck, bool) { 18 validations := make([]*models.IstioCheck, 0) 19 if !s.hasMatchingWorkload(s.Gateway.Spec.Selector) { 20 validation := models.Build("gateways.selector", "spec/selector") 21 validations = append(validations, &validation) 22 } 23 return validations, len(validations) == 0 24 } 25 26 func (s SelectorChecker) hasMatchingWorkload(labelSelector map[string]string) bool { 27 selector := labels.SelectorFromSet(labelSelector) 28 29 for _, wls := range s.WorkloadsPerNamespace { 30 if s.IsGatewayToNamespace && wls.Namespace != s.Gateway.Namespace { 31 continue 32 } 33 for _, wl := range wls.Workloads { 34 wlLabelSet := labels.Set(wl.Labels) 35 if selector.Matches(wlLabelSet) { 36 return true 37 } 38 } 39 } 40 return false 41 }