Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

catalog/ingress: check backend's port in addition to name #4202

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/catalog/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions pkg/catalog/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down