Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kuma-cp): force routing through zone egress #7558

Merged
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
11 changes: 5 additions & 6 deletions pkg/xds/topology/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func BuildEgressEndpointMap(
) core_xds.EndpointMap {
outbound := core_xds.EndpointMap{}

fillIngressOutbounds(outbound, zoneIngresses, nil, localZone, mesh, nil)
fillIngressOutbounds(outbound, zoneIngresses, nil, localZone, mesh, nil, false)

fillExternalServicesReachableFromZone(ctx, outbound, externalServices, mesh, loader, localZone)

Expand Down Expand Up @@ -71,7 +71,7 @@ func BuildEdsEndpointMap(
) core_xds.EndpointMap {
outbound := core_xds.EndpointMap{}

ingressInstances := fillIngressOutbounds(outbound, zoneIngresses, zoneEgresses, localZone, mesh, nil)
ingressInstances := fillIngressOutbounds(outbound, zoneIngresses, zoneEgresses, localZone, mesh, nil, mesh.ZoneEgressEnabled())
endpointWeight := uint32(1)
if ingressInstances > 0 {
endpointWeight = ingressInstances
Expand Down Expand Up @@ -188,6 +188,7 @@ func BuildCrossMeshEndpointMap(
localZone,
mesh,
otherMesh,
mesh.ZoneEgressEnabled(),
)

endpointWeight := uint32(1)
Expand Down Expand Up @@ -244,6 +245,7 @@ func fillIngressOutbounds(
localZone string,
mesh *core_mesh.MeshResource,
otherMesh *core_mesh.MeshResource, // otherMesh is set if we are looking for specific crossmesh connections
routeThroughZoneEgress bool,
) uint32 {
ziInstances := map[string]struct{}{}

Expand Down Expand Up @@ -319,7 +321,7 @@ func fillIngressOutbounds(
// ignore
// If zone egresses present, we want to pass the traffic:
// dp -> zone egress -> zone ingress -> dp
if mesh.ZoneEgressEnabled() && len(zoneEgresses) > 0 {
if routeThroughZoneEgress {
for _, ze := range zoneEgresses {
zeNetworking := ze.Spec.GetNetworking()
zeAddress := zeNetworking.GetAddress()
Expand Down Expand Up @@ -348,9 +350,6 @@ func fillIngressOutbounds(
Weight: serviceInstances,
Locality: locality,
}
if mesh.ZoneEgressEnabled() && service.ExternalService {
michaelbeaumont marked this conversation as resolved.
Show resolved Hide resolved
endpoint.ExternalService = &core_xds.ExternalService{}
}

outbound[serviceName] = append(outbound[serviceName], endpoint)
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/xds/topology/outbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,12 +1195,11 @@ var _ = Describe("TrafficRoute", func() {
expected: core_xds.EndpointMap{
"service-in-zone2": []core_xds.Endpoint{
{
Target: "192.168.0.100",
Port: 12345,
Tags: map[string]string{mesh_proto.ServiceTag: "service-in-zone2", mesh_proto.ZoneTag: "zone-2", "mesh": "default"},
Weight: 2, // local weight is bumped to 2 to factor two instances of Ingresses
Locality: &core_xds.Locality{Zone: "zone-2", Priority: 0},
ExternalService: &core_xds.ExternalService{},
Target: "192.168.0.100",
Port: 12345,
Tags: map[string]string{mesh_proto.ServiceTag: "service-in-zone2", mesh_proto.ZoneTag: "zone-2", "mesh": "default"},
Weight: 2, // local weight is bumped to 2 to factor two instances of Ingresses
Locality: &core_xds.Locality{Zone: "zone-2", Priority: 0},
},
},
"test": []core_xds.Endpoint{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ conf:

Expect(NewClusterSetup().
Install(Kuma(config_core.Zone, WithGlobalAddress(globalCP.GetKDSServerAddress()))). // do not deploy Egress
Install(IngressUniversal(global.GetKuma().GenerateZoneIngressToken)).
Install(DemoClientUniversal(
"zone4-demo-client",
nonDefaultMesh,
Expand All @@ -123,6 +124,10 @@ conf:
WithoutDataplane(),
WithVerbose())
}).
Install(TestServerUniversal("test-server", nonDefaultMesh,
WithArgs([]string{"echo", "--instance", "test-server"}),
WithTransparentProxy(true),
)).
Setup(zone4),
).To(Succeed())

Expand Down Expand Up @@ -161,6 +166,16 @@ conf:
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal("es-test-server"))
}, "30s", "1s").Should(Succeed())

By("reaching internal service from k8s")
Eventually(func(g Gomega) {
response, err := client.CollectEchoResponse(
zone1, "demo-client", "test-server.mesh",
client.FromKubernetesPod(TestNamespace, "demo-client"),
)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal("test-server"))
}, "30s", "1s").Should(Succeed())
})

It("passthrough false with zoneegress true", func() {
Expand All @@ -184,5 +199,15 @@ conf:
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Exitcode).To(Or(Equal(56), Equal(7), Equal(28)))
}, "30s", "1s").Should(Succeed())

By("not reaching internal service from k8s when zone egress is down")
Eventually(func(g Gomega) {
response, err := client.CollectFailure(
zone1, "demo-client", "test-server.mesh",
client.FromKubernetesPod(TestNamespace, "demo-client"),
)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Exitcode).To(Or(Equal(56), Equal(7), Equal(28)))
}, "30s", "1s").Should(Succeed())
})
}