Merge branch 'master' into issue-239-multiple-targets

This commit is contained in:
Gary Kramlich 2018-04-12 12:15:39 -05:00
commit 4d532e25e7
3 changed files with 44 additions and 32 deletions

View File

@ -112,9 +112,9 @@ func NewAzureProvider(configFile string, domainFilter DomainFilter, zoneIDFilter
return nil, fmt.Errorf("failed to create service principal token: %v", err) 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) zonesClient.Authorizer = autorest.NewBearerAuthorizer(token)
recordsClient := dns.NewRecordSetsClient(cfg.SubscriptionID) recordsClient := dns.NewRecordSetsClientWithBaseURI(environment.ResourceManagerEndpoint, cfg.SubscriptionID)
recordsClient.Authorizer = autorest.NewBearerAuthorizer(token) recordsClient.Authorizer = autorest.NewBearerAuthorizer(token)
provider := &AzureProvider{ provider := &AzureProvider{

View File

@ -241,12 +241,24 @@ func NewDesignateProvider(domainFilter DomainFilter, dryRun bool) (Provider, err
}, nil }, nil
} }
// converts domain name to FQDN // converts domain names to FQDN
func canonicalizeDomainName(domain string) string { func canonicalizeDomainNames(domains []string) []string {
if !strings.HasSuffix(domain, ".") { var cDomains []string
domain += "." for _, d := range domains {
if !strings.HasSuffix(d, ".") {
d += "."
cDomains = append(cDomains, strings.ToLower(d))
}
} }
return strings.ToLower(domain) return cDomains
}
// converts domain name to FQDN
func canonicalizeDomainName(d string) string {
if !strings.HasSuffix(d, ".") {
d += "."
}
return strings.ToLower(d)
} }
// returns ZoneID -> ZoneName mapping for zones that are managed by the Designate and match domain filter // returns ZoneID -> ZoneName mapping for zones that are managed by the Designate and match domain filter
@ -352,14 +364,14 @@ func addEndpoint(ep *endpoint.Endpoint, recordSets map[string]*recordSet, delete
rs.names[rec] = true rs.names[rec] = true
} }
} }
targets := ep.Targets
for _, target := range ep.Targets { if ep.RecordType == endpoint.RecordTypeCNAME {
if ep.RecordType == endpoint.RecordTypeCNAME { targets = canonicalizeDomainNames(targets)
target = canonicalizeDomainName(target)
}
rs.names[target] = !delete
recordSets[key] = rs
} }
for _, t := range targets {
rs.names[t] = !delete
}
recordSets[key] = rs
} }
// ApplyChanges applies a given set of changes in a given zone. // ApplyChanges applies a given set of changes in a given zone.

View File

@ -181,7 +181,7 @@ func TestDesignateRecords(t *testing.T) {
{ {
DNSName: "www.example.com", DNSName: "www.example.com",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.1"}, Targets: endpoint.Targets{"10.1.1.1"},
Labels: map[string]string{ Labels: map[string]string{
designateRecordSetID: rs11ID, designateRecordSetID: rs11ID,
designateZoneID: zone1ID, designateZoneID: zone1ID,
@ -191,7 +191,7 @@ func TestDesignateRecords(t *testing.T) {
{ {
DNSName: "www.example.com", DNSName: "www.example.com",
RecordType: endpoint.RecordTypeTXT, RecordType: endpoint.RecordTypeTXT,
Targets: []string{"text1"}, Targets: endpoint.Targets{"text1"},
Labels: map[string]string{ Labels: map[string]string{
designateRecordSetID: rs12ID, designateRecordSetID: rs12ID,
designateZoneID: zone1ID, designateZoneID: zone1ID,
@ -201,7 +201,7 @@ func TestDesignateRecords(t *testing.T) {
{ {
DNSName: "ftp.example.com", DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.2"}, Targets: endpoint.Targets{"10.1.1.2"},
Labels: map[string]string{ Labels: map[string]string{
designateRecordSetID: rs14ID, designateRecordSetID: rs14ID,
designateZoneID: zone1ID, designateZoneID: zone1ID,
@ -211,7 +211,7 @@ func TestDesignateRecords(t *testing.T) {
{ {
DNSName: "srv.test.net", DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.1"}, Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{ Labels: map[string]string{
designateRecordSetID: rs21ID, designateRecordSetID: rs21ID,
designateZoneID: zone2ID, designateZoneID: zone2ID,
@ -221,7 +221,7 @@ func TestDesignateRecords(t *testing.T) {
{ {
DNSName: "srv.test.net", DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.2"}, Targets: endpoint.Targets{"10.2.1.2"},
Labels: map[string]string{ Labels: map[string]string{
designateRecordSetID: rs21ID, designateRecordSetID: rs21ID,
designateZoneID: zone2ID, designateZoneID: zone2ID,
@ -231,7 +231,7 @@ func TestDesignateRecords(t *testing.T) {
{ {
DNSName: "db.test.net", DNSName: "db.test.net",
RecordType: endpoint.RecordTypeCNAME, RecordType: endpoint.RecordTypeCNAME,
Targets: []string{"sql.test.net"}, Targets: endpoint.Targets{"sql.test.net"},
Labels: map[string]string{ Labels: map[string]string{
designateRecordSetID: rs22ID, designateRecordSetID: rs22ID,
designateZoneID: zone2ID, designateZoneID: zone2ID,
@ -278,37 +278,37 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
{ {
DNSName: "www.example.com", DNSName: "www.example.com",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.1"}, Targets: endpoint.Targets{"10.1.1.1"},
Labels: map[string]string{}, Labels: map[string]string{},
}, },
{ {
DNSName: "www.example.com", DNSName: "www.example.com",
RecordType: endpoint.RecordTypeTXT, RecordType: endpoint.RecordTypeTXT,
Targets: []string{"text1"}, Targets: endpoint.Targets{"text1"},
Labels: map[string]string{}, Labels: map[string]string{},
}, },
{ {
DNSName: "ftp.example.com", DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.2"}, Targets: endpoint.Targets{"10.1.1.2"},
Labels: map[string]string{}, Labels: map[string]string{},
}, },
{ {
DNSName: "srv.test.net", DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.1"}, Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{}, Labels: map[string]string{},
}, },
{ {
DNSName: "srv.test.net", DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.2"}, Targets: endpoint.Targets{"10.2.1.2"},
Labels: map[string]string{}, Labels: map[string]string{},
}, },
{ {
DNSName: "db.test.net", DNSName: "db.test.net",
RecordType: endpoint.RecordTypeCNAME, RecordType: endpoint.RecordTypeCNAME,
Targets: []string{"sql.test.net"}, Targets: endpoint.Targets{"sql.test.net"},
Labels: map[string]string{}, Labels: map[string]string{},
}, },
} }
@ -389,7 +389,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{ {
DNSName: "ftp.example.com", DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.2"}, Targets: endpoint.Targets{"10.1.1.2"},
Labels: map[string]string{ Labels: map[string]string{
designateZoneID: "zone-1", designateZoneID: "zone-1",
designateRecordSetID: expected[2].ID, designateRecordSetID: expected[2].ID,
@ -399,7 +399,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{ {
DNSName: "srv.test.net.", DNSName: "srv.test.net.",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.2"}, Targets: endpoint.Targets{"10.2.1.2"},
Labels: map[string]string{ Labels: map[string]string{
designateZoneID: "zone-2", designateZoneID: "zone-2",
designateRecordSetID: expected[3].ID, designateRecordSetID: expected[3].ID,
@ -411,7 +411,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{ {
DNSName: "ftp.example.com", DNSName: "ftp.example.com",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.3.3.1"}, Targets: endpoint.Targets{"10.3.3.1"},
Labels: map[string]string{ Labels: map[string]string{
designateZoneID: "zone-1", designateZoneID: "zone-1",
designateRecordSetID: expected[2].ID, designateRecordSetID: expected[2].ID,
@ -421,7 +421,7 @@ func testDesignateUpdateRecords(t *testing.T, client *fakeDesignateClient) []*re
{ {
DNSName: "srv.test.net.", DNSName: "srv.test.net.",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.3.3.2"}, Targets: endpoint.Targets{"10.3.3.2"},
Labels: map[string]string{ Labels: map[string]string{
designateZoneID: "zone-2", designateZoneID: "zone-2",
designateRecordSetID: expected[3].ID, designateRecordSetID: expected[3].ID,
@ -472,7 +472,7 @@ func testDesignateDeleteRecords(t *testing.T, client *fakeDesignateClient) {
{ {
DNSName: "www.example.com.", DNSName: "www.example.com.",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.1.1.1"}, Targets: endpoint.Targets{"10.1.1.1"},
Labels: map[string]string{ Labels: map[string]string{
designateZoneID: "zone-1", designateZoneID: "zone-1",
designateRecordSetID: expected[0].ID, designateRecordSetID: expected[0].ID,
@ -482,7 +482,7 @@ func testDesignateDeleteRecords(t *testing.T, client *fakeDesignateClient) {
{ {
DNSName: "srv.test.net.", DNSName: "srv.test.net.",
RecordType: endpoint.RecordTypeA, RecordType: endpoint.RecordTypeA,
Targets: []string{"10.2.1.1"}, Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{ Labels: map[string]string{
designateZoneID: "zone-2", designateZoneID: "zone-2",
designateRecordSetID: expected[3].ID, designateRecordSetID: expected[3].ID,