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): don't fail when 2 headless services pointing to the same service (backport of #7282) #7295

Merged
merged 1 commit into from
Jul 19, 2023
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
10 changes: 8 additions & 2 deletions pkg/dns/vips/virtual_outbound_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import (
"fmt"
"net"
"sort"

"github.com/kumahq/kuma/pkg/core"
)

var logger = core.Log.WithName("vips-outbound-view")

type VirtualOutboundMeshView struct {
byHostname map[HostnameEntry]*VirtualOutbound
}
Expand Down Expand Up @@ -47,9 +51,11 @@ func (vo *VirtualOutboundMeshView) Add(entry HostnameEntry, outbound OutboundEnt
return nil
}
if entry.Type == Host {
return fmt.Errorf("autogenerated DNS entry %s:%d from %s conflicts with existing entry %s, this happens when there are two external services with the same 'networking.address', to disable automatic DNS generation in external services set 'networking.disableHostDNSEntry=true' in at least one of these externalService", entry.Name, outbound.Port, outbound.Origin, existingOutbound.Origin)
logger.Error(fmt.Errorf("autogenerated DNS entry %s:%d from %s conflicts with existing entry %s", entry.Name, outbound.Port, outbound.Origin, existingOutbound.Origin), "there are two external services with the same 'networking.address' or two headless services, to disable automatic DNS generation in external services set 'networking.disableHostDNSEntry=true' in at least one of these externalService")
return nil
} else {
return fmt.Errorf("can't add %s:%d from %s because it's already used by entity defined in:'%s'", entry.Name, outbound.Port, outbound.Origin, existingOutbound.Origin)
logger.Error(fmt.Errorf("can't add %s:%d from %s because it's already used by entity defined in:'%s'", entry.Name, outbound.Port, outbound.Origin, existingOutbound.Origin), "failed to generate DNS entry")
return nil
}
}
}
Expand Down
67 changes: 26 additions & 41 deletions pkg/dns/vips_allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,53 +721,38 @@ var _ = DescribeTable("outboundView",
},
},
}),
)

type outboundViewErrorTestCase struct {
givenResources map[model.ResourceKey]model.Resource
buildError string
}

var _ = DescribeTable("outboundView",
func(tc outboundViewErrorTestCase) {
ctx := context.Background()
rm := resourceManagerWithResources(ctx, tc.givenResources)

// When
allocator, err := dns.NewVIPsAllocator(rm, nil, dns_server.Config{}, config.ExperimentalConfig{UseTagFirstVirtualOutboundModel: false}, "zone-a")
Expect(err).NotTo(HaveOccurred())
serviceSet, err := allocator.BuildVirtualOutboundMeshView(ctx, "mesh")

Expect(serviceSet).To(BeNil())
Expect(err.Error()).To(MatchRegexp(tc.buildError))
},
Entry("should fail when two external services with same address are defined without disableHostDNSEntry",
outboundViewErrorTestCase{
givenResources: map[model.ResourceKey]model.Resource{
model.WithMesh("mesh", "es-1"): &mesh.ExternalServiceResource{
Spec: &mesh_proto.ExternalService{
Networking: &mesh_proto.ExternalService_Networking{
Address: "external.service.com:8080",
},
Tags: map[string]string{
mesh_proto.ServiceTag: "my-external-service-1",
},
Entry("should not fail when two external services with same address are defined without disableHostDNSEntry", outboundViewTestCase{
givenResources: map[model.ResourceKey]model.Resource{
model.WithMesh("mesh", "es-1"): &mesh.ExternalServiceResource{
Spec: &mesh_proto.ExternalService{
Networking: &mesh_proto.ExternalService_Networking{
Address: "external.service.com:8080",
},
Tags: map[string]string{
mesh_proto.ServiceTag: "my-external-service-1",
},
},
model.WithMesh("mesh", "es-2"): &mesh.ExternalServiceResource{
Spec: &mesh_proto.ExternalService{
Networking: &mesh_proto.ExternalService_Networking{
Address: "external.service.com:8080",
},
Tags: map[string]string{
mesh_proto.ServiceTag: "my-external-service-2",
},
},
model.WithMesh("mesh", "es-2"): &mesh.ExternalServiceResource{
Spec: &mesh_proto.ExternalService{
Networking: &mesh_proto.ExternalService_Networking{
Address: "external.service.com:8080",
},
Tags: map[string]string{
mesh_proto.ServiceTag: "my-external-service-2",
},
},
},
buildError: "cannot add outbound for external service 'es-\\d': autogenerated DNS entry external.service.com:8080 from external-service:es-\\d conflicts with existing entry external-service:es-\\d, this happens when there are two external services with the same 'networking.address', to disable automatic DNS generation in external services set 'networking.disableHostDNSEntry=true' in at least one of these externalService",
},
),
whenSkipServiceVips: true,
whenMesh: "mesh",
thenHostnameEntries: []vips.HostnameEntry{vips.NewHostEntry("external.service.com")},
thenOutbounds: map[vips.HostnameEntry][]vips.OutboundEntry{
vips.NewHostEntry("external.service.com"): {
{TagSet: map[string]string{mesh_proto.ServiceTag: "my-external-service-1"}, Origin: "external-service:es-1", Port: 8080},
},
},
}),
)

var _ = Describe("AllocateVIPs", func() {
Expand Down