Skip to content

Commit

Permalink
fix(kuma-cp): don't fail when 2 headless services pointing to the sam…
Browse files Browse the repository at this point in the history
…e service (#7282)

Signed-off-by: Lukasz Dziedziak <lukidzi@gmail.com>
  • Loading branch information
lukidzi authored Jul 19, 2023
1 parent dd95f22 commit 7f5680d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 43 deletions.
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

0 comments on commit 7f5680d

Please sign in to comment.