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

fix(kuma-cp): deep copy tags when gen. outbounds (backport #5070) #5071

Merged
merged 2 commits into from
Sep 28, 2022
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
4 changes: 0 additions & 4 deletions pkg/xds/sync/proxy_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ var _ = Describe("Proxy Builder", func() {
{
Tags: map[string]string{
mesh_proto.ServiceTag: "service-in-zone-2",
"mesh": "default",
},
Instances: 1,
Mesh: "default",
Expand All @@ -147,7 +146,6 @@ var _ = Describe("Proxy Builder", func() {
Tags: map[string]string{
mesh_proto.ServiceTag: "external-service-in-zone-2",
mesh_proto.ZoneTag: "zone-2",
"mesh": "default",
},
Instances: 1,
Mesh: "default",
Expand All @@ -168,7 +166,6 @@ var _ = Describe("Proxy Builder", func() {
{
Tags: map[string]string{
mesh_proto.ServiceTag: "service-in-zone-2",
"mesh": "default",
},
Instances: 1,
Mesh: "default",
Expand All @@ -177,7 +174,6 @@ var _ = Describe("Proxy Builder", func() {
Tags: map[string]string{
mesh_proto.ServiceTag: "external-service-in-zone-2",
mesh_proto.ZoneTag: "zone-2",
"mesh": "default",
},
Instances: 1,
Mesh: "default",
Expand Down
27 changes: 16 additions & 11 deletions pkg/xds/topology/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func fillDataplaneOutbounds(
dpNetworking := dpSpec.GetNetworking()

for _, inbound := range dpNetworking.GetHealthyInbounds() {
inboundTags := inbound.GetTags()
inboundTags := cloneTags(inbound.GetTags())
serviceName := inboundTags[mesh_proto.ServiceTag]
inboundInterface := dpNetworking.ToInboundInterface(inbound)
inboundAddress := inboundInterface.DataplaneAdvertisedIP
Expand Down Expand Up @@ -325,7 +325,8 @@ func fillIngressOutbounds(
continue
}

serviceTags := service.GetTags()
// deep copy map to not modify tags in BuildRemoteEndpointMap
serviceTags := cloneTags(service.GetTags())
serviceName := serviceTags[mesh_proto.ServiceTag]
serviceInstances := service.GetInstances()
locality := localityFromTags(mesh, priorityRemote, serviceTags)
Expand All @@ -352,7 +353,7 @@ func fillIngressOutbounds(
}
// this is necessary for correct spiffe generation for dp when
// traffic is routed: egress -> ingress -> egress
if mesh.ZoneEgressEnabled() && service.ExternalService {
if service.ExternalService {
endpoint.ExternalService = &core_xds.ExternalService{}
}

Expand Down Expand Up @@ -427,10 +428,8 @@ func fillExternalServicesOutboundsThroughEgress(
mesh *core_mesh.MeshResource,
) {
for _, externalService := range externalServices {
serviceTags := map[string]string{}
for tag, value := range externalService.Spec.GetTags() { // deep copy map to not modify tags in ExternalService.
serviceTags[tag] = value
}
// deep copy map to not modify tags in ExternalService.
serviceTags := cloneTags(externalService.Spec.GetTags())
serviceName := serviceTags[mesh_proto.ServiceTag]
locality := localityFromTags(mesh, priorityRemote, serviceTags)

Expand Down Expand Up @@ -465,10 +464,8 @@ func NewExternalServiceEndpoint(
spec := externalService.Spec
tls := spec.GetNetworking().GetTls()
meshName := mesh.GetMeta().GetName()
tags := map[string]string{}
for tag, value := range spec.GetTags() { // deep copy map to not modify tags in ExternalService.
tags[tag] = value
}
// deep copy map to not modify tags in ExternalService.
tags := cloneTags(spec.GetTags())

caCert, err := loadBytes(tls.GetCaCert(), meshName, loader)
if err != nil {
Expand Down Expand Up @@ -514,6 +511,14 @@ func NewExternalServiceEndpoint(
}, nil
}

func cloneTags(tags map[string]string) map[string]string {
result := map[string]string{}
for tag, value := range tags {
result[tag] = value
}
return result
}

func loadBytes(ds *v1alpha1.DataSource, mesh string, loader datasource.Loader) ([]byte, error) {
if ds == nil {
return nil, nil
Expand Down