Skip to content

Commit

Permalink
Fix designate provider and tests (kubernetes-sigs#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
njuettner authored and linki committed Apr 12, 2018
1 parent 678d558 commit e499a73
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
28 changes: 21 additions & 7 deletions provider/designate.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,24 @@ func NewDesignateProvider(domainFilter DomainFilter, dryRun bool) (Provider, err
}, nil
}

// converts domain names to FQDN
func canonicalizeDomainNames(domains []string) []string {
var cDomains []string
for _, d := range domains {
if !strings.HasSuffix(d, ".") {
d += "."
cDomains = append(cDomains, strings.ToLower(d))
}
}
return cDomains
}

// converts domain name to FQDN
func canonicalizeDomainName(domain string) string {
if !strings.HasSuffix(domain, ".") {
domain += "."
func canonicalizeDomainName(d string) string {
if !strings.HasSuffix(d, ".") {
d += "."
}
return strings.ToLower(domain)
return strings.ToLower(d)
}

// returns ZoneID -> ZoneName mapping for zones that are managed by the Designate and match domain filter
Expand Down Expand Up @@ -352,11 +364,13 @@ func addEndpoint(ep *endpoint.Endpoint, recordSets map[string]*recordSet, delete
rs.names[rec] = true
}
}
target := ep.Target
targets := ep.Targets
if ep.RecordType == endpoint.RecordTypeCNAME {
target = canonicalizeDomainName(target)
targets = canonicalizeDomainNames(targets)
}
for _, t := range targets {
rs.names[t] = !delete
}
rs.names[target] = !delete
recordSets[key] = rs
}

Expand Down
38 changes: 19 additions & 19 deletions provider/designate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestDesignateRecords(t *testing.T) {
{
DNSName: "www.example.com",
RecordType: endpoint.RecordTypeA,
Target: "10.1.1.1",
Targets: endpoint.Targets{"10.1.1.1"},
Labels: map[string]string{
designateRecordSetID: rs11ID,
designateZoneID: zone1ID,
Expand All @@ -191,7 +191,7 @@ func TestDesignateRecords(t *testing.T) {
{
DNSName: "www.example.com",
RecordType: endpoint.RecordTypeTXT,
Target: "text1",
Targets: endpoint.Targets{"text1"},
Labels: map[string]string{
designateRecordSetID: rs12ID,
designateZoneID: zone1ID,
Expand All @@ -201,7 +201,7 @@ func TestDesignateRecords(t *testing.T) {
{
DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA,
Target: "10.1.1.2",
Targets: endpoint.Targets{"10.1.1.2"},
Labels: map[string]string{
designateRecordSetID: rs14ID,
designateZoneID: zone1ID,
Expand All @@ -211,7 +211,7 @@ func TestDesignateRecords(t *testing.T) {
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Target: "10.2.1.1",
Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{
designateRecordSetID: rs21ID,
designateZoneID: zone2ID,
Expand All @@ -221,7 +221,7 @@ func TestDesignateRecords(t *testing.T) {
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Target: "10.2.1.2",
Targets: endpoint.Targets{"10.2.1.2"},
Labels: map[string]string{
designateRecordSetID: rs21ID,
designateZoneID: zone2ID,
Expand All @@ -231,7 +231,7 @@ func TestDesignateRecords(t *testing.T) {
{
DNSName: "db.test.net",
RecordType: endpoint.RecordTypeCNAME,
Target: "sql.test.net",
Targets: endpoint.Targets{"sql.test.net"},
Labels: map[string]string{
designateRecordSetID: rs22ID,
designateZoneID: zone2ID,
Expand All @@ -252,7 +252,7 @@ out:
continue out
}
}
t.Errorf("unexpected endpoint %s/%s -> %s", ep.DNSName, ep.RecordType, ep.Target)
t.Errorf("unexpected endpoint %s/%s -> %s", ep.DNSName, ep.RecordType, ep.Targets)
}
if len(expected) != 0 {
t.Errorf("not all expected endpoints were returned. Remained: %v", expected)
Expand All @@ -278,37 +278,37 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
{
DNSName: "www.example.com",
RecordType: endpoint.RecordTypeA,
Target: "10.1.1.1",
Targets: endpoint.Targets{"10.1.1.1"},
Labels: map[string]string{},
},
{
DNSName: "www.example.com",
RecordType: endpoint.RecordTypeTXT,
Target: "text1",
Targets: endpoint.Targets{"text1"},
Labels: map[string]string{},
},
{
DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA,
Target: "10.1.1.2",
Targets: endpoint.Targets{"10.1.1.2"},
Labels: map[string]string{},
},
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Target: "10.2.1.1",
Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{},
},
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Target: "10.2.1.2",
Targets: endpoint.Targets{"10.2.1.2"},
Labels: map[string]string{},
},
{
DNSName: "db.test.net",
RecordType: endpoint.RecordTypeCNAME,
Target: "sql.test.net",
Targets: endpoint.Targets{"sql.test.net"},
Labels: map[string]string{},
},
}
Expand Down Expand Up @@ -389,7 +389,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{
DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA,
Target: "10.1.1.2",
Targets: endpoint.Targets{"10.1.1.2"},
Labels: map[string]string{
designateZoneID: "zone-1",
designateRecordSetID: expected[2].ID,
Expand All @@ -399,7 +399,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{
DNSName: "srv.test.net.",
RecordType: endpoint.RecordTypeA,
Target: "10.2.1.2",
Targets: endpoint.Targets{"10.2.1.2"},
Labels: map[string]string{
designateZoneID: "zone-2",
designateRecordSetID: expected[3].ID,
Expand All @@ -411,7 +411,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{
DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA,
Target: "10.3.3.1",
Targets: endpoint.Targets{"10.3.3.1"},
Labels: map[string]string{
designateZoneID: "zone-1",
designateRecordSetID: expected[2].ID,
Expand All @@ -421,7 +421,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{
DNSName: "srv.test.net.",
RecordType: endpoint.RecordTypeA,
Target: "10.3.3.2",
Targets: endpoint.Targets{"10.3.3.2"},
Labels: map[string]string{
designateZoneID: "zone-2",
designateRecordSetID: expected[3].ID,
Expand Down Expand Up @@ -472,7 +472,7 @@ func testDesignateDeleteRecords(t *testing.T, client *fakeDesignateClient) {
{
DNSName: "www.example.com.",
RecordType: endpoint.RecordTypeA,
Target: "10.1.1.1",
Targets: endpoint.Targets{"10.1.1.1"},
Labels: map[string]string{
designateZoneID: "zone-1",
designateRecordSetID: expected[0].ID,
Expand All @@ -482,7 +482,7 @@ func testDesignateDeleteRecords(t *testing.T, client *fakeDesignateClient) {
{
DNSName: "srv.test.net.",
RecordType: endpoint.RecordTypeA,
Target: "10.2.1.1",
Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{
designateZoneID: "zone-2",
designateRecordSetID: expected[3].ID,
Expand Down

0 comments on commit e499a73

Please sign in to comment.