From 56d3730cb033c3164949175f6fedda0c3d810600 Mon Sep 17 00:00:00 2001 From: Lionello Lunesu Date: Thu, 9 Jan 2025 13:27:49 -0800 Subject: [PATCH] PR comments --- src/pkg/cli/client/byoc/aws/domain.go | 8 ++++---- src/pkg/clouds/aws/route53.go | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pkg/cli/client/byoc/aws/domain.go b/src/pkg/cli/client/byoc/aws/domain.go index 34da078e..39b9b135 100644 --- a/src/pkg/cli/client/byoc/aws/domain.go +++ b/src/pkg/cli/client/byoc/aws/domain.go @@ -31,13 +31,13 @@ func prepareDomainDelegation(ctx context.Context, projectDomain string, r53Clien term.Debugf("Zone %q not found, delegation set will be created", projectDomain) // Case 1: The zone doesn't exist: we'll create/get a delegation set and let CD/Pulumi create the hosted zone - delegationSet, err = prepareDomainDelegationFromDelegationSet(ctx, r53Client) + delegationSet, err = getOrCreateDelegationSet(ctx, r53Client) if err != nil { return nil, "", err } } else { // Case 2: Get the NS records for the existing subdomain zone - delegationSet, err = prepareDomainDelegationFromZone(ctx, zone, r53Client) + delegationSet, err = getOrCreateDelegationSetByZone(ctx, zone, r53Client) if err != nil { return nil, "", err } @@ -54,7 +54,7 @@ func prepareDomainDelegation(ctx context.Context, projectDomain string, r53Clien return delegationSet.NameServers, delegationSetId, nil } -func prepareDomainDelegationFromDelegationSet(ctx context.Context, r53Client aws.Route53API) (*types.DelegationSet, error) { +func getOrCreateDelegationSet(ctx context.Context, r53Client aws.Route53API) (*types.DelegationSet, error) { // Avoid creating a new delegation set if one already exists delegationSet, err := aws.GetDelegationSet(ctx, r53Client) // Create a new delegation set if it doesn't exist @@ -69,7 +69,7 @@ func prepareDomainDelegationFromDelegationSet(ctx context.Context, r53Client aws return delegationSet, err } -func prepareDomainDelegationFromZone(ctx context.Context, zone *types.HostedZone, r53Client aws.Route53API) (*types.DelegationSet, error) { +func getOrCreateDelegationSetByZone(ctx context.Context, zone *types.HostedZone, r53Client aws.Route53API) (*types.DelegationSet, error) { projectDomain := dns.Normalize(*zone.Name) nsServers, err := aws.ListResourceRecords(ctx, *zone.Id, projectDomain, types.RRTypeNs, r53Client) if err != nil { diff --git a/src/pkg/clouds/aws/route53.go b/src/pkg/clouds/aws/route53.go index 705e2d77..13f44647 100644 --- a/src/pkg/clouds/aws/route53.go +++ b/src/pkg/clouds/aws/route53.go @@ -3,6 +3,7 @@ package aws import ( "context" "errors" + "math/rand" "time" "github.com/DefangLabs/defang/src/pkg/dns" @@ -50,9 +51,7 @@ func GetDelegationSetByZone(ctx context.Context, zoneId *string, r53 Route53API) } func GetDelegationSet(ctx context.Context, r53 Route53API) (*types.DelegationSet, error) { - params := &route53.ListReusableDelegationSetsInput{ - MaxItems: ptr.Int32(1), - } + params := &route53.ListReusableDelegationSetsInput{} resp, err := r53.ListReusableDelegationSets(ctx, params) if err != nil { return nil, err @@ -60,7 +59,9 @@ func GetDelegationSet(ctx context.Context, r53 Route53API) (*types.DelegationSet if len(resp.DelegationSets) == 0 { return nil, ErrNoDelegationSetFound } - return &resp.DelegationSets[0], nil + // Return a random delegation set, to work around the 100 zones-per-delegation-set limit, + // because we can't easily tell how many zones are using each delegation set. + return &resp.DelegationSets[rand.Intn(len(resp.DelegationSets))], nil } func GetHostedZoneByName(ctx context.Context, domain string, r53 Route53API) (*types.HostedZone, error) {