diff --git a/provider/zonefinder.go b/provider/zonefinder.go index 1e3354f40e..6eed204239 100644 --- a/provider/zonefinder.go +++ b/provider/zonefinder.go @@ -26,7 +26,7 @@ func (z zoneIDName) Add(zoneID, zoneName string) { func (z zoneIDName) FindZone(hostname string) (suitableZoneID, suitableZoneName string) { for zoneID, zoneName := range z { - if strings.HasSuffix(hostname, zoneName) { + if hostname == zoneName || strings.HasSuffix(hostname, "."+zoneName) { if suitableZoneName == "" || len(zoneName) > len(suitableZoneName) { suitableZoneID = zoneID suitableZoneName = zoneName diff --git a/provider/zonefinder_test.go b/provider/zonefinder_test.go index 09b3f03ba6..efadb4421a 100644 --- a/provider/zonefinder_test.go +++ b/provider/zonefinder_test.go @@ -33,15 +33,28 @@ func TestZoneIDName(t *testing.T) { "654321": "foo.qux.baz", }, z) + // simple entry in a domain zoneID, zoneName := z.FindZone("name.qux.baz") assert.Equal(t, "qux.baz", zoneName) assert.Equal(t, "123456", zoneID) + // simple entry in a domain's subdomain. zoneID, zoneName = z.FindZone("name.foo.qux.baz") assert.Equal(t, "foo.qux.baz", zoneName) assert.Equal(t, "654321", zoneID) + // no possible zone for entry zoneID, zoneName = z.FindZone("name.qux.foo") assert.Equal(t, "", zoneName) assert.Equal(t, "", zoneID) + + // entry's suffix matches a subdomain but doesn't belong there + zoneID, zoneName = z.FindZone("name-foo.qux.baz") + assert.Equal(t, "qux.baz", zoneName) + assert.Equal(t, "123456", zoneID) + + // entry is an exact match of the domain (e.g. azure provider) + zoneID, zoneName = z.FindZone("foo.qux.baz") + assert.Equal(t, "foo.qux.baz", zoneName) + assert.Equal(t, "654321", zoneID) }