Skip to content

Commit

Permalink
Merge branch 'master' into issue-239-multiple-targets
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmy committed Apr 12, 2018
2 parents 0e83547 + e499a73 commit 4d532e2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
4 changes: 2 additions & 2 deletions provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ func NewAzureProvider(configFile string, domainFilter DomainFilter, zoneIDFilter
return nil, fmt.Errorf("failed to create service principal token: %v", err)
}

zonesClient := dns.NewZonesClient(cfg.SubscriptionID)
zonesClient := dns.NewZonesClientWithBaseURI(environment.ResourceManagerEndpoint, cfg.SubscriptionID)
zonesClient.Authorizer = autorest.NewBearerAuthorizer(token)
recordsClient := dns.NewRecordSetsClient(cfg.SubscriptionID)
recordsClient := dns.NewRecordSetsClientWithBaseURI(environment.ResourceManagerEndpoint, cfg.SubscriptionID)
recordsClient.Authorizer = autorest.NewBearerAuthorizer(token)

provider := &AzureProvider{
Expand Down
34 changes: 23 additions & 11 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,14 +364,14 @@ func addEndpoint(ep *endpoint.Endpoint, recordSets map[string]*recordSet, delete
rs.names[rec] = true
}
}

for _, target := range ep.Targets {
if ep.RecordType == endpoint.RecordTypeCNAME {
target = canonicalizeDomainName(target)
}
rs.names[target] = !delete
recordSets[key] = rs
targets := ep.Targets
if ep.RecordType == endpoint.RecordTypeCNAME {
targets = canonicalizeDomainNames(targets)
}
for _, t := range targets {
rs.names[t] = !delete
}
recordSets[key] = rs
}

// ApplyChanges applies a given set of changes in a given zone.
Expand Down
36 changes: 18 additions & 18 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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"sql.test.net"},
Targets: endpoint.Targets{"sql.test.net"},
Labels: map[string]string{
designateRecordSetID: rs22ID,
designateZoneID: zone2ID,
Expand Down Expand Up @@ -278,37 +278,37 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
{
DNSName: "www.example.com",
RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.1"},
Targets: endpoint.Targets{"10.1.1.1"},
Labels: map[string]string{},
},
{
DNSName: "www.example.com",
RecordType: endpoint.RecordTypeTXT,
Targets: []string{"text1"},
Targets: endpoint.Targets{"text1"},
Labels: map[string]string{},
},
{
DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.2"},
Targets: endpoint.Targets{"10.1.1.2"},
Labels: map[string]string{},
},
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.1"},
Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{},
},
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.2"},
Targets: endpoint.Targets{"10.2.1.2"},
Labels: map[string]string{},
},
{
DNSName: "db.test.net",
RecordType: endpoint.RecordTypeCNAME,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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,
Targets: []string{"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 4d532e2

Please sign in to comment.