mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 01:26:59 +02:00
chore(refactore): added lint checks
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
parent
8e695e68b1
commit
abdf8bbc02
@ -1,7 +1,8 @@
|
|||||||
|
# https://golangci-lint.run/usage/configuration/
|
||||||
version: "2"
|
version: "2"
|
||||||
linters:
|
linters:
|
||||||
default: none
|
default: none
|
||||||
enable:
|
enable: # golangci-lint help linters
|
||||||
- dogsled
|
- dogsled
|
||||||
- goprintffuncname
|
- goprintffuncname
|
||||||
- govet
|
- govet
|
||||||
@ -13,6 +14,9 @@ linters:
|
|||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
- whitespace
|
- whitespace
|
||||||
|
- predeclared # Find code that shadows one of Go's predeclared identifiers
|
||||||
|
- sloglint # Ensure consistent code style when using log/slog
|
||||||
|
- asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name
|
||||||
settings:
|
settings:
|
||||||
exhaustive:
|
exhaustive:
|
||||||
default-signifies-exhaustive: false
|
default-signifies-exhaustive: false
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ConflictResolver is used to make a decision in case of two or more different kubernetes resources
|
// ConflictResolver is used to make a decision in case of two or more different kubernetes resources
|
||||||
// are trying to acquire same DNS name
|
// are trying to acquire the same DNS name
|
||||||
type ConflictResolver interface {
|
type ConflictResolver interface {
|
||||||
ResolveCreate(candidates []*endpoint.Endpoint) *endpoint.Endpoint
|
ResolveCreate(candidates []*endpoint.Endpoint) *endpoint.Endpoint
|
||||||
ResolveUpdate(current *endpoint.Endpoint, candidates []*endpoint.Endpoint) *endpoint.Endpoint
|
ResolveUpdate(current *endpoint.Endpoint, candidates []*endpoint.Endpoint) *endpoint.Endpoint
|
||||||
@ -38,13 +38,13 @@ type PerResource struct{}
|
|||||||
// ResolveCreate is invoked when dns name is not owned by any resource
|
// ResolveCreate is invoked when dns name is not owned by any resource
|
||||||
// ResolveCreate takes "minimal" (string comparison of Target) endpoint to acquire the DNS record
|
// ResolveCreate takes "minimal" (string comparison of Target) endpoint to acquire the DNS record
|
||||||
func (s PerResource) ResolveCreate(candidates []*endpoint.Endpoint) *endpoint.Endpoint {
|
func (s PerResource) ResolveCreate(candidates []*endpoint.Endpoint) *endpoint.Endpoint {
|
||||||
var min *endpoint.Endpoint
|
var minE *endpoint.Endpoint
|
||||||
for _, ep := range candidates {
|
for _, ep := range candidates {
|
||||||
if min == nil || s.less(ep, min) {
|
if minE == nil || s.less(ep, minE) {
|
||||||
min = ep
|
minE = ep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return min
|
return minE
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveUpdate is invoked when dns name is already owned by "current" endpoint
|
// ResolveUpdate is invoked when dns name is already owned by "current" endpoint
|
||||||
|
@ -90,14 +90,6 @@ type akamaiZone struct {
|
|||||||
func NewAkamaiProvider(akamaiConfig AkamaiConfig, akaService AkamaiDNSService) (provider.Provider, error) {
|
func NewAkamaiProvider(akamaiConfig AkamaiConfig, akaService AkamaiDNSService) (provider.Provider, error) {
|
||||||
var edgeGridConfig edgegrid.Config
|
var edgeGridConfig edgegrid.Config
|
||||||
|
|
||||||
/*
|
|
||||||
log.Debugf("Host: %s", akamaiConfig.ServiceConsumerDomain)
|
|
||||||
log.Debugf("ClientToken: %s", akamaiConfig.ClientToken)
|
|
||||||
log.Debugf("ClientSecret: %s", akamaiConfig.ClientSecret)
|
|
||||||
log.Debugf("AccessToken: %s", akamaiConfig.AccessToken)
|
|
||||||
log.Debugf("EdgePath: %s", akamaiConfig.EdgercPath)
|
|
||||||
log.Debugf("EdgeSection: %s", akamaiConfig.EdgercSection)
|
|
||||||
*/
|
|
||||||
// environment overrides edgerc file but config needs to be complete
|
// environment overrides edgerc file but config needs to be complete
|
||||||
if akamaiConfig.ServiceConsumerDomain == "" || akamaiConfig.ClientToken == "" || akamaiConfig.ClientSecret == "" || akamaiConfig.AccessToken == "" {
|
if akamaiConfig.ServiceConsumerDomain == "" || akamaiConfig.ClientToken == "" || akamaiConfig.ClientSecret == "" || akamaiConfig.AccessToken == "" {
|
||||||
// Kubernetes config incomplete or non existent. Can't mix and match.
|
// Kubernetes config incomplete or non existent. Can't mix and match.
|
||||||
@ -106,7 +98,7 @@ func NewAkamaiProvider(akamaiConfig AkamaiConfig, akaService AkamaiDNSService) (
|
|||||||
edgeGridConfig, err = edgegrid.Init(akamaiConfig.EdgercPath, akamaiConfig.EdgercSection) // use default .edgerc location and section
|
edgeGridConfig, err = edgegrid.Init(akamaiConfig.EdgercPath, akamaiConfig.EdgercSection) // use default .edgerc location and section
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Edgegrid Init Failed")
|
log.Errorf("Edgegrid Init Failed")
|
||||||
return &AkamaiProvider{}, err // return empty provider for backward compatibility
|
return &AkamaiProvider{}, err // return an empty provider for backward compatibility
|
||||||
}
|
}
|
||||||
edgeGridConfig.HeaderToSign = append(edgeGridConfig.HeaderToSign, "X-External-DNS")
|
edgeGridConfig.HeaderToSign = append(edgeGridConfig.HeaderToSign, "X-External-DNS")
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/pvtz"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/pvtz"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"sigs.k8s.io/external-dns/endpoint"
|
"sigs.k8s.io/external-dns/endpoint"
|
||||||
"sigs.k8s.io/external-dns/plan"
|
"sigs.k8s.io/external-dns/plan"
|
||||||
@ -223,18 +224,7 @@ func newTestAlibabaCloudProvider(private bool) *AlibabaCloudProvider {
|
|||||||
cfg := alibabaCloudConfig{
|
cfg := alibabaCloudConfig{
|
||||||
VPCID: "vpc-xxxxxx",
|
VPCID: "vpc-xxxxxx",
|
||||||
}
|
}
|
||||||
//
|
|
||||||
//dnsClient, _ := alidns.NewClientWithAccessKey(
|
|
||||||
// cfg.RegionID,
|
|
||||||
// cfg.AccessKeyID,
|
|
||||||
// cfg.AccessKeySecret,
|
|
||||||
//)
|
|
||||||
//
|
|
||||||
//pvtzClient, _ := pvtz.NewClientWithAccessKey(
|
|
||||||
// "cn-hangzhou",
|
|
||||||
// cfg.AccessKeyID,
|
|
||||||
// cfg.AccessKeySecret,
|
|
||||||
//)
|
|
||||||
domainFilterTest := endpoint.NewDomainFilter([]string{"container-service.top.", "example.org"})
|
domainFilterTest := endpoint.NewDomainFilter([]string{"container-service.top.", "example.org"})
|
||||||
|
|
||||||
return &AlibabaCloudProvider{
|
return &AlibabaCloudProvider{
|
||||||
@ -256,8 +246,8 @@ func TestAlibabaCloudPrivateProvider_Records(t *testing.T) {
|
|||||||
if len(endpoints) != 2 {
|
if len(endpoints) != 2 {
|
||||||
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
||||||
}
|
}
|
||||||
for _, endpoint := range endpoints {
|
for _, ep := range endpoints {
|
||||||
t.Logf("Endpoint for %++v", *endpoint)
|
t.Logf("Endpoint for %++v", *ep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,8 +261,8 @@ func TestAlibabaCloudProvider_Records(t *testing.T) {
|
|||||||
if len(endpoints) != 2 {
|
if len(endpoints) != 2 {
|
||||||
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
||||||
}
|
}
|
||||||
for _, endpoint := range endpoints {
|
for _, ep := range endpoints {
|
||||||
t.Logf("Endpoint for %++v", *endpoint)
|
t.Logf("Endpoint for %++v", *ep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +303,8 @@ func TestAlibabaCloudProvider_ApplyChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
p.ApplyChanges(ctx, &changes)
|
err := p.ApplyChanges(ctx, &changes)
|
||||||
|
assert.NoError(t, err)
|
||||||
endpoints, err := p.Records(ctx)
|
endpoints, err := p.Records(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to get records: %v", err)
|
t.Errorf("Failed to get records: %v", err)
|
||||||
@ -321,8 +312,8 @@ func TestAlibabaCloudProvider_ApplyChanges(t *testing.T) {
|
|||||||
if len(endpoints) != 3 {
|
if len(endpoints) != 3 {
|
||||||
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
||||||
}
|
}
|
||||||
for _, endpoint := range endpoints {
|
for _, ep := range endpoints {
|
||||||
t.Logf("Endpoint for %++v", *endpoint)
|
t.Logf("Endpoint for %++v", *ep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, ep := range endpoints {
|
for _, ep := range endpoints {
|
||||||
@ -343,8 +334,8 @@ func TestAlibabaCloudProvider_Records_PrivateZone(t *testing.T) {
|
|||||||
if len(endpoints) != 2 {
|
if len(endpoints) != 2 {
|
||||||
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
||||||
}
|
}
|
||||||
for _, endpoint := range endpoints {
|
for _, ep := range endpoints {
|
||||||
t.Logf("Endpoint for %++v", *endpoint)
|
t.Logf("Endpoint for %++v", *ep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,7 +369,8 @@ func TestAlibabaCloudProvider_ApplyChanges_PrivateZone(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
p.ApplyChanges(ctx, &changes)
|
err := p.ApplyChanges(ctx, &changes)
|
||||||
|
assert.NoError(t, err)
|
||||||
endpoints, err := p.Records(ctx)
|
endpoints, err := p.Records(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to get records: %v", err)
|
t.Errorf("Failed to get records: %v", err)
|
||||||
@ -386,8 +378,8 @@ func TestAlibabaCloudProvider_ApplyChanges_PrivateZone(t *testing.T) {
|
|||||||
if len(endpoints) != 2 {
|
if len(endpoints) != 2 {
|
||||||
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
t.Errorf("Incorrect number of records: %d", len(endpoints))
|
||||||
}
|
}
|
||||||
for _, endpoint := range endpoints {
|
for _, ep := range endpoints {
|
||||||
t.Logf("Endpoint for %++v", *endpoint)
|
t.Logf("Endpoint for %++v", *ep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ type profiledZone struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cs Route53Changes) Route53Changes() []route53types.Change {
|
func (cs Route53Changes) Route53Changes() []route53types.Change {
|
||||||
ret := []route53types.Change{}
|
var ret []route53types.Change
|
||||||
for _, c := range cs {
|
for _, c := range cs {
|
||||||
ret = append(ret, c.Change)
|
ret = append(ret, c.Change)
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ type AWSConfig struct {
|
|||||||
|
|
||||||
// NewAWSProvider initializes a new AWS Route53 based Provider.
|
// NewAWSProvider initializes a new AWS Route53 based Provider.
|
||||||
func NewAWSProvider(awsConfig AWSConfig, clients map[string]Route53API) (*AWSProvider, error) {
|
func NewAWSProvider(awsConfig AWSConfig, clients map[string]Route53API) (*AWSProvider, error) {
|
||||||
provider := &AWSProvider{
|
pr := &AWSProvider{
|
||||||
clients: clients,
|
clients: clients,
|
||||||
domainFilter: awsConfig.DomainFilter,
|
domainFilter: awsConfig.DomainFilter,
|
||||||
zoneIDFilter: awsConfig.ZoneIDFilter,
|
zoneIDFilter: awsConfig.ZoneIDFilter,
|
||||||
@ -331,7 +331,7 @@ func NewAWSProvider(awsConfig AWSConfig, clients map[string]Route53API) (*AWSPro
|
|||||||
failedChangesQueue: make(map[string]Route53Changes),
|
failedChangesQueue: make(map[string]Route53Changes),
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider, nil
|
return pr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zones returns the list of hosted zones.
|
// Zones returns the list of hosted zones.
|
||||||
@ -561,33 +561,33 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Identify if old and new endpoints require DELETE/CREATE instead of UPDATE.
|
// Identify if old and new endpoints require DELETE/CREATE instead of UPDATE.
|
||||||
func (p *AWSProvider) requiresDeleteCreate(old *endpoint.Endpoint, new *endpoint.Endpoint) bool {
|
func (p *AWSProvider) requiresDeleteCreate(old *endpoint.Endpoint, newE *endpoint.Endpoint) bool {
|
||||||
// a change of record type
|
// a change of a record type
|
||||||
if old.RecordType != new.RecordType {
|
if old.RecordType != newE.RecordType {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// an ALIAS record change to/from an A
|
// an ALIAS record change to/from an A
|
||||||
if old.RecordType == endpoint.RecordTypeA {
|
if old.RecordType == endpoint.RecordTypeA {
|
||||||
oldAlias, _ := old.GetProviderSpecificProperty(providerSpecificAlias)
|
oldAlias, _ := old.GetProviderSpecificProperty(providerSpecificAlias)
|
||||||
newAlias, _ := new.GetProviderSpecificProperty(providerSpecificAlias)
|
newAlias, _ := newE.GetProviderSpecificProperty(providerSpecificAlias)
|
||||||
if oldAlias != newAlias {
|
if oldAlias != newAlias {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// a set identifier change
|
// a set identifier change
|
||||||
if old.SetIdentifier != new.SetIdentifier {
|
if old.SetIdentifier != newE.SetIdentifier {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// a change of routing policy
|
// a change of routing policy
|
||||||
// default to true for geolocation properties if any geolocation property exists in old/new but not the other
|
// defaults to true for geolocation properties if any geolocation property exists in old/new but not the other
|
||||||
for _, propType := range [7]string{providerSpecificWeight, providerSpecificRegion, providerSpecificFailover,
|
for _, propType := range [7]string{providerSpecificWeight, providerSpecificRegion, providerSpecificFailover,
|
||||||
providerSpecificFailover, providerSpecificGeolocationContinentCode, providerSpecificGeolocationCountryCode,
|
providerSpecificFailover, providerSpecificGeolocationContinentCode, providerSpecificGeolocationCountryCode,
|
||||||
providerSpecificGeolocationSubdivisionCode} {
|
providerSpecificGeolocationSubdivisionCode} {
|
||||||
_, oldPolicy := old.GetProviderSpecificProperty(propType)
|
_, oldPolicy := old.GetProviderSpecificProperty(propType)
|
||||||
_, newPolicy := new.GetProviderSpecificProperty(propType)
|
_, newPolicy := newE.GetProviderSpecificProperty(propType)
|
||||||
if oldPolicy != newPolicy {
|
if oldPolicy != newPolicy {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -601,14 +601,14 @@ func (p *AWSProvider) createUpdateChanges(newEndpoints, oldEndpoints []*endpoint
|
|||||||
var creates []*endpoint.Endpoint
|
var creates []*endpoint.Endpoint
|
||||||
var updates []*endpoint.Endpoint
|
var updates []*endpoint.Endpoint
|
||||||
|
|
||||||
for i, new := range newEndpoints {
|
for i, newE := range newEndpoints {
|
||||||
old := oldEndpoints[i]
|
oldE := oldEndpoints[i]
|
||||||
if p.requiresDeleteCreate(old, new) {
|
if p.requiresDeleteCreate(oldE, newE) {
|
||||||
deletes = append(deletes, old)
|
deletes = append(deletes, oldE)
|
||||||
creates = append(creates, new)
|
creates = append(creates, newE)
|
||||||
} else {
|
} else {
|
||||||
// Safe to perform an UPSERT.
|
// Safe to perform an UPSERT.
|
||||||
updates = append(updates, new)
|
updates = append(updates, newE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,8 +760,8 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes Route53Changes,
|
|||||||
func (p *AWSProvider) newChanges(action route53types.ChangeAction, endpoints []*endpoint.Endpoint) Route53Changes {
|
func (p *AWSProvider) newChanges(action route53types.ChangeAction, endpoints []*endpoint.Endpoint) Route53Changes {
|
||||||
changes := make(Route53Changes, 0, len(endpoints))
|
changes := make(Route53Changes, 0, len(endpoints))
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, ep := range endpoints {
|
||||||
change := p.newChange(action, endpoint)
|
change := p.newChange(action, ep)
|
||||||
changes = append(changes, change)
|
changes = append(changes, change)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func TestGetCloudConfiguration(t *testing.T) {
|
|||||||
|
|
||||||
func TestOverrideConfiguration(t *testing.T) {
|
func TestOverrideConfiguration(t *testing.T) {
|
||||||
_, filename, _, _ := runtime.Caller(0)
|
_, filename, _, _ := runtime.Caller(0)
|
||||||
configFile := path.Join(path.Dir(filename), "config_test.json")
|
configFile := path.Join(path.Dir(filename), "fixtures/config_test.json")
|
||||||
cfg, err := getConfig(configFile, "subscription-override", "rg-override", "", "aad-endpoint-override")
|
cfg, err := getConfig(configFile, "subscription-override", "rg-override", "", "aad-endpoint-override")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("got unexpected err %v", err)
|
t.Errorf("got unexpected err %v", err)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"tenantId": "tenant",
|
"tenantId": "tenant",
|
||||||
"subscriptionId": "subscription",
|
"subscriptionId": "subscription",
|
||||||
"resourceGroup": "rg",
|
"resourceGroup": "rg",
|
||||||
"aadClientId": "clientId",
|
"aadClientId": "clientId",
|
||||||
"aadClientSecret": "clientSecret"
|
"aadClientSecret": "clientSecret"
|
||||||
}
|
}
|
@ -310,10 +310,10 @@ func (f *zoneFilter) EndpointZoneID(endpoint *endpoint.Endpoint, zones map[strin
|
|||||||
|
|
||||||
func merge(updateOld, updateNew []*endpoint.Endpoint) []*endpoint.Endpoint {
|
func merge(updateOld, updateNew []*endpoint.Endpoint) []*endpoint.Endpoint {
|
||||||
findMatch := func(template *endpoint.Endpoint) *endpoint.Endpoint {
|
findMatch := func(template *endpoint.Endpoint) *endpoint.Endpoint {
|
||||||
for _, new := range updateNew {
|
for _, record := range updateNew {
|
||||||
if template.DNSName == new.DNSName &&
|
if template.DNSName == record.DNSName &&
|
||||||
template.RecordType == new.RecordType {
|
template.RecordType == record.RecordType {
|
||||||
return new
|
return record
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -323,7 +323,7 @@ func merge(updateOld, updateNew []*endpoint.Endpoint) []*endpoint.Endpoint {
|
|||||||
for _, old := range updateOld {
|
for _, old := range updateOld {
|
||||||
matchingNew := findMatch(old)
|
matchingNew := findMatch(old)
|
||||||
if matchingNew == nil {
|
if matchingNew == nil {
|
||||||
// no match, shouldn't happen
|
// no match shouldn't happen
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ package godaddy
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -46,9 +46,6 @@ var actionNames = []string{
|
|||||||
|
|
||||||
const domainsURI = "/v1/domains?statuses=ACTIVE,PENDING_DNS_ACTIVE"
|
const domainsURI = "/v1/domains?statuses=ACTIVE,PENDING_DNS_ACTIVE"
|
||||||
|
|
||||||
// ErrRecordToMutateNotFound when ApplyChange has to update/delete and didn't found the record in the existing zone (Change with no record ID)
|
|
||||||
var ErrRecordToMutateNotFound = errors.New("record to mutate not found in current zone")
|
|
||||||
|
|
||||||
type gdClient interface {
|
type gdClient interface {
|
||||||
Patch(string, interface{}, interface{}) error
|
Patch(string, interface{}, interface{}) error
|
||||||
Post(string, interface{}, interface{}) error
|
Post(string, interface{}, interface{}) error
|
||||||
@ -294,14 +291,14 @@ func (p *GDProvider) groupByNameAndType(zoneRecords []gdRecords) []*endpoint.End
|
|||||||
recordName = strings.TrimPrefix(fmt.Sprintf("%s.%s", records[0].Name, zoneName), ".")
|
recordName = strings.TrimPrefix(fmt.Sprintf("%s.%s", records[0].Name, zoneName), ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := endpoint.NewEndpointWithTTL(
|
ep := endpoint.NewEndpointWithTTL(
|
||||||
recordName,
|
recordName,
|
||||||
records[0].Type,
|
records[0].Type,
|
||||||
endpoint.TTL(records[0].TTL),
|
endpoint.TTL(records[0].TTL),
|
||||||
targets...,
|
targets...,
|
||||||
)
|
)
|
||||||
|
|
||||||
endpoints = append(endpoints, endpoint)
|
endpoints = append(endpoints, ep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,8 +581,8 @@ func countTargets(p *plan.Changes) int {
|
|||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
for _, endpoints := range changes {
|
for _, endpoints := range changes {
|
||||||
for _, endpoint := range endpoints {
|
for _, ep := range endpoints {
|
||||||
count += len(endpoint.Targets)
|
count += len(ep.Targets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,15 +590,7 @@ func countTargets(p *plan.Changes) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func maxOf(vars ...int64) int64 {
|
func maxOf(vars ...int64) int64 {
|
||||||
max := vars[0]
|
return slices.Max(vars)
|
||||||
|
|
||||||
for _, i := range vars {
|
|
||||||
if max < i {
|
|
||||||
max = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return max
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func toString(obj interface{}) string {
|
func toString(obj interface{}) string {
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
yaml "github.com/goccy/go-yaml"
|
"github.com/goccy/go-yaml"
|
||||||
"github.com/oracle/oci-go-sdk/v65/common"
|
"github.com/oracle/oci-go-sdk/v65/common"
|
||||||
"github.com/oracle/oci-go-sdk/v65/common/auth"
|
"github.com/oracle/oci-go-sdk/v65/common/auth"
|
||||||
"github.com/oracle/oci-go-sdk/v65/dns"
|
"github.com/oracle/oci-go-sdk/v65/dns"
|
||||||
@ -153,7 +153,7 @@ func (p *OCIProvider) zones(ctx context.Context) (map[string]dns.ZoneSummary, er
|
|||||||
}
|
}
|
||||||
zones := make(map[string]dns.ZoneSummary)
|
zones := make(map[string]dns.ZoneSummary)
|
||||||
scopes := []dns.GetZoneScopeEnum{dns.GetZoneScopeEnum(p.zoneScope)}
|
scopes := []dns.GetZoneScopeEnum{dns.GetZoneScopeEnum(p.zoneScope)}
|
||||||
// If zone scope is empty, list all zones types.
|
// If the zone scope is empty, list all zones types.
|
||||||
if p.zoneScope == "" {
|
if p.zoneScope == "" {
|
||||||
scopes = dns.GetGetZoneScopeEnumValues()
|
scopes = dns.GetGetZoneScopeEnumValues()
|
||||||
}
|
}
|
||||||
@ -232,7 +232,7 @@ func (p *OCIProvider) addPaginatedZones(ctx context.Context, zones map[string]dn
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *OCIProvider) newFilteredRecordOperations(endpoints []*endpoint.Endpoint, opType dns.RecordOperationOperationEnum) []dns.RecordOperation {
|
func (p *OCIProvider) newFilteredRecordOperations(endpoints []*endpoint.Endpoint, opType dns.RecordOperationOperationEnum) []dns.RecordOperation {
|
||||||
ops := []dns.RecordOperation{}
|
var ops []dns.RecordOperation
|
||||||
for _, ep := range endpoints {
|
for _, ep := range endpoints {
|
||||||
if ep == nil {
|
if ep == nil {
|
||||||
continue
|
continue
|
||||||
@ -261,7 +261,7 @@ func (p *OCIProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
|
|||||||
return nil, provider.NewSoftError(fmt.Errorf("getting zones: %w", err))
|
return nil, provider.NewSoftError(fmt.Errorf("getting zones: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoints := []*endpoint.Endpoint{}
|
var endpoints []*endpoint.Endpoint
|
||||||
for _, zone := range zones {
|
for _, zone := range zones {
|
||||||
var page *string
|
var page *string
|
||||||
for {
|
for {
|
||||||
@ -303,7 +303,7 @@ func (p *OCIProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
|
|||||||
func (p *OCIProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
func (p *OCIProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
||||||
log.Debugf("Processing changes: %+v", changes)
|
log.Debugf("Processing changes: %+v", changes)
|
||||||
|
|
||||||
ops := []dns.RecordOperation{}
|
var ops []dns.RecordOperation
|
||||||
ops = append(ops, p.newFilteredRecordOperations(changes.Create, dns.RecordOperationOperationAdd)...)
|
ops = append(ops, p.newFilteredRecordOperations(changes.Create, dns.RecordOperationOperationAdd)...)
|
||||||
|
|
||||||
ops = append(ops, p.newFilteredRecordOperations(changes.UpdateNew, dns.RecordOperationOperationAdd)...)
|
ops = append(ops, p.newFilteredRecordOperations(changes.UpdateNew, dns.RecordOperationOperationAdd)...)
|
||||||
@ -349,7 +349,7 @@ func (p *OCIProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) e
|
|||||||
|
|
||||||
// AdjustEndpoints modifies the endpoints as needed by the specific provider
|
// AdjustEndpoints modifies the endpoints as needed by the specific provider
|
||||||
func (p *OCIProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
|
func (p *OCIProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
|
||||||
adjustedEndpoints := []*endpoint.Endpoint{}
|
var adjustedEndpoints []*endpoint.Endpoint
|
||||||
for _, e := range endpoints {
|
for _, e := range endpoints {
|
||||||
// OCI DNS does not support the set-identifier attribute, so we remove it to avoid plan failure
|
// OCI DNS does not support the set-identifier attribute, so we remove it to avoid plan failure
|
||||||
if e.SetIdentifier != "" {
|
if e.SetIdentifier != "" {
|
||||||
|
@ -300,12 +300,12 @@ func (im *DynamoDBRegistry) ApplyChanges(ctx context.Context, changes *plan.Chan
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i, endpoint := range filteredChanges.Create {
|
for i, ep := range filteredChanges.Create {
|
||||||
if endpoint.Key() == key {
|
if ep.Key() == key {
|
||||||
log.Infof("Skipping endpoint %v because owner does not match", endpoint)
|
log.Infof("Skipping endpoint %v because owner does not match", ep)
|
||||||
filteredChanges.Create = append(filteredChanges.Create[:i], filteredChanges.Create[i+1:]...)
|
filteredChanges.Create = append(filteredChanges.Create[:i], filteredChanges.Create[i+1:]...)
|
||||||
// The dynamodb insertion failed; remove from our cache.
|
// The dynamodb insertion failed; remove from our cache.
|
||||||
im.removeFromCache(endpoint)
|
im.removeFromCache(ep)
|
||||||
delete(im.labels, key)
|
delete(im.labels, key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ func toDynamoLabels(labels endpoint.Labels) dynamodbtypes.AttributeValue {
|
|||||||
return &dynamodbtypes.AttributeValueMemberM{Value: labelMap}
|
return &dynamodbtypes.AttributeValueMemberM{Value: labelMap}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im *DynamoDBRegistry) appendInsert(statements []dynamodbtypes.BatchStatementRequest, key endpoint.EndpointKey, new endpoint.Labels) []dynamodbtypes.BatchStatementRequest {
|
func (im *DynamoDBRegistry) appendInsert(statements []dynamodbtypes.BatchStatementRequest, key endpoint.EndpointKey, newL endpoint.Labels) []dynamodbtypes.BatchStatementRequest {
|
||||||
return append(statements, dynamodbtypes.BatchStatementRequest{
|
return append(statements, dynamodbtypes.BatchStatementRequest{
|
||||||
Statement: aws.String(fmt.Sprintf("INSERT INTO %q VALUE {'k':?, 'o':?, 'l':?}", im.table)),
|
Statement: aws.String(fmt.Sprintf("INSERT INTO %q VALUE {'k':?, 'o':?, 'l':?}", im.table)),
|
||||||
ConsistentRead: aws.Bool(true),
|
ConsistentRead: aws.Bool(true),
|
||||||
@ -475,16 +475,16 @@ func (im *DynamoDBRegistry) appendInsert(statements []dynamodbtypes.BatchStateme
|
|||||||
&dynamodbtypes.AttributeValueMemberS{
|
&dynamodbtypes.AttributeValueMemberS{
|
||||||
Value: im.ownerID,
|
Value: im.ownerID,
|
||||||
},
|
},
|
||||||
toDynamoLabels(new),
|
toDynamoLabels(newL),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im *DynamoDBRegistry) appendUpdate(statements []dynamodbtypes.BatchStatementRequest, key endpoint.EndpointKey, old endpoint.Labels, new endpoint.Labels) []dynamodbtypes.BatchStatementRequest {
|
func (im *DynamoDBRegistry) appendUpdate(statements []dynamodbtypes.BatchStatementRequest, key endpoint.EndpointKey, old endpoint.Labels, newE endpoint.Labels) []dynamodbtypes.BatchStatementRequest {
|
||||||
if len(old) == len(new) {
|
if len(old) == len(newE) {
|
||||||
equal := true
|
equal := true
|
||||||
for k, v := range old {
|
for k, v := range old {
|
||||||
if newV, exists := new[k]; !exists || v != newV {
|
if newV, exists := newE[k]; !exists || v != newV {
|
||||||
equal = false
|
equal = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -497,7 +497,7 @@ func (im *DynamoDBRegistry) appendUpdate(statements []dynamodbtypes.BatchStateme
|
|||||||
return append(statements, dynamodbtypes.BatchStatementRequest{
|
return append(statements, dynamodbtypes.BatchStatementRequest{
|
||||||
Statement: aws.String(fmt.Sprintf("UPDATE %q SET \"l\"=? WHERE \"k\"=?", im.table)),
|
Statement: aws.String(fmt.Sprintf("UPDATE %q SET \"l\"=? WHERE \"k\"=?", im.table)),
|
||||||
Parameters: []dynamodbtypes.AttributeValue{
|
Parameters: []dynamodbtypes.AttributeValue{
|
||||||
toDynamoLabels(new),
|
toDynamoLabels(newE),
|
||||||
toDynamoKey(key),
|
toDynamoKey(key),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -148,7 +148,7 @@ func (cs *crdSource) AddEventHandler(ctx context.Context, handler func()) {
|
|||||||
AddFunc: func(obj interface{}) {
|
AddFunc: func(obj interface{}) {
|
||||||
handler()
|
handler()
|
||||||
},
|
},
|
||||||
UpdateFunc: func(old interface{}, new interface{}) {
|
UpdateFunc: func(old interface{}, newI interface{}) {
|
||||||
handler()
|
handler()
|
||||||
},
|
},
|
||||||
DeleteFunc: func(obj interface{}) {
|
DeleteFunc: func(obj interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user