From fe0e424d33d08d39d7abaaa238fbd84ba69bb856 Mon Sep 17 00:00:00 2001 From: Christoph Brand Date: Wed, 7 Mar 2018 18:53:50 +0100 Subject: [PATCH 1/2] Add Foreign Cloud support to Azure Provider (#485) --- provider/azure.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/provider/azure.go b/provider/azure.go index f23dc53845..1f287630e7 100644 --- a/provider/azure.go +++ b/provider/azure.go @@ -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{ From e499a737cbd71e4ab535670a7dfd8f1517bc250a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20J=C3=BCttner?= Date: Thu, 12 Apr 2018 14:58:48 +0200 Subject: [PATCH 2/2] Fix designate provider and tests (#522) --- provider/designate.go | 28 +++++++++++++++++++++------- provider/designate_test.go | 38 +++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/provider/designate.go b/provider/designate.go index 9f70dc759f..e3bfe7ae79 100644 --- a/provider/designate.go +++ b/provider/designate.go @@ -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 @@ -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 } diff --git a/provider/designate_test.go b/provider/designate_test.go index fe1579ff6c..05e01f4650 100644 --- a/provider/designate_test.go +++ b/provider/designate_test.go @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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) @@ -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{}, }, } @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,