From a7a0545141999ced38608e4338198ac53f7453c8 Mon Sep 17 00:00:00 2001 From: Viraj Kulkarni Date: Tue, 7 Jan 2025 18:09:01 -0800 Subject: [PATCH] remaining test case resolved Signed-off-by: Viraj Kulkarni --- admiral/pkg/clusters/service_handler.go | 4 +- .../pkg/controller/admiral/service_test.go | 39 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/admiral/pkg/clusters/service_handler.go b/admiral/pkg/clusters/service_handler.go index b0b9cfae5..e2f3b3a48 100644 --- a/admiral/pkg/clusters/service_handler.go +++ b/admiral/pkg/clusters/service_handler.go @@ -102,7 +102,7 @@ func handleServiceEventForDeployment( return fmt.Errorf(AlertLogMsg, ctx.Value(common.EventType)) } - if common.IsIstioIngressGatewayService(svc, "") { + if common.IsIstioIngressGatewayService(svc, common.GetAdmiralParams().LabelSet.GatewayApp) { // The eventType is overridden to admiral.Update. This is mainly // for admiral.Delete events sent for the ingress in the cluster // else it would delete all the SEs in the source and dependent clusters @@ -165,7 +165,7 @@ func handleServiceEventForRollout( return fmt.Errorf(AlertLogMsg, ctx.Value(common.EventType)) } - if common.IsIstioIngressGatewayService(svc, "") { + if common.IsIstioIngressGatewayService(svc, common.GetAdmiralParams().LabelSet.GatewayApp) { // The eventType is overridden to admiral.Update. This is mainly // for admiral.Delete events sent for the ingress in the cluster // else it would delete all the SEs in the source and dependent clusters diff --git a/admiral/pkg/controller/admiral/service_test.go b/admiral/pkg/controller/admiral/service_test.go index 4faa7f3d0..9743b9138 100644 --- a/admiral/pkg/controller/admiral/service_test.go +++ b/admiral/pkg/controller/admiral/service_test.go @@ -291,24 +291,24 @@ func TestServiceCache_GetLoadBalancer(t *testing.T) { service := &coreV1.Service{} service.Name = "test-service" - service.Namespace = "istio-system" + service.Namespace = common.NamespaceIstioSystem service.Status = coreV1.ServiceStatus{} service.Status.LoadBalancer = coreV1.LoadBalancerStatus{} service.Status.LoadBalancer.Ingress = append(service.Status.LoadBalancer.Ingress, coreV1.LoadBalancerIngress{Hostname: "hostname.com"}) - service.Labels = map[string]string{"app": "istio-ingressgateway"} + service.Labels = map[string]string{"app": common.IstioIngressGatewayLabelValue} s2 := &coreV1.Service{} s2.Name = "test-service-ip" - s2.Namespace = "istio-system" + s2.Namespace = common.NamespaceIstioSystem s2.Status = coreV1.ServiceStatus{} s2.Status.LoadBalancer = coreV1.LoadBalancerStatus{} s2.Status.LoadBalancer.Ingress = append(s2.Status.LoadBalancer.Ingress, coreV1.LoadBalancerIngress{IP: "1.2.3.4"}) - s2.Labels = map[string]string{"app": "istio-ingressgateway"} + s2.Labels = map[string]string{"app": common.IstioIngressGatewayLabelValue} // The primary use case is to support ingress gateways for local development externalIPService := &coreV1.Service{} externalIPService.Name = "test-service-externalip" - externalIPService.Namespace = "istio-system" + externalIPService.Namespace = common.NamespaceIstioSystem externalIPService.Spec = coreV1.ServiceSpec{} externalIPService.Spec.ExternalIPs = []string{"1.2.3.4"} externalIPService.Spec.Ports = []coreV1.ServicePort{ @@ -375,7 +375,7 @@ func TestServiceCache_GetLoadBalancer(t *testing.T) { { name: "Find service load balancer when present", cache: &sc, - key: "istio-ingressgateway", + key: common.IstioIngressGatewayLabelValue, ns: common.NamespaceIstioSystem, expectedReturn: "hostname.com", expectedPort: common.DefaultMtlsPort, @@ -391,7 +391,7 @@ func TestServiceCache_GetLoadBalancer(t *testing.T) { { name: "Falls back to IP", cache: &sc_fallbackToIp, - key: "istio-ingressgateway", + key: common.IstioIngressGatewayLabelValue, ns: common.NamespaceIstioSystem, expectedReturn: "1.2.3.4", expectedPort: common.DefaultMtlsPort, @@ -450,15 +450,15 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { service := &coreV1.Service{} service.Name = "test-service" - service.Namespace = "ns" + service.Namespace = common.NamespaceIstioSystem service.Status = coreV1.ServiceStatus{} service.Status.LoadBalancer = coreV1.LoadBalancerStatus{} service.Status.LoadBalancer.Ingress = append(service.Status.LoadBalancer.Ingress, coreV1.LoadBalancerIngress{Hostname: "hostname.com"}) - service.Labels = map[string]string{"app": "test-service"} + service.Labels = map[string]string{"app": common.IstioIngressGatewayLabelValue} s2 := &coreV1.Service{} s2.Name = "test-service-ip" - s2.Namespace = "ns" + s2.Namespace = common.NamespaceIstioSystem s2.Status = coreV1.ServiceStatus{} s2.Status.LoadBalancer = coreV1.LoadBalancerStatus{} s2.Status.LoadBalancer.Ingress = append(s2.Status.LoadBalancer.Ingress, coreV1.LoadBalancerIngress{IP: "1.2.3.4"}) @@ -483,7 +483,7 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { ignoreService := &coreV1.Service{} ignoreService.Name = "test-service-ignored" - ignoreService.Namespace = "ns" + ignoreService.Namespace = common.NamespaceIstioSystem ignoreService.Status = coreV1.ServiceStatus{} ignoreService.Status.LoadBalancer = coreV1.LoadBalancerStatus{} ignoreService.Status.LoadBalancer.Ingress = append(service.Status.LoadBalancer.Ingress, coreV1.LoadBalancerIngress{Hostname: "hostname.com"}) @@ -492,7 +492,7 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { ignoreService2 := &coreV1.Service{} ignoreService2.Name = "test-service-ignored-later" - ignoreService2.Namespace = "ns" + ignoreService2.Namespace = common.NamespaceIstioSystem ignoreService2.Status = coreV1.ServiceStatus{} ignoreService2.Status.LoadBalancer = coreV1.LoadBalancerStatus{} ignoreService2.Status.LoadBalancer.Ingress = append(service.Status.LoadBalancer.Ingress, coreV1.LoadBalancerIngress{Hostname: "hostname.com"}) @@ -500,7 +500,7 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { ignoreService3 := &coreV1.Service{} ignoreService3.Name = "test-service-unignored-later" - ignoreService3.Namespace = "ns" + ignoreService3.Namespace = common.NamespaceIstioSystem ignoreService3.Status = coreV1.ServiceStatus{} ignoreService3.Status.LoadBalancer = coreV1.LoadBalancerStatus{} ignoreService3.Status.LoadBalancer.Ingress = append(service.Status.LoadBalancer.Ingress, coreV1.LoadBalancerIngress{Hostname: "hostname.com"}) @@ -531,8 +531,8 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { { name: "Given service and loadbalancer, should return endpoint with dot in the end", cache: &sc, - key: "test-service", - ns: "ns", + key: common.IstioIngressGatewayLabelValue, + ns: common.NamespaceIstioSystem, expectedReturn: "hostname.com.", expectedPort: common.DefaultMtlsPort, }, @@ -548,7 +548,7 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { name: "Given host not present in load balancer, should fallback to IP without dot at the end", cache: &sc, key: "test-service-ip", - ns: "ns", + ns: common.NamespaceIstioSystem, expectedReturn: "1.2.3.4", expectedPort: common.DefaultMtlsPort, }, @@ -556,7 +556,7 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { name: "Given ignore label, should return dummy", cache: &sc, key: "test-service-ignored", - ns: "ns", + ns: common.NamespaceIstioSystem, expectedReturn: "dummy.admiral.global", expectedPort: common.DefaultMtlsPort, }, @@ -564,7 +564,7 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { name: "Successfully ignores services when the ignore label is added after the service had been added to the cache for the first time", cache: &sc, key: "test-service-ignored-later", - ns: "ns", + ns: common.NamespaceIstioSystem, expectedReturn: "dummy.admiral.global", expectedPort: common.DefaultMtlsPort, }, @@ -572,7 +572,7 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { name: "Successfully finds services when the ignore label is added initially, then removed", cache: &sc, key: "test-service-unignored-later", - ns: "ns", + ns: common.NamespaceIstioSystem, expectedReturn: "hostname.com.", expectedPort: common.DefaultMtlsPort, }, @@ -590,7 +590,6 @@ func TestServiceCache_GetLoadBalancerWithAbsoluteFQDN(t *testing.T) { func setAbsoluteFQDN(flag bool) { admiralParams := common.GetAdmiralParams() - //admiralParams.LabelSet.GatewayApp = "istio-ingressgateway" admiralParams.EnableAbsoluteFQDN = flag common.ResetSync() common.InitializeConfig(admiralParams)