From 402a1ed08dae31e783906626887f13e6b134c64c Mon Sep 17 00:00:00 2001 From: rasel Date: Mon, 15 Apr 2024 19:00:15 +0600 Subject: [PATCH] Fix aws client issue Signed-off-by: rasel --- apis/external/v1alpha1/openapi_generated.go | 7 --- .../v1alpha1/zz_generated.deepcopy.go | 5 -- ...ternal-dns.appscode.com_externaldnses.yaml | 4 -- pkg/plan/plan.go | 56 ++++++++++++------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/apis/external/v1alpha1/openapi_generated.go b/apis/external/v1alpha1/openapi_generated.go index c8f9a1f0..2d7ec649 100644 --- a/apis/external/v1alpha1/openapi_generated.go +++ b/apis/external/v1alpha1/openapi_generated.go @@ -18530,13 +18530,6 @@ func schema_external_dns_operator_apis_external_v1alpha1_CloudflareProvider(ref Format: "", }, }, - "zonesPerPage": { - SchemaProps: spec.SchemaProps{ - Description: "When using the Cloudflare provider, specify how many zones per page listed, max. possible 50 (default: 50)", - Type: []string{"integer"}, - Format: "int32", - }, - }, "baseURL": { SchemaProps: spec.SchemaProps{ Type: []string{"string"}, diff --git a/apis/external/v1alpha1/zz_generated.deepcopy.go b/apis/external/v1alpha1/zz_generated.deepcopy.go index b015ebb7..d0919558 100644 --- a/apis/external/v1alpha1/zz_generated.deepcopy.go +++ b/apis/external/v1alpha1/zz_generated.deepcopy.go @@ -143,11 +143,6 @@ func (in *CloudflareProvider) DeepCopyInto(out *CloudflareProvider) { *out = new(bool) **out = **in } - if in.ZonesPerPage != nil { - in, out := &in.ZonesPerPage, &out.ZonesPerPage - *out = new(int) - **out = **in - } if in.SecretRef != nil { in, out := &in.SecretRef, &out.SecretRef *out = new(CloudflareSecretReference) diff --git a/crds/external-dns.appscode.com_externaldnses.yaml b/crds/external-dns.appscode.com_externaldnses.yaml index 371d6b84..79875689 100644 --- a/crds/external-dns.appscode.com_externaldnses.yaml +++ b/crds/external-dns.appscode.com_externaldnses.yaml @@ -162,10 +162,6 @@ spec: required: - name type: object - zonesPerPage: - description: 'When using the Cloudflare provider, specify how - many zones per page listed, max. possible 50 (default: 50)' - type: integer type: object connectorSourceServer: description: The server to connect for connector source, valid only diff --git a/pkg/plan/plan.go b/pkg/plan/plan.go index 110ff8d3..c540b6bf 100644 --- a/pkg/plan/plan.go +++ b/pkg/plan/plan.go @@ -26,6 +26,9 @@ import ( api "kubeops.dev/external-dns-operator/apis/external/v1alpha1" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/route53" + sd "github.com/aws/aws-sdk-go/service/servicediscovery" "github.com/sirupsen/logrus" "gomodules.xyz/sets" "k8s.io/apimachinery/pkg/labels" @@ -46,7 +49,6 @@ import ( "sigs.k8s.io/external-dns/provider/digitalocean" "sigs.k8s.io/external-dns/provider/dnsimple" "sigs.k8s.io/external-dns/provider/dyn" - "sigs.k8s.io/external-dns/provider/exoscale" "sigs.k8s.io/external-dns/provider/gandi" "sigs.k8s.io/external-dns/provider/godaddy" "sigs.k8s.io/external-dns/provider/google" @@ -220,7 +222,7 @@ func SetDNSRecords(ctx context.Context, edns *api.ExternalDNS) ([]api.DNSRecord, return nil, err } - reg, err := createRegistry(cfg, *pvdr) + reg, err := createRegistry(cfg, pvdr) if err != nil { klog.Errorf("failed to create Registry.", err.Error()) return nil, err @@ -588,7 +590,7 @@ func createEndpointsSource(ctx context.Context, cfg *externaldns.Config) (source return endpointsSource, nil } -func createProviderFromCfg(ctx context.Context, cfg *externaldns.Config, endpointsSource source.Source) (*provider.Provider, error) { +func createProviderFromCfg(ctx context.Context, cfg *externaldns.Config, endpointsSource source.Source) (provider.Provider, error) { var p provider.Provider var err error @@ -604,6 +606,20 @@ func createProviderFromCfg(ctx context.Context, cfg *externaldns.Config, endpoin zoneTypeFilter := provider.NewZoneTypeFilter(cfg.AWSZoneType) zoneTagFilter := provider.NewZoneTagFilter(cfg.AWSZoneTagFilter) + var awsSession *session.Session + if cfg.Provider == "aws" || cfg.Provider == "aws-sd" { + awsSession, err = aws.NewSession( + aws.AWSSessionConfig{ + AssumeRole: cfg.AWSAssumeRole, + AssumeRoleExternalID: cfg.AWSAssumeRoleExternalID, + APIRetries: cfg.AWSAPIRetries, + }, + ) + if err != nil { + log.Fatal(err) + } + } + switch cfg.Provider { case "akamai": p, err = akamai.NewAkamaiProvider( @@ -623,27 +639,27 @@ func createProviderFromCfg(ctx context.Context, cfg *externaldns.Config, endpoin case "aws": p, err = aws.NewAWSProvider( aws.AWSConfig{ - DomainFilter: domainFilter, - ZoneIDFilter: zoneIDFilter, - ZoneTypeFilter: zoneTypeFilter, - ZoneTagFilter: zoneTagFilter, - BatchChangeSize: cfg.AWSBatchChangeSize, - BatchChangeInterval: cfg.AWSBatchChangeInterval, - EvaluateTargetHealth: cfg.AWSEvaluateTargetHealth, - // FIX - // AssumeRole: cfg.AWSAssumeRole, - // APIRetries: cfg.AWSAPIRetries, - PreferCNAME: cfg.AWSPreferCNAME, - DryRun: cfg.DryRun, - ZoneCacheDuration: cfg.AWSZoneCacheDuration, + DomainFilter: domainFilter, + ZoneIDFilter: zoneIDFilter, + ZoneTypeFilter: zoneTypeFilter, + ZoneTagFilter: zoneTagFilter, + ZoneMatchParent: cfg.AWSZoneMatchParent, + BatchChangeSize: cfg.AWSBatchChangeSize, + BatchChangeSizeBytes: cfg.AWSBatchChangeSizeBytes, + BatchChangeSizeValues: cfg.AWSBatchChangeSizeValues, + BatchChangeInterval: cfg.AWSBatchChangeInterval, + EvaluateTargetHealth: cfg.AWSEvaluateTargetHealth, + PreferCNAME: cfg.AWSPreferCNAME, + DryRun: cfg.DryRun, + ZoneCacheDuration: cfg.AWSZoneCacheDuration, }, - nil, // FIX + route53.New(awsSession), ) case providerAWSSD: if cfg.Registry != "noop" && cfg.Registry != providerAWSSD { cfg.Registry = providerAWSSD } - p, err = awssd.NewAWSSDProvider(domainFilter, cfg.AWSZoneType, cfg.DryRun, cfg.AWSSDServiceCleanup, cfg.TXTOwnerID /* FIX */, nil) + p, err = awssd.NewAWSSDProvider(domainFilter, cfg.AWSZoneType, cfg.DryRun, cfg.AWSSDServiceCleanup, cfg.TXTOwnerID, sd.New(awsSession)) case "azure-dns", "azure": p, err = azure.NewAzureProvider(cfg.AzureConfigFile, domainFilter, zoneNameFilter, zoneIDFilter, "FIX -- subscriptionID", cfg.AzureResourceGroup, cfg.AzureUserAssignedIdentityClientID, cfg.DryRun) case "azure-private-dns": @@ -711,8 +727,6 @@ func createProviderFromCfg(ctx context.Context, cfg *externaldns.Config, endpoin DryRun: cfg.DryRun, }, ) - case "exoscale": - p, err = exoscale.NewExoscaleProvider(cfg.ExoscaleAPIEnvironment, cfg.ExoscaleAPIZone, cfg.ExoscaleAPIKey, cfg.ExoscaleAPISecret, cfg.DryRun, exoscale.ExoscaleWithDomain(domainFilter), exoscale.ExoscaleWithLogging()), nil case "inmemory": p, err = inmemory.NewInMemoryProvider(inmemory.InMemoryInitZones(cfg.InMemoryZones), inmemory.InMemoryWithDomain(domainFilter), inmemory.InMemoryWithLogging()), nil case "designate": @@ -767,7 +781,7 @@ func createProviderFromCfg(ctx context.Context, cfg *externaldns.Config, endpoin log.Fatalf("unknown dns provider: %s", cfg.Provider) } - return &p, err + return p, err } func createRegistry(cfg *externaldns.Config, p provider.Provider) (registry.Registry, error) {