Skip to content

Commit

Permalink
txt prefix - just concatenate, remove spew, fix txt record label
Browse files Browse the repository at this point in the history
  • Loading branch information
ideahitme committed Apr 11, 2017
1 parent 077fe88 commit 268e1f7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 49 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (cfg *Config) ParseFlags(args []string) error {
flags.BoolVar(&cfg.Version, "version", false, "display the version")
flags.StringVar(&cfg.Registry, "registry", "noop", "type of registry for ownership: <noop|txt>")
flags.StringVar(&cfg.RecordOwnerID, "record-owner-id", "", "id of the current external dns for labeling owned records")
flags.StringVar(&cfg.TXTPrefix, "txt-prefix", "", `prefix of the associated TXT records DNS name; if --txt-prefix=abc,
corresponding txt record for CNAME [example.org] will have DNSName [abc.example.org]. Required for CNAME support`)
flags.StringVar(&cfg.TXTPrefix, "txt-prefix", "", `prefix of the associated TXT records DNS name; if --txt-prefix="abc-",
corresponding txt record for CNAME [example.org] will have DNSName [abc-example.org]. Required for CNAME ownership support`)
return flags.Parse(args)
}
2 changes: 0 additions & 2 deletions provider/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/davecgh/go-spew/spew"

"github.com/kubernetes-incubator/external-dns/endpoint"
"github.com/kubernetes-incubator/external-dns/internal/testutils"
Expand Down Expand Up @@ -513,7 +512,6 @@ func TestAWSSanitizeZone(t *testing.T) {

func validateEndpoints(t *testing.T, endpoints []*endpoint.Endpoint, expected []*endpoint.Endpoint) {
if !testutils.SameEndpoints(endpoints, expected) {
spew.Dump(endpoints, expected)
t.Fatalf("expected %v, got %v", expected, endpoints)
}
}
Expand Down
29 changes: 3 additions & 26 deletions registry/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
)

var (
txtLabelRegex = regexp.MustCompile("^heritage=external-dns;record-owner-id=(.+)")
txtLabelFormat = "heritage=external-dns;record-owner-id=%s"
txtLabelRegex = regexp.MustCompile("^heritage=external-dns;external-dns/record-owner-id=(.+)")
txtLabelFormat = "heritage=external-dns;external-dns/record-owner-id=%s"
)

// TXTRegistry implements registry interface with ownership implemented via associated TXT records
Expand All @@ -46,12 +46,7 @@ func NewTXTRegistry(provider provider.Provider, txtPrefix, ownerID string) (*TXT
return nil, errors.New("owner id cannot be empty")
}

var mapper nameMapper
if txtPrefix == "" {
mapper = newNoopNameMapper()
} else {
mapper = newPrefixNameMapper(txtPrefix)
}
mapper := newPrefixNameMapper(txtPrefix)

return &TXTRegistry{
provider: provider,
Expand Down Expand Up @@ -150,7 +145,6 @@ type prefixNameMapper struct {
var _ nameMapper = prefixNameMapper{}

func newPrefixNameMapper(prefix string) prefixNameMapper {
prefix = strings.TrimSuffix(prefix, ".") + "."
return prefixNameMapper{prefix: prefix}
}

Expand All @@ -164,20 +158,3 @@ func (pr prefixNameMapper) toEndpointName(txtDNSName string) string {
func (pr prefixNameMapper) toTXTName(endpointDNSName string) string {
return pr.prefix + endpointDNSName
}

type noopNameMapper struct {
}

var _ nameMapper = noopNameMapper{}

func newNoopNameMapper() *noopNameMapper {
return &noopNameMapper{}
}

func (pr noopNameMapper) toEndpointName(txtDNSName string) string {
return txtDNSName
}

func (pr noopNameMapper) toTXTName(endpointDNSName string) string {
return endpointDNSName
}
38 changes: 19 additions & 19 deletions registry/txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func testTXTRegistryNew(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if _, ok := r.mapper.(*noopNameMapper); !ok {
if _, ok := r.mapper.(prefixNameMapper); !ok {
t.Error("Incorrect type of prefix name mapper")
}

Expand All @@ -79,13 +79,13 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner-2", "TXT", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner-2", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
})
expectedRecords := []*endpoint.Endpoint{
Expand Down Expand Up @@ -139,7 +139,7 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
},
}

r, _ := NewTXTRegistry(p, "txt", "owner")
r, _ := NewTXTRegistry(p, "txt.", "owner")
records, _ := r.Records(testZone)
if !testutils.SameEndpoints(records, expectedRecords) {
t.Error("incorrect result returned from txt registry")
Expand All @@ -153,13 +153,13 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner-2", "TXT", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner-2", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
})
expectedRecords := []*endpoint.Endpoint{
Expand Down Expand Up @@ -233,16 +233,16 @@ func testTXTRegistryApplyChangesWithPrefix(t *testing.T) {
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
})
r, _ := NewTXTRegistry(p, "txt", "owner")
r, _ := NewTXTRegistry(p, "txt.", "owner")

changes := &plan.Changes{
Create: []*endpoint.Endpoint{
Expand All @@ -261,11 +261,11 @@ func testTXTRegistryApplyChangesWithPrefix(t *testing.T) {
expected := &plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("new-record-1.test-zone.example.org", "new-loadbalancer-1.lb.com", "", ""),
newEndpointWithOwner("txt.new-record-1.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.new-record-1.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
Delete: []*endpoint.Endpoint{
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
UpdateNew: []*endpoint.Endpoint{
newEndpointWithOwner("tar.test-zone.example.org", "new-tar.loadbalancer.com", "ALIAS", "owner"),
Expand Down Expand Up @@ -311,13 +311,13 @@ func testTXTRegistryApplyChangesNoPrefix(t *testing.T) {
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
})
r, _ := NewTXTRegistry(p, "", "owner")
Expand All @@ -339,11 +339,11 @@ func testTXTRegistryApplyChangesNoPrefix(t *testing.T) {
expected := &plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("new-record-1.test-zone.example.org", "new-loadbalancer-1.lb.com", "", ""),
newEndpointWithOwner("new-record-1.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("new-record-1.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
Delete: []*endpoint.Endpoint{
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;record-owner-id=owner", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "heritage=external-dns;external-dns/record-owner-id=owner", "TXT", ""),
},
UpdateNew: []*endpoint.Endpoint{},
UpdateOld: []*endpoint.Endpoint{},
Expand Down

0 comments on commit 268e1f7

Please sign in to comment.