From 394f46cd64a76b19d422e36f4879d506eb409a67 Mon Sep 17 00:00:00 2001 From: Tariq Ibrahim Date: Thu, 23 Jan 2020 14:07:40 -0800 Subject: [PATCH] uprade golangci-lint and add megacheck & interface linters --- .golangci.yml | 3 +- .travis.yml | 2 +- endpoint/labels_test.go | 1 - provider/akamai.go | 10 -- provider/akamai_test.go | 5 +- provider/alibaba_cloud.go | 1 - provider/aws.go | 2 +- provider/aws_test.go | 8 +- provider/azure_private_dns.go | 11 +- provider/cloudflare_test.go | 226 ----------------------------- provider/digital_ocean_test.go | 258 --------------------------------- provider/dnsimple_test.go | 2 - provider/dyn.go | 15 +- provider/google_test.go | 2 - provider/ns1.go | 2 +- provider/rcode0_test.go | 9 -- source/cloudfoundry.go | 1 - source/crd_test.go | 2 +- source/gateway.go | 13 +- source/ingress.go | 2 +- source/ingressroute.go | 2 +- source/node.go | 2 +- source/service.go | 6 +- 23 files changed, 19 insertions(+), 566 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 565c910957..3c9495ef9b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,4 +19,5 @@ linters: - goimports - misspell - unconvert - - staticcheck + - megacheck + - interfacer diff --git a/.travis.yml b/.travis.yml index 72e5ebddbb..5368e04355 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ matrix: - go: tip env: -- GOLANGCI_RELEASE="v1.22.2" +- GOLANGCI_RELEASE="v1.23.1" before_install: - GO111MODULE=off go get github.com/mattn/goveralls diff --git a/endpoint/labels_test.go b/endpoint/labels_test.go index a8783db604..05d57758ea 100644 --- a/endpoint/labels_test.go +++ b/endpoint/labels_test.go @@ -31,7 +31,6 @@ type LabelsSuite struct { barText string barTextAsMap Labels noHeritageText string - noHeritageAsMap Labels wrongHeritageText string multipleHeritageText string //considered invalid } diff --git a/provider/akamai.go b/provider/akamai.go index 5ef8d7311e..d141580a7d 100644 --- a/provider/akamai.go +++ b/provider/akamai.go @@ -289,16 +289,6 @@ func (p *AkamaiProvider) newAkamaiRecord(dnsName, recordType string, targets ... } } -func (p *AkamaiProvider) newAkamaiRecordsets(dnsName, recordType string, targets ...string) *akamaiRecordsets { - akamaiRecords := make([]akamaiRecord, 0) - akamaiRecord := p.newAkamaiRecord(dnsName, recordType, targets...) - akamaiRecords = append(akamaiRecords, *akamaiRecord) - - return &akamaiRecordsets{ - Recordsets: akamaiRecords, - } -} - func (p *AkamaiProvider) createRecords(zoneNameIDMapper zoneIDName, endpoints []*endpoint.Endpoint) (created []*endpoint.Endpoint, failed []*endpoint.Endpoint) { for _, endpoint := range endpoints { diff --git a/provider/akamai_test.go b/provider/akamai_test.go index 85bce13903..36260b5bbe 100644 --- a/provider/akamai_test.go +++ b/provider/akamai_test.go @@ -62,10 +62,7 @@ func (m *mockAkamaiClient) Do(config edgegrid.Config, req *http.Request) (*http. handler := func(w http.ResponseWriter, r *http.Request) (isError bool) { b, _ := ioutil.ReadAll(r.Body) io.WriteString(w, string(b)) - if string(b) == "{\"status\": 404 }" { - return true - } - return false + return string(b) == "{\"status\": 404 }" } w := httptest.NewRecorder() err := handler(w, req) diff --git a/provider/alibaba_cloud.go b/provider/alibaba_cloud.go index cd07813f4f..5723af3a80 100644 --- a/provider/alibaba_cloud.go +++ b/provider/alibaba_cloud.go @@ -68,7 +68,6 @@ type AlibabaCloudPrivateZoneAPI interface { type AlibabaCloudProvider struct { domainFilter DomainFilter zoneIDFilter ZoneIDFilter // Private Zone only - zoneTypeFilter ZoneTypeFilter MaxChangeCount int EvaluateTargetHealth bool AssumeRole string diff --git a/provider/aws.go b/provider/aws.go index 2cbfee31e3..ffd05b683e 100644 --- a/provider/aws.go +++ b/provider/aws.go @@ -591,7 +591,7 @@ func batchChangeSet(cs []*route53.Change, batchSize int) [][]*route53.Change { batchChanges := make([][]*route53.Change, 0) - changesByName := make(map[string][]*route53.Change, 0) + changesByName := make(map[string][]*route53.Change) for _, v := range cs { changesByName[*v.ResourceRecordSet.Name] = append(changesByName[*v.ResourceRecordSet.Name], v) } diff --git a/provider/aws_test.go b/provider/aws_test.go index 1dc1120100..73d82bc919 100644 --- a/provider/aws_test.go +++ b/provider/aws_test.go @@ -82,9 +82,7 @@ func (r *Route53APIStub) ListResourceRecordSetsPagesWithContext(ctx context.Cont output.ResourceRecordSets = []*route53.ResourceRecordSet{} } else { for _, rrsets := range r.recordSets[aws.StringValue(input.HostedZoneId)] { - for _, rrset := range rrsets { - output.ResourceRecordSets = append(output.ResourceRecordSets, rrset) - } + output.ResourceRecordSets = append(output.ResourceRecordSets, rrsets...) } } lastPage := true @@ -1131,9 +1129,7 @@ func listAWSRecords(t *testing.T, client Route53API, zone string) []*route53.Res require.NoError(t, client.ListResourceRecordSetsPagesWithContext(context.Background(), &route53.ListResourceRecordSetsInput{ HostedZoneId: aws.String(zone), }, func(resp *route53.ListResourceRecordSetsOutput, _ bool) bool { - for _, recordSet := range resp.ResourceRecordSets { - recordSets = append(recordSets, recordSet) - } + recordSets = append(recordSets, resp.ResourceRecordSets...) return true })) diff --git a/provider/azure_private_dns.go b/provider/azure_private_dns.go index 74e1697abe..4c3b73f385 100644 --- a/provider/azure_private_dns.go +++ b/provider/azure_private_dns.go @@ -21,23 +21,16 @@ import ( "fmt" "strings" - "github.com/Azure/go-autorest/autorest" - - log "github.com/sirupsen/logrus" - "github.com/Azure/azure-sdk-for-go/profiles/latest/privatedns/mgmt/privatedns" + "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/Azure/go-autorest/autorest/to" + log "github.com/sirupsen/logrus" "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/plan" ) -type azurePrivateDNSConfig struct { - SubscriptionID string `json:"subscriptionId" yaml:"subscriptionId"` - ResourceGroup string `json:"resourceGroup" yaml:"resourceGroup"` -} - // PrivateZonesClient is an interface of privatedns.PrivateZoneClient that can be stubbed for testing. type PrivateZonesClient interface { ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, top *int32) (result privatedns.PrivateZoneListResultIterator, err error) diff --git a/provider/cloudflare_test.go b/provider/cloudflare_test.go index 01a9877a2b..3fcc922a41 100644 --- a/provider/cloudflare_test.go +++ b/provider/cloudflare_test.go @@ -78,70 +78,6 @@ func (m *mockCloudFlareClient) ListZonesContext(ctx context.Context, opts ...clo }, nil } -type mockCloudFlareUserDetailsFail struct{} - -func (m *mockCloudFlareUserDetailsFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { - return nil, nil -} - -func (m *mockCloudFlareUserDetailsFail) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) { - return []cloudflare.DNSRecord{}, nil -} - -func (m *mockCloudFlareUserDetailsFail) UpdateDNSRecord(zoneID, recordID string, rr cloudflare.DNSRecord) error { - return nil -} - -func (m *mockCloudFlareUserDetailsFail) DeleteDNSRecord(zoneID, recordID string) error { - return nil -} - -func (m *mockCloudFlareUserDetailsFail) UserDetails() (cloudflare.User, error) { - return cloudflare.User{}, fmt.Errorf("could not get ID from zone name") -} - -func (m *mockCloudFlareUserDetailsFail) ZoneIDByName(zoneName string) (string, error) { - return "", nil -} - -func (m *mockCloudFlareUserDetailsFail) ListZones(zoneID ...string) ([]cloudflare.Zone, error) { - return []cloudflare.Zone{{Name: "ext-dns-test.zalando.to."}}, nil -} - -func (m *mockCloudFlareUserDetailsFail) ListZonesContext(ctx context.Context, opts ...cloudflare.ReqOption) (cloudflare.ZonesResponse, error) { - return cloudflare.ZonesResponse{}, nil -} - -type mockCloudFlareCreateZoneFail struct{} - -func (m *mockCloudFlareCreateZoneFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { - return nil, nil -} - -func (m *mockCloudFlareCreateZoneFail) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) { - return []cloudflare.DNSRecord{}, nil -} - -func (m *mockCloudFlareCreateZoneFail) UpdateDNSRecord(zoneID, recordID string, rr cloudflare.DNSRecord) error { - return nil -} - -func (m *mockCloudFlareCreateZoneFail) DeleteDNSRecord(zoneID, recordID string) error { - return nil -} - -func (m *mockCloudFlareCreateZoneFail) UserDetails() (cloudflare.User, error) { - return cloudflare.User{ID: "xxxxxxxxxxxxxxxxxxx"}, nil -} - -func (m *mockCloudFlareCreateZoneFail) ZoneIDByName(zoneName string) (string, error) { - return "", nil -} - -func (m *mockCloudFlareCreateZoneFail) ListZones(zoneID ...string) ([]cloudflare.Zone, error) { - return []cloudflare.Zone{{Name: "ext-dns-test.zalando.to."}}, nil -} - type mockCloudFlareDNSRecordsFail struct{} func (m *mockCloudFlareDNSRecordsFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { @@ -182,66 +118,6 @@ func (m *mockCloudFlareDNSRecordsFail) ListZonesContext(ctx context.Context, opt }, nil } -type mockCloudFlareZoneIDByNameFail struct{} - -func (m *mockCloudFlareZoneIDByNameFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { - return nil, nil -} - -func (m *mockCloudFlareZoneIDByNameFail) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) { - return []cloudflare.DNSRecord{}, nil -} - -func (m *mockCloudFlareZoneIDByNameFail) UpdateDNSRecord(zoneID, recordID string, rr cloudflare.DNSRecord) error { - return nil -} - -func (m *mockCloudFlareZoneIDByNameFail) DeleteDNSRecord(zoneID, recordID string) error { - return nil -} - -func (m *mockCloudFlareZoneIDByNameFail) UserDetails() (cloudflare.User, error) { - return cloudflare.User{}, nil -} - -func (m *mockCloudFlareZoneIDByNameFail) ZoneIDByName(zoneName string) (string, error) { - return "", fmt.Errorf("no ID for zone found") -} - -func (m *mockCloudFlareZoneIDByNameFail) ListZones(zoneID ...string) ([]cloudflare.Zone, error) { - return []cloudflare.Zone{{Name: "ext-dns-test.zalando.to."}}, nil -} - -type mockCloudFlareDeleteZoneFail struct{} - -func (m *mockCloudFlareDeleteZoneFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { - return nil, nil -} - -func (m *mockCloudFlareDeleteZoneFail) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) { - return []cloudflare.DNSRecord{}, nil -} - -func (m *mockCloudFlareDeleteZoneFail) UpdateDNSRecord(zoneID, recordID string, rr cloudflare.DNSRecord) error { - return nil -} - -func (m *mockCloudFlareDeleteZoneFail) DeleteDNSRecord(zoneID, recordID string) error { - return nil -} - -func (m *mockCloudFlareDeleteZoneFail) UserDetails() (cloudflare.User, error) { - return cloudflare.User{}, nil -} - -func (m *mockCloudFlareDeleteZoneFail) ZoneIDByName(zoneName string) (string, error) { - return "1234567890", nil -} - -func (m *mockCloudFlareDeleteZoneFail) ListZones(zoneID ...string) ([]cloudflare.Zone, error) { - return []cloudflare.Zone{{Name: "ext-dns-test.zalando.to."}}, nil -} - type mockCloudFlareListZonesFail struct{} func (m *mockCloudFlareListZonesFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { @@ -276,108 +152,6 @@ func (m *mockCloudFlareListZonesFail) ListZonesContext(ctx context.Context, opts return cloudflare.ZonesResponse{}, fmt.Errorf("no zones available") } -type mockCloudFlareCreateRecordsFail struct{} - -func (m *mockCloudFlareCreateRecordsFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { - return nil, fmt.Errorf("could not create record") -} - -func (m *mockCloudFlareCreateRecordsFail) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) { - return []cloudflare.DNSRecord{{ID: "1234567890", Name: "foobar.ext-dns-test.zalando.to."}}, nil -} - -func (m *mockCloudFlareCreateRecordsFail) UpdateDNSRecord(zoneID, recordID string, rr cloudflare.DNSRecord) error { - return nil -} - -func (m *mockCloudFlareCreateRecordsFail) DeleteDNSRecord(zoneID, recordID string) error { - return nil -} - -func (m *mockCloudFlareCreateRecordsFail) UserDetails() (cloudflare.User, error) { - return cloudflare.User{ID: "xxxxxxxxxxxxxxxxxxx"}, nil -} - -func (m *mockCloudFlareCreateRecordsFail) ZoneIDByName(zoneName string) (string, error) { - return "1234567890", nil -} - -func (m *mockCloudFlareCreateRecordsFail) ListZones(zoneID ...string) ([]cloudflare.Zone, error) { - return []cloudflare.Zone{{}}, fmt.Errorf("no zones available") -} - -func (m *mockCloudFlareCreateRecordsFail) ListZonesContext(ctx context.Context, opts ...cloudflare.ReqOption) (cloudflare.ZonesResponse, error) { - return cloudflare.ZonesResponse{}, nil -} - -type mockCloudFlareDeleteRecordsFail struct{} - -func (m *mockCloudFlareDeleteRecordsFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { - return nil, nil -} - -func (m *mockCloudFlareDeleteRecordsFail) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) { - return []cloudflare.DNSRecord{{ID: "1234567890", Name: "foobar.ext-dns-test.zalando.to."}}, nil -} - -func (m *mockCloudFlareDeleteRecordsFail) UpdateDNSRecord(zoneID, recordID string, rr cloudflare.DNSRecord) error { - return nil -} - -func (m *mockCloudFlareDeleteRecordsFail) DeleteDNSRecord(zoneID, recordID string) error { - return fmt.Errorf("could not delete record") -} - -func (m *mockCloudFlareDeleteRecordsFail) UserDetails() (cloudflare.User, error) { - return cloudflare.User{ID: "xxxxxxxxxxxxxxxxxxx"}, nil -} - -func (m *mockCloudFlareDeleteRecordsFail) ZoneIDByName(zoneName string) (string, error) { - return "1234567890", nil -} - -func (m *mockCloudFlareDeleteRecordsFail) ListZones(zoneID ...string) ([]cloudflare.Zone, error) { - return []cloudflare.Zone{{Name: "ext-dns-test.zalando.to."}}, nil -} - -func (m *mockCloudFlareDeleteRecordsFail) ListZonesContext(ctx context.Context, opts ...cloudflare.ReqOption) (cloudflare.ZonesResponse, error) { - return cloudflare.ZonesResponse{}, nil -} - -type mockCloudFlareUpdateRecordsFail struct{} - -func (m *mockCloudFlareUpdateRecordsFail) CreateDNSRecord(zoneID string, rr cloudflare.DNSRecord) (*cloudflare.DNSRecordResponse, error) { - return nil, nil -} - -func (m *mockCloudFlareUpdateRecordsFail) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) { - return []cloudflare.DNSRecord{{ID: "1234567890", Name: "foobar.ext-dns-test.zalando.to."}}, nil -} - -func (m *mockCloudFlareUpdateRecordsFail) UpdateDNSRecord(zoneID, recordID string, rr cloudflare.DNSRecord) error { - return fmt.Errorf("could not update record") -} - -func (m *mockCloudFlareUpdateRecordsFail) DeleteDNSRecord(zoneID, recordID string) error { - return nil -} - -func (m *mockCloudFlareUpdateRecordsFail) UserDetails() (cloudflare.User, error) { - return cloudflare.User{ID: "xxxxxxxxxxxxxxxxxxx"}, nil -} - -func (m *mockCloudFlareUpdateRecordsFail) ZoneIDByName(zoneName string) (string, error) { - return "1234567890", nil -} - -func (m *mockCloudFlareUpdateRecordsFail) ListZones(zoneID ...string) ([]cloudflare.Zone, error) { - return []cloudflare.Zone{{Name: "ext-dns-test.zalando.to."}}, nil -} - -func (m *mockCloudFlareUpdateRecordsFail) ListZonesContext(ctx context.Context, opts ...cloudflare.ReqOption) (cloudflare.ZonesResponse, error) { - return cloudflare.ZonesResponse{}, nil -} - func TestNewCloudFlareChanges(t *testing.T) { expect := []struct { Name string diff --git a/provider/digital_ocean_test.go b/provider/digital_ocean_test.go index 9372a5f2f8..a8f4580ca2 100644 --- a/provider/digital_ocean_test.go +++ b/provider/digital_ocean_test.go @@ -30,12 +30,6 @@ import ( "sigs.k8s.io/external-dns/plan" ) -type mockDigitalOceanInterface interface { - List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) - Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) - Delete(context.Context, string) (*godo.Response, error) -} - type mockDigitalOceanClient struct{} func (m *mockDigitalOceanClient) List(ctx context.Context, opt *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { @@ -113,150 +107,6 @@ func (m *mockDigitalOceanClient) Records(ctx context.Context, domain string, opt } } -type mockDigitalOceanListFail struct{} - -func (m *mockDigitalOceanListFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { - return []godo.Domain{}, nil, fmt.Errorf("Fail to get domains") -} - -func (m *mockDigitalOceanListFail) Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanListFail) CreateRecord(context.Context, string, *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanListFail) Delete(context.Context, string) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanListFail) DeleteRecord(ctx context.Context, domain string, id int) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanListFail) EditRecord(ctx context.Context, domain string, id int, editRequest *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanListFail) Get(ctx context.Context, name string) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanListFail) Record(ctx context.Context, domain string, id int) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanListFail) Records(ctx context.Context, domain string, opt *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) { - return []godo.DomainRecord{{ID: 1}, {ID: 2}}, nil, nil -} - -type mockDigitalOceanGetFail struct{} - -func (m *mockDigitalOceanGetFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { - return []godo.Domain{{Name: "foo.com"}, {Name: "bar.com"}}, nil, nil -} - -func (m *mockDigitalOceanGetFail) Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanGetFail) CreateRecord(context.Context, string, *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanGetFail) Delete(context.Context, string) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanGetFail) DeleteRecord(ctx context.Context, domain string, id int) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanGetFail) EditRecord(ctx context.Context, domain string, id int, editRequest *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanGetFail) Get(ctx context.Context, name string) (*godo.Domain, *godo.Response, error) { - return nil, nil, fmt.Errorf("Failed to get domain") -} - -func (m *mockDigitalOceanGetFail) Record(ctx context.Context, domain string, id int) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanGetFail) Records(ctx context.Context, domain string, opt *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) { - return []godo.DomainRecord{{ID: 1}, {ID: 2}}, nil, nil -} - -type mockDigitalOceanCreateFail struct{} - -func (m *mockDigitalOceanCreateFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { - return []godo.Domain{{Name: "foo.com"}, {Name: "bar.com"}}, nil, nil -} - -func (m *mockDigitalOceanCreateFail) Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) { - return nil, nil, fmt.Errorf("Failed to create domain") -} - -func (m *mockDigitalOceanCreateFail) CreateRecord(context.Context, string, *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanCreateFail) Delete(context.Context, string) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanCreateFail) DeleteRecord(ctx context.Context, domain string, id int) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanCreateFail) EditRecord(ctx context.Context, domain string, id int, editRequest *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanCreateFail) Get(ctx context.Context, name string) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanCreateFail) Record(ctx context.Context, domain string, id int) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanCreateFail) Records(ctx context.Context, domain string, opt *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) { - return []godo.DomainRecord{{ID: 1}, {ID: 2}}, nil, nil -} - -type mockDigitalOceanDeleteFail struct{} - -func (m *mockDigitalOceanDeleteFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { - return []godo.Domain{{Name: "foo.com"}, {Name: "bar.com"}}, nil, nil -} - -func (m *mockDigitalOceanDeleteFail) Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanDeleteFail) CreateRecord(context.Context, string, *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanDeleteFail) Delete(context.Context, string) (*godo.Response, error) { - return nil, fmt.Errorf("Failed to delete domain") -} -func (m *mockDigitalOceanDeleteFail) DeleteRecord(ctx context.Context, domain string, id int) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanDeleteFail) EditRecord(ctx context.Context, domain string, id int, editRequest *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanDeleteFail) Get(ctx context.Context, name string) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanDeleteFail) Record(ctx context.Context, domain string, id int) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanDeleteFail) Records(ctx context.Context, domain string, opt *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) { - return []godo.DomainRecord{{ID: 1}, {ID: 2}}, nil, nil -} - type mockDigitalOceanRecordsFail struct{} func (m *mockDigitalOceanRecordsFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { @@ -293,114 +143,6 @@ func (m *mockDigitalOceanRecordsFail) Records(ctx context.Context, domain string return []godo.DomainRecord{}, nil, fmt.Errorf("Failed to get records") } -type mockDigitalOceanUpdateRecordsFail struct{} - -func (m *mockDigitalOceanUpdateRecordsFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { - return []godo.Domain{{Name: "foo.com"}, {Name: "bar.com"}}, nil, nil -} - -func (m *mockDigitalOceanUpdateRecordsFail) Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanUpdateRecordsFail) CreateRecord(context.Context, string, *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanUpdateRecordsFail) Delete(context.Context, string) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanUpdateRecordsFail) DeleteRecord(ctx context.Context, domain string, id int) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanUpdateRecordsFail) EditRecord(ctx context.Context, domain string, id int, editRequest *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return nil, nil, fmt.Errorf("Failed to update record") -} - -func (m *mockDigitalOceanUpdateRecordsFail) Get(ctx context.Context, name string) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanUpdateRecordsFail) Record(ctx context.Context, domain string, id int) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanUpdateRecordsFail) Records(ctx context.Context, domain string, opt *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) { - return []godo.DomainRecord{{ID: 1}, {ID: 2}}, nil, nil -} - -type mockDigitalOceanDeleteRecordsFail struct{} - -func (m *mockDigitalOceanDeleteRecordsFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { - return []godo.Domain{{Name: "foo.com"}, {Name: "bar.com"}}, nil, nil -} - -func (m *mockDigitalOceanDeleteRecordsFail) Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanDeleteRecordsFail) CreateRecord(context.Context, string, *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanDeleteRecordsFail) Delete(context.Context, string) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanDeleteRecordsFail) DeleteRecord(ctx context.Context, domain string, id int) (*godo.Response, error) { - return nil, fmt.Errorf("Failed to delete record") -} -func (m *mockDigitalOceanDeleteRecordsFail) EditRecord(ctx context.Context, domain string, id int, editRequest *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanDeleteRecordsFail) Get(ctx context.Context, name string) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanDeleteRecordsFail) Record(ctx context.Context, domain string, id int) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanDeleteRecordsFail) Records(ctx context.Context, domain string, opt *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) { - return []godo.DomainRecord{{ID: 1, Name: "foobar.ext-dns-test.zalando.to."}, {ID: 2}}, nil, nil -} - -type mockDigitalOceanCreateRecordsFail struct{} - -func (m *mockDigitalOceanCreateRecordsFail) List(context.Context, *godo.ListOptions) ([]godo.Domain, *godo.Response, error) { - return []godo.Domain{{Name: "foo.com"}, {Name: "bar.com"}}, nil, nil -} - -func (m *mockDigitalOceanCreateRecordsFail) Create(context.Context, *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanCreateRecordsFail) CreateRecord(context.Context, string, *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return nil, nil, fmt.Errorf("Failed to create record") -} - -func (m *mockDigitalOceanCreateRecordsFail) Delete(context.Context, string) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanCreateRecordsFail) DeleteRecord(ctx context.Context, domain string, id int) (*godo.Response, error) { - return nil, nil -} -func (m *mockDigitalOceanCreateRecordsFail) EditRecord(ctx context.Context, domain string, id int, editRequest *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanCreateRecordsFail) Get(ctx context.Context, name string) (*godo.Domain, *godo.Response, error) { - return &godo.Domain{Name: "example.com"}, nil, nil -} - -func (m *mockDigitalOceanCreateRecordsFail) Record(ctx context.Context, domain string, id int) (*godo.DomainRecord, *godo.Response, error) { - return &godo.DomainRecord{ID: 1}, nil, nil -} - -func (m *mockDigitalOceanCreateRecordsFail) Records(ctx context.Context, domain string, opt *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) { - return []godo.DomainRecord{{ID: 1, Name: "foobar.ext-dns-test.zalando.to."}, {ID: 2}}, nil, nil -} - func TestNewDigitalOceanChanges(t *testing.T) { action := DigitalOceanCreate endpoints := []*endpoint.Endpoint{{DNSName: "new", Targets: endpoint.Targets{"target"}}} diff --git a/provider/dnsimple_test.go b/provider/dnsimple_test.go index d391e27b65..e22dcd9356 100644 --- a/provider/dnsimple_test.go +++ b/provider/dnsimple_test.go @@ -37,8 +37,6 @@ var mockProvider dnsimpleProvider var dnsimpleListRecordsResponse dnsimple.ZoneRecordsResponse var dnsimpleListZonesResponse dnsimple.ZonesResponse -type mockDnsimpleZonesService struct{} - func TestDnsimpleServices(t *testing.T) { // Setup example responses firstZone := dnsimple.Zone{ diff --git a/provider/dyn.go b/provider/dyn.go index b08a84529b..e269287b0d 100644 --- a/provider/dyn.go +++ b/provider/dyn.go @@ -395,19 +395,6 @@ func (d *dynProviderState) fetchAllRecordsInZone(zone string) (*dynectsoap.GetAl } -// fetchAllRecordLinksInZone list all records in a zone with a single call. Records not matched by the -// DomainFilter are ignored. The response is a list of links that can be fed to dynect.Client.Do() -// directly -func (d *dynProviderState) fetchAllRecordLinksInZone(client *dynect.Client, zone string) ([]string, error) { - var allRecords dynect.AllRecordsResponse - err := client.Do("GET", fmt.Sprintf("AllRecord/%s/", zone), nil, &allRecords) - if err != nil { - return nil, err - } - - return filterAndFixLinks(allRecords.Data, d.DomainFilter), nil -} - // buildLinkToRecord build a resource link. The symmetry of the dyn API is used to save // switch-case boilerplate. // Empty response means the endpoint is not mappable to a records link: either because the fqdn @@ -604,7 +591,7 @@ func (d *dynProviderState) Records(ctx context.Context) ([]*endpoint.Endpoint, e for _, zone := range zones { serial, err := d.fetchZoneSerial(client, zone) if err != nil { - if strings.Index(err.Error(), "404 Not Found") >= 0 { + if strings.Contains(err.Error(), "404 Not Found") { log.Infof("Ignore zone %s as it does not exist", zone) continue } diff --git a/provider/google_test.go b/provider/google_test.go index 7caedfe42c..627729b2da 100644 --- a/provider/google_test.go +++ b/provider/google_test.go @@ -578,7 +578,6 @@ func TestGoogleBatchChangeSetExceeding(t *testing.T) { const testCount = 50 const testLimit = 11 const expectedBatchCount = 5 - const expectedChangesCount = 10 for i := 1; i <= testCount; i += 2 { cs.Additions = append(cs.Additions, &dns.ResourceRecordSet{ @@ -612,7 +611,6 @@ func TestGoogleBatchChangeSetExceeding(t *testing.T) { func TestGoogleBatchChangeSetExceedingNameChange(t *testing.T) { cs := &dns.Change{} - const testCount = 10 const testLimit = 1 cs.Additions = append(cs.Additions, &dns.ResourceRecordSet{ diff --git a/provider/ns1.go b/provider/ns1.go index 2bda2e907d..4a1c0477db 100644 --- a/provider/ns1.go +++ b/provider/ns1.go @@ -115,7 +115,7 @@ func newNS1ProviderWithHTTPClient(config NS1Config, client *http.Client) (*NS1Pr clientArgs = append(clientArgs, api.SetEndpoint(config.NS1Endpoint)) } - if config.NS1IgnoreSSL == true { + if config.NS1IgnoreSSL { log.Info("ns1-ignoressl flag is True, skipping SSL verification") defaultTransport := http.DefaultTransport.(*http.Transport) tr := &http.Transport{ diff --git a/provider/rcode0_test.go b/provider/rcode0_test.go index a977b8fe81..9f43404279 100644 --- a/provider/rcode0_test.go +++ b/provider/rcode0_test.go @@ -47,20 +47,11 @@ type mockRRSetService struct { TestErrorReturned bool } -func (m *mockRcodeZeroClient) resetMockServices() { - m.Zones = &mockZoneManagementService{} - m.RRSet = &mockRRSetService{} -} - func (m *mockZoneManagementService) resetTestConditions() { m.TestNilZonesReturned = false m.TestErrorReturned = false } -func (m *mockRRSetService) resetTestConditions() { - m.TestErrorReturned = false -} - func TestRcodeZeroProvider_Records(t *testing.T) { mockRRSetService := &mockRRSetService{} diff --git a/source/cloudfoundry.go b/source/cloudfoundry.go index eb3566994e..2a69087865 100644 --- a/source/cloudfoundry.go +++ b/source/cloudfoundry.go @@ -26,7 +26,6 @@ import ( type cloudfoundrySource struct { client *cfclient.Client - config Config } // NewCloudFoundrySource creates a new cloudfoundrySource with the given config diff --git a/source/crd_test.go b/source/crd_test.go index ce8e76c7cd..33038520e9 100644 --- a/source/crd_test.go +++ b/source/crd_test.go @@ -52,7 +52,7 @@ func defaultHeader() http.Header { return header } -func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser { +func objBody(codec runtime.Encoder, obj runtime.Object) io.ReadCloser { return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, obj)))) } diff --git a/source/gateway.go b/source/gateway.go index 7ce56cfeb5..9198f4fafb 100644 --- a/source/gateway.go +++ b/source/gateway.go @@ -95,7 +95,7 @@ func NewIstioGatewaySource( // wait for the local cache to be populated. err = wait.Poll(time.Second, 60*time.Second, func() (bool, error) { - return serviceInformer.Informer().HasSynced() == true, nil + return serviceInformer.Informer().HasSynced(), nil }) if err != nil { return nil, fmt.Errorf("failed to sync cache: %v", err) @@ -327,14 +327,3 @@ func (sc *gatewaySource) endpointsFromGatewayConfig(config istiomodel.Config) ([ return endpoints, nil } - -func parseIngressGateway(ingressGateway string) (namespace, name string, err error) { - parts := strings.Split(ingressGateway, "/") - if len(parts) != 2 { - err = fmt.Errorf("invalid ingress gateway service (namespace/name) found '%v'", ingressGateway) - } else { - namespace, name = parts[0], parts[1] - } - - return -} diff --git a/source/ingress.go b/source/ingress.go index 370a35f2a1..8f90523fcc 100644 --- a/source/ingress.go +++ b/source/ingress.go @@ -91,7 +91,7 @@ func NewIngressSource(kubeClient kubernetes.Interface, namespace, annotationFilt // wait for the local cache to be populated. err = wait.Poll(time.Second, 60*time.Second, func() (bool, error) { - return ingressInformer.Informer().HasSynced() == true, nil + return ingressInformer.Informer().HasSynced(), nil }) if err != nil { return nil, fmt.Errorf("failed to sync cache: %v", err) diff --git a/source/ingressroute.go b/source/ingressroute.go index 77455ecb7a..fb4ef69dfd 100644 --- a/source/ingressroute.go +++ b/source/ingressroute.go @@ -104,7 +104,7 @@ func NewContourIngressRouteSource( // wait for the local cache to be populated. err = wait.Poll(time.Second, 60*time.Second, func() (bool, error) { - return ingressRouteInformer.Informer().HasSynced() == true, nil + return ingressRouteInformer.Informer().HasSynced(), nil }) if err != nil { return nil, fmt.Errorf("failed to sync cache: %v", err) diff --git a/source/node.go b/source/node.go index a8bd0d3d47..aaaf648267 100644 --- a/source/node.go +++ b/source/node.go @@ -78,7 +78,7 @@ func NewNodeSource(kubeClient kubernetes.Interface, annotationFilter, fqdnTempla // wait for the local cache to be populated. err = wait.Poll(time.Second, 60*time.Second, func() (bool, error) { - return nodeInformer.Informer().HasSynced() == true, nil + return nodeInformer.Informer().HasSynced(), nil }) if err != nil { return nil, fmt.Errorf("failed to sync cache: %v", err) diff --git a/source/service.go b/source/service.go index ee8d7ce882..23839fe9ee 100644 --- a/source/service.go +++ b/source/service.go @@ -113,7 +113,7 @@ func NewServiceSource(kubeClient kubernetes.Interface, namespace, annotationFilt // wait for the local cache to be populated. err = wait.Poll(time.Second, 60*time.Second, func() (bool, error) { - return serviceInformer.Informer().HasSynced() == true, nil + return serviceInformer.Informer().HasSynced(), nil }) if err != nil { return nil, fmt.Errorf("failed to sync cache: %v", err) @@ -234,9 +234,9 @@ func (sc *serviceSource) extractHeadlessEndpoints(svc *v1.Service, hostname stri headlessDomains = append(headlessDomains, fmt.Sprintf("%s.%s", v.Spec.Hostname, hostname)) } for _, headlessDomain := range headlessDomains { - if sc.publishHostIP == true { + if sc.publishHostIP { log.Debugf("Generating matching endpoint %s with HostIP %s", headlessDomain, v.Status.HostIP) - // To reduce traffice on the DNS API only add record for running Pods. Good Idea? + // To reduce traffic on the DNS API only add record for running Pods. Good Idea? if v.Status.Phase == v1.PodRunning { targetsByHeadlessDomain[headlessDomain] = append(targetsByHeadlessDomain[headlessDomain], v.Status.HostIP) } else {