Skip to content

Commit

Permalink
remaining test case resolved
Browse files Browse the repository at this point in the history
Signed-off-by: Viraj Kulkarni <[email protected]>
  • Loading branch information
Viraj Kulkarni committed Jan 8, 2025
1 parent 8e877df commit a7a0545
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions admiral/pkg/clusters/service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 19 additions & 20 deletions admiral/pkg/controller/admiral/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"})
Expand All @@ -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"})
Expand All @@ -492,15 +492,15 @@ 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"})
ignoreService2.Labels = map[string]string{"app": "test-service-ignored-later"}

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"})
Expand Down Expand Up @@ -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,
},
Expand All @@ -548,31 +548,31 @@ 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,
},
{
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,
},
{
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,
},
{
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,
},
Expand All @@ -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)
Expand Down

0 comments on commit a7a0545

Please sign in to comment.