Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing copyright header and gofumpt #3033

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/scripts/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func removeLinkPrefixInIndex() {
updatedContent := strings.ReplaceAll(string(content), "](./docs/", "](")
updatedContent = strings.ReplaceAll(updatedContent, "](docs/", "](")

f, err := os.OpenFile("./docs/index.md", os.O_RDWR, 0644)
f, err := os.OpenFile("./docs/index.md", os.O_RDWR, 0o644)
if err != nil {
log.Fatalf("Could not open index.md file to update content. Original error: %s", err)
}
Expand Down
6 changes: 2 additions & 4 deletions endpoint/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ import (
"strings"
)

var (
// ErrInvalidHeritage is returned when heritage was not found, or different heritage is found
ErrInvalidHeritage = errors.New("heritage is unknown or not found")
)
// ErrInvalidHeritage is returned when heritage was not found, or different heritage is found
var ErrInvalidHeritage = errors.New("heritage is unknown or not found")

const (
heritage = "external-dns"
Expand Down
4 changes: 2 additions & 2 deletions endpoint/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type LabelsSuite struct {
barTextAsMap Labels
noHeritageText string
wrongHeritageText string
multipleHeritageText string //considered invalid
multipleHeritageText string // considered invalid
}

func (suite *LabelsSuite) SetupTest() {
Expand All @@ -48,7 +48,7 @@ func (suite *LabelsSuite) SetupTest() {
"resource": "bar-resource",
"new-key": "bar-new-key",
}
suite.barText = "heritage=external-dns,,external-dns/owner=bar-owner,external-dns/resource=bar-resource,external-dns/new-key=bar-new-key,random=stuff,no-equal-sign,," //also has some random gibberish
suite.barText = "heritage=external-dns,,external-dns/owner=bar-owner,external-dns/resource=bar-resource,external-dns/new-key=bar-new-key,random=stuff,no-equal-sign,," // also has some random gibberish

suite.noHeritageText = "external-dns/owner=random-owner"
suite.wrongHeritageText = "heritage=mate,external-dns/owner=random-owner"
Expand Down
1 change: 1 addition & 0 deletions endpoint/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func main() {
p, err = safedns.NewSafeDNSProvider(domainFilter, cfg.DryRun)
case "plural":
p, err = plural.NewPluralProvider(cfg.PluralCluster, cfg.PluralProvider)
case "tencentcloud":
case "tencentcloud":
p, err = tencentcloud.NewTencentCloudProvider(domainFilter, zoneIDFilter, cfg.TencentCloudConfigFile, cfg.TencentCloudZoneType, cfg.DryRun)
default:
log.Fatalf("unknown dns provider: %s", cfg.Provider)
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ const (
passwordMask = "******"
)

var (
// Version is the current version of the app, generated at build time
Version = "unknown"
)
// Version is the current version of the app, generated at build time
var Version = "unknown"

// Config is a project-wide configuration
type Config struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/externaldns/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestValidateGoodRfc2136Config(t *testing.T) {
}

func TestValidateBadRfc2136GssTsigConfig(t *testing.T) {
var invalidRfc2136GssTsigConfigs = []*externaldns.Config{
invalidRfc2136GssTsigConfigs := []*externaldns.Config{
{
LogFormat: "json",
Sources: []string{"test-source"},
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) {
}

func TestValidateGoodRfc2136GssTsigConfig(t *testing.T) {
var validRfc2136GssTsigConfigs = []*externaldns.Config{
validRfc2136GssTsigConfigs := []*externaldns.Config{
{
LogFormat: "json",
Sources: []string{"test-source"},
Expand Down
4 changes: 2 additions & 2 deletions plan/conflict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (suite *ResolverSuite) SetupTest() {
endpoint.ResourceLabelKey: "ingress/default/bar-127",
},
}
suite.bar127AAnother = &endpoint.Endpoint{ //TODO: remove this once we move to multiple targets under same endpoint
suite.bar127AAnother = &endpoint.Endpoint{ // TODO: remove this once we move to multiple targets under same endpoint
DNSName: "bar",
Targets: endpoint.Targets{"8.8.8.8"},
RecordType: "A",
Expand Down Expand Up @@ -113,7 +113,7 @@ func (suite *ResolverSuite) TestStrictResolver() {
suite.Equal(suite.fooA5, suite.perResource.ResolveCreate([]*endpoint.Endpoint{suite.fooA5, suite.fooV1Cname}), "should pick min one")
suite.Equal(suite.fooV1Cname, suite.perResource.ResolveCreate([]*endpoint.Endpoint{suite.fooV2Cname, suite.fooV1Cname}), "should pick min one")

//test that perResource resolver preserves resource if it still exists
// test that perResource resolver preserves resource if it still exists
suite.Equal(suite.bar127AAnother, suite.perResource.ResolveUpdate(suite.bar127A, []*endpoint.Endpoint{suite.bar127AAnother, suite.bar127A}), "should pick min for update when same resource endpoint occurs multiple times (remove after multiple-target support") // TODO:remove this test
suite.Equal(suite.bar127A, suite.perResource.ResolveUpdate(suite.bar127A, []*endpoint.Endpoint{suite.bar192A, suite.bar127A}), "should pick existing resource")
suite.Equal(suite.fooV2Cname, suite.perResource.ResolveUpdate(suite.fooV2Cname, []*endpoint.Endpoint{suite.fooV2Cname, suite.fooV2CnameDuplicate}), "should pick existing resource even if targets are same")
Expand Down
6 changes: 3 additions & 3 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type planTable struct {
resolver ConflictResolver
}

func newPlanTable() planTable { //TODO: make resolver configurable
func newPlanTable() planTable { // TODO: make resolver configurable
return planTable{map[string]map[string]*planTableRow{}, PerResource{}}
}

Expand Down Expand Up @@ -148,15 +148,15 @@ func (p *Plan) Calculate() *Plan {

for _, topRow := range t.rows {
for _, row := range topRow {
if row.current == nil { //dns name not taken
if row.current == nil { // dns name not taken
changes.Create = append(changes.Create, t.resolver.ResolveCreate(row.candidates))
}
if row.current != nil && len(row.candidates) == 0 {
changes.Delete = append(changes.Delete, row.current)
}

// TODO: allows record type change, which might not be supported by all dns providers
if row.current != nil && len(row.candidates) > 0 { //dns name is taken
if row.current != nil && len(row.candidates) > 0 { // dns name is taken
update := t.resolver.ResolveUpdate(row.current, row.candidates)
// compare "update" to "current" to figure out if actual update is required
if shouldUpdateTTL(update, row.current) || targetChanged(update, row.current) || p.shouldUpdateProviderSpecific(update, row.current) {
Expand Down
13 changes: 3 additions & 10 deletions plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (suite *PlanTestSuite) SetupTest() {
func (suite *PlanTestSuite) TestSyncFirstRound() {
current := []*endpoint.Endpoint{}
desired := []*endpoint.Endpoint{suite.fooV1Cname, suite.fooV2Cname, suite.bar127A}
expectedCreate := []*endpoint.Endpoint{suite.fooV1Cname, suite.bar127A} //v1 is chosen because of resolver taking "min"
expectedCreate := []*endpoint.Endpoint{suite.fooV1Cname, suite.bar127A} // v1 is chosen because of resolver taking "min"
expectedUpdateOld := []*endpoint.Endpoint{}
expectedUpdateNew := []*endpoint.Endpoint{}
expectedDelete := []*endpoint.Endpoint{}
Expand Down Expand Up @@ -544,7 +544,7 @@ func (suite *PlanTestSuite) TestRemoveEndpointWithUpsert() {
validateEntries(suite.T(), changes.Delete, expectedDelete)
}

//TODO: remove once multiple-target per endpoint is supported
// TODO: remove once multiple-target per endpoint is supported
func (suite *PlanTestSuite) TestDuplicatedEndpointsForSameResourceReplace() {
current := []*endpoint.Endpoint{suite.fooV3CnameSameResource, suite.bar192A}
desired := []*endpoint.Endpoint{suite.fooV1Cname, suite.fooV3CnameSameResource}
Expand All @@ -567,9 +567,8 @@ func (suite *PlanTestSuite) TestDuplicatedEndpointsForSameResourceReplace() {
validateEntries(suite.T(), changes.Delete, expectedDelete)
}

//TODO: remove once multiple-target per endpoint is supported
// TODO: remove once multiple-target per endpoint is supported
func (suite *PlanTestSuite) TestDuplicatedEndpointsForSameResourceRetain() {

current := []*endpoint.Endpoint{suite.fooV1Cname, suite.bar192A}
desired := []*endpoint.Endpoint{suite.fooV1Cname, suite.fooV3CnameSameResource}
expectedCreate := []*endpoint.Endpoint{}
Expand All @@ -592,7 +591,6 @@ func (suite *PlanTestSuite) TestDuplicatedEndpointsForSameResourceRetain() {
}

func (suite *PlanTestSuite) TestMultipleRecordsSameNameDifferentSetIdentifier() {

current := []*endpoint.Endpoint{suite.multiple1}
desired := []*endpoint.Endpoint{suite.multiple2, suite.multiple3}
expectedCreate := []*endpoint.Endpoint{suite.multiple3}
Expand All @@ -615,7 +613,6 @@ func (suite *PlanTestSuite) TestMultipleRecordsSameNameDifferentSetIdentifier()
}

func (suite *PlanTestSuite) TestSetIdentifierUpdateCreatesAndDeletes() {

current := []*endpoint.Endpoint{suite.multiple2}
desired := []*endpoint.Endpoint{suite.multiple3}
expectedCreate := []*endpoint.Endpoint{suite.multiple3}
Expand All @@ -638,7 +635,6 @@ func (suite *PlanTestSuite) TestSetIdentifierUpdateCreatesAndDeletes() {
}

func (suite *PlanTestSuite) TestDomainFiltersInitial() {

current := []*endpoint.Endpoint{suite.domainFilterExcluded}
desired := []*endpoint.Endpoint{suite.domainFilterExcluded, suite.domainFilterFiltered1, suite.domainFilterFiltered2, suite.domainFilterFiltered3}
expectedCreate := []*endpoint.Endpoint{suite.domainFilterFiltered1, suite.domainFilterFiltered2, suite.domainFilterFiltered3}
Expand All @@ -662,7 +658,6 @@ func (suite *PlanTestSuite) TestDomainFiltersInitial() {
}

func (suite *PlanTestSuite) TestDomainFiltersUpdate() {

current := []*endpoint.Endpoint{suite.domainFilterExcluded, suite.domainFilterFiltered1, suite.domainFilterFiltered2}
desired := []*endpoint.Endpoint{suite.domainFilterExcluded, suite.domainFilterFiltered1, suite.domainFilterFiltered2, suite.domainFilterFiltered3}
expectedCreate := []*endpoint.Endpoint{suite.domainFilterFiltered3}
Expand All @@ -686,7 +681,6 @@ func (suite *PlanTestSuite) TestDomainFiltersUpdate() {
}

func (suite *PlanTestSuite) TestMissing() {

missing := []*endpoint.Endpoint{suite.domainFilterFilteredTXT1, suite.domainFilterFilteredTXT2, suite.domainFilterExcludedTXT}
expectedCreate := []*endpoint.Endpoint{suite.domainFilterFilteredTXT1, suite.domainFilterFilteredTXT2}

Expand Down Expand Up @@ -893,7 +887,6 @@ func TestShouldUpdateProviderSpecific(tt *testing.T) {
}
b := plan.shouldUpdateProviderSpecific(test.desired, test.current)
assert.Equal(t, test.shouldUpdate, b)

})
}
}
7 changes: 3 additions & 4 deletions provider/akamai/akamai.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func (p AkamaiProvider) fetchZones() (akamaiZones, error) {
queryArgs.ContractIds = strings.Join(p.zoneIDFilter.ZoneIDs, ",")
}
resp, err := p.client.ListZones(queryArgs) // retrieve all primary zones filtered by contract ids

if err != nil {
log.Errorf("Failed to fetch zones from Akamai")
return filteredZones, err
Expand All @@ -215,7 +214,7 @@ func (p AkamaiProvider) fetchZones() (akamaiZones, error) {
return filteredZones, nil
}

//Records returns the list of records in a given zone.
// Records returns the list of records in a given zone.
func (p AkamaiProvider) Records(context.Context) (endpoints []*endpoint.Endpoint, err error) {
zones, err := p.fetchZones() // returns a filtered set of zones
if err != nil {
Expand All @@ -242,7 +241,7 @@ func (p AkamaiProvider) Records(context.Context) (endpoints []*endpoint.Endpoint
continue
}
var temp interface{} = int64(recordset.TTL)
var ttl = endpoint.TTL(temp.(int64))
ttl := endpoint.TTL(temp.(int64))
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(recordset.Name,
recordset.Type,
ttl,
Expand Down Expand Up @@ -359,7 +358,7 @@ func trimTxtRdata(rdata []string, rtype string) []string {

func ttlAsInt(src endpoint.TTL) int {
var temp interface{} = int64(src)
var temp64 = temp.(int64)
temp64 := temp.(int64)
var ttl int = edgeDNSRecordTTL
if temp64 > 0 && temp64 <= int64(maxInt) {
ttl = int(temp64)
Expand Down
Loading