From 28964447a04577b34339e399eb71215ca4ccf9c7 Mon Sep 17 00:00:00 2001 From: Eric Lordahl Date: Thu, 14 Jun 2018 00:18:45 -0400 Subject: [PATCH] AWS provider: Properly check suitable domains --- provider/aws.go | 2 +- provider/aws_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/provider/aws.go b/provider/aws.go index 63376c44bf..8d921c4b05 100644 --- a/provider/aws.go +++ b/provider/aws.go @@ -435,7 +435,7 @@ func suitableZones(hostname string, zones map[string]*route53.HostedZone) []*rou var publicZone *route53.HostedZone for _, z := range zones { - if strings.HasSuffix(hostname, aws.StringValue(z.Name)) { + if aws.StringValue(z.Name) == hostname || strings.HasSuffix(hostname, "."+aws.StringValue(z.Name)) { if z.Config == nil || !aws.BoolValue(z.Config.PrivateZone) { // Only select the best matching public zone if publicZone == nil || len(aws.StringValue(z.Name)) > len(aws.StringValue(publicZone.Name)) { diff --git a/provider/aws_test.go b/provider/aws_test.go index d215d903c6..fbe085d6d9 100644 --- a/provider/aws_test.go +++ b/provider/aws_test.go @@ -781,6 +781,12 @@ func TestAWSSuitableZones(t *testing.T) { }{ {"foo.bar.example.org.", []*route53.HostedZone{zones["example-org-private"], zones["bar-example-org-private"], zones["bar-example-org"]}}, {"foo.example.org.", []*route53.HostedZone{zones["example-org-private"], zones["example-org"]}}, + + // bar.example.org is NOT suitable + {"foobar.example.org.", []*route53.HostedZone{zones["example-org-private"], zones["example-org"]}}, + + // all matching private zones are suitable (i'm not sure why) + {"bar.example.org.", []*route53.HostedZone{zones["example-org-private"], zones["bar-example-org-private"], zones["bar-example-org"]}}, {"foo.kubernetes.io.", nil}, } { suitableZones := suitableZones(tc.hostname, zones)