diff --git a/pkg/catalog/ingress.go b/pkg/catalog/ingress.go index c3fc838549..710e5748fa 100644 --- a/pkg/catalog/ingress.go +++ b/pkg/catalog/ingress.go @@ -67,7 +67,7 @@ func (mc *MeshCatalog) getIngressTrafficPolicy(svc service.MeshService) (*traffi sourceServiceIdentities := mapset.NewSet() var trafficMatches []*trafficpolicy.IngressTrafficMatch for _, backend := range ingressBackendPolicy.Spec.Backends { - if backend.Name != svc.Name { + if backend.Name != svc.Name || backend.Port.Number != int(svc.TargetPort) { continue } @@ -154,6 +154,13 @@ func (mc *MeshCatalog) getIngressTrafficPolicy(svc service.MeshService) (*traffi trafficRoutingRules = append(trafficRoutingRules, routingRule) } + if len(trafficMatches) == 0 { + // Since no trafficMatches exist for this IngressBackend config, it implies that the given + // MeshService does not map to this IngressBackend config. + log.Debug().Msgf("No ingress traffic matches exist for MeshService %s, no ingress config required", svc.EnvoyLocalClusterName()) + return nil, nil + } + ingressBackendWithStatus.Status = policyV1alpha1.IngressBackendStatus{ CurrentStatus: "committed", Reason: "successfully committed by the system", diff --git a/pkg/catalog/ingress_test.go b/pkg/catalog/ingress_test.go index 267a8abe29..2ea26aa050 100644 --- a/pkg/catalog/ingress_test.go +++ b/pkg/catalog/ingress_test.go @@ -2652,6 +2652,45 @@ func TestGetIngressTrafficPolicy(t *testing.T) { }, expectError: false, }, + { + name: "MeshService.TargetPort does not match ingress backend port", + ingressBackendPolicyEnabled: true, + // meshSvc.TargetPort does not match ingressBackend.Spec.Backends[].Port.Number + meshSvc: service.MeshService{Name: "foo", Namespace: "testns", Protocol: "http", TargetPort: 90}, + ingressBackend: &policyV1alpha1.IngressBackend{ + ObjectMeta: metav1.ObjectMeta{ + Name: "ingress-backend-1", + Namespace: "testns", + }, + Spec: policyV1alpha1.IngressBackendSpec{ + Backends: []policyV1alpha1.BackendSpec{ + { + Name: "foo", + Port: policyV1alpha1.PortSpec{ + Number: 80, + Protocol: "http", + }, + }, + }, + Sources: []policyV1alpha1.IngressSourceSpec{ + { + Kind: policyV1alpha1.KindIPRange, + Name: "10.0.0.0/10", + }, + { + Kind: policyV1alpha1.KindIPRange, + Name: "20.0.0.0/10", + }, + { + Kind: policyV1alpha1.KindIPRange, + Name: "invalid", // should be ignored + }, + }, + }, + }, + expectedPolicy: nil, + expectError: false, + }, } for _, tc := range testCases {