Skip to content

Commit

Permalink
Merge pull request #1013 from p53/fix-prefix-to-lower
Browse files Browse the repository at this point in the history
Fix txt prefix bug, should be lowercased because when writing to dns …
  • Loading branch information
k8s-ci-robot authored Sep 10, 2019
2 parents 74582ef + b685c73 commit 8da3b34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions registry/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ type prefixNameMapper struct {
var _ nameMapper = prefixNameMapper{}

func newPrefixNameMapper(prefix string) prefixNameMapper {
return prefixNameMapper{prefix: prefix}
return prefixNameMapper{prefix: strings.ToLower(prefix)}
}

func (pr prefixNameMapper) toEndpointName(txtDNSName string) string {
if strings.HasPrefix(txtDNSName, pr.prefix) {
return strings.TrimPrefix(txtDNSName, pr.prefix)
lowerDNSName := strings.ToLower(txtDNSName)
if strings.HasPrefix(lowerDNSName, pr.prefix) {
return strings.TrimPrefix(lowerDNSName, pr.prefix)
}
return ""
}
Expand Down
7 changes: 6 additions & 1 deletion registry/txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", endpoint.RecordTypeTXT, ""),
newEndpointWithOwnerAndLabels("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, "", endpoint.Labels{"tar": "sometar"}),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("TxT.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", endpoint.RecordTypeTXT, ""), // case-insensitive TXT prefix
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
Expand Down Expand Up @@ -140,6 +140,11 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
records, _ := r.Records()

assert.True(t, testutils.SameEndpoints(records, expectedRecords))

// Ensure prefix is case-insensitive
r, _ = NewTXTRegistry(p, "TxT.", "owner", time.Hour)
records, _ = r.Records()

assert.True(t, testutils.SameEndpointLabels(records, expectedRecords))
}

Expand Down

0 comments on commit 8da3b34

Please sign in to comment.