Skip to content

Commit

Permalink
added sleep time between paging ListResourceRecordSet
Browse files Browse the repository at this point in the history
  • Loading branch information
oferz-everc committed Jul 14, 2024
1 parent eadce08 commit f8064db
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions charts/external-dns/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ spec:
{{- range .Values.extraArgs }}
- {{ tpl . $ }}
{{- end }}
{{- if .Values.awsPagingInterval }}
- --aws-paging-interval={{ .Values.awsPagingInterval }}
{{- end }}
ports:
- name: http
protocol: TCP
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorials/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ Running several fast polling ExternalDNS instances in a given account can easily
* `--aws-batch-change-size=4000` (default `1000`)
* Increase the interval between changes
* `--aws-batch-change-interval=10s` (default `1s`)
* Increase the interval between paging through records (ListResourceRecordSet)
* `--aws-paging-interval=500` in milliseconds (default 0)
* Introducing some jitter to the pod initialization, so that when multiple instances of ExternalDNS are updated at the same time they do not make their requests on the same second.

A simple way to implement randomised startup is with an init container:
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func main() {
PreferCNAME: cfg.AWSPreferCNAME,
DryRun: cfg.DryRun,
ZoneCacheDuration: cfg.AWSZoneCacheDuration,
PagingInterval: cfg.AWSPagingInterval,
},
clients,
)
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type Config struct {
AWSZoneMatchParent bool
AWSDynamoDBRegion string
AWSDynamoDBTable string
AWSPagingInterval time.Duration
AzureConfigFile string
AzureResourceGroup string
AzureSubscriptionID string
Expand Down Expand Up @@ -267,6 +268,7 @@ var defaultConfig = &Config{
AWSSDServiceCleanup: false,
AWSDynamoDBRegion: "",
AWSDynamoDBTable: "external-dns",
AWSPagingInterval 0,
AzureConfigFile: "/etc/kubernetes/azure.json",
AzureResourceGroup: "",
AzureSubscriptionID: "",
Expand Down Expand Up @@ -477,6 +479,7 @@ func (cfg *Config) ParseFlags(args []string) error {
app.Flag("aws-batch-change-size-bytes", "When using the AWS provider, set the maximum byte size that will be applied in each batch.").Default(strconv.Itoa(defaultConfig.AWSBatchChangeSizeBytes)).IntVar(&cfg.AWSBatchChangeSizeBytes)
app.Flag("aws-batch-change-size-values", "When using the AWS provider, set the maximum total record values that will be applied in each batch.").Default(strconv.Itoa(defaultConfig.AWSBatchChangeSizeValues)).IntVar(&cfg.AWSBatchChangeSizeValues)
app.Flag("aws-batch-change-interval", "When using the AWS provider, set the interval between batch changes.").Default(defaultConfig.AWSBatchChangeInterval.String()).DurationVar(&cfg.AWSBatchChangeInterval)
app.Flag("aws-paging-interval", "When using the AWS provider, set the interval between paging throgugh ListResourceRecordSet calls.").Default(defaultConfig.AWSPagingInterval.String()).DurationVar(&cfg.AWSPagingInterval)
app.Flag("aws-evaluate-target-health", "When using the AWS provider, set whether to evaluate the health of a DNS target (default: enabled, disable with --no-aws-evaluate-target-health)").Default(strconv.FormatBool(defaultConfig.AWSEvaluateTargetHealth)).BoolVar(&cfg.AWSEvaluateTargetHealth)
app.Flag("aws-api-retries", "When using the AWS API, set the maximum number of retries before giving up.").Default(strconv.Itoa(defaultConfig.AWSAPIRetries)).IntVar(&cfg.AWSAPIRetries)
app.Flag("aws-prefer-cname", "When using the AWS provider, prefer using CNAME instead of ALIAS (default: disabled)").BoolVar(&cfg.AWSPreferCNAME)
Expand Down
13 changes: 11 additions & 2 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ type AWSConfig struct {
PreferCNAME bool
DryRun bool
ZoneCacheDuration time.Duration
PagingInterval time.Duration
}

// NewAWSProvider initializes a new AWS Route53 based Provider.
Expand All @@ -295,6 +296,7 @@ func NewAWSProvider(awsConfig AWSConfig, clients map[string]Route53API) (*AWSPro
preferCNAME: awsConfig.PreferCNAME,
dryRun: awsConfig.DryRun,
zonesCache: &zonesListCache{duration: awsConfig.ZoneCacheDuration},
pagingInterval awsConfig.PagingInterval,
failedChangesQueue: make(map[string]Route53Changes),
}

Expand Down Expand Up @@ -413,8 +415,15 @@ func (p *AWSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpoi
return p.records(ctx, zones)
}

func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZone) ([]*endpoint.Endpoint, error) {
func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZone, pagingInterval time.Duration) ([]*endpoint.Endpoint, error) {
endpoints := make([]*endpoint.Endpoint, 0)
pagingInterval := 0 * time.Second // default paging value
if p.awsPagingInterval != "" {
interval, err := time.ParseDuration(p.awsPagingInterval)
if err == nil {
pagingInterval = interval
}
}
f := func(resp *route53.ListResourceRecordSetsOutput, lastPage bool) (shouldContinue bool) {
for _, r := range resp.ResourceRecordSets {
newEndpoints := make([]*endpoint.Endpoint, 0)
Expand Down Expand Up @@ -488,7 +497,7 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon
endpoints = append(endpoints, ep)
}
}

time.Sleep(pagingInterval) // Added sleep interval between paging
return true
}

Expand Down

0 comments on commit f8064db

Please sign in to comment.