From 1a4c7b5f3cc307ced6e3f22d3a386d38332ca0ce Mon Sep 17 00:00:00 2001 From: John Gardiner Myers Date: Mon, 12 Jun 2023 19:29:34 -0700 Subject: [PATCH] Support DynamoDB tables in other regions --- docs/registry/dynamodb.md | 1 + main.go | 7 ++++++- pkg/apis/externaldns/types.go | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/registry/dynamodb.md b/docs/registry/dynamodb.md index 92f90de69..9e5f8331f 100644 --- a/docs/registry/dynamodb.md +++ b/docs/registry/dynamodb.md @@ -6,6 +6,7 @@ The DynamoDB registry stores DNS record metadata in an AWS DynamoDB table. By default, the DynamoDB registry stores data in the table named `external-dns`. A different table may be specified using the `--dynamodb-table` flag. +A different region may be specified using the `--dynamodb-region` flag. The table must have a partition (hash) key named `k` and string type. The table must not have a sort (range) key. diff --git a/main.go b/main.go index 65dbb3e7e..d83a4e25d 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( "syscall" "time" + awsSDK "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/aws/aws-sdk-go/service/route53" @@ -397,7 +398,11 @@ func main() { var r registry.Registry switch cfg.Registry { case "dynamodb": - r, err = registry.NewDynamoDBRegistry(p, cfg.TXTOwnerID, dynamodb.New(awsSession), cfg.AWSDynamoDBTable, cfg.TXTCacheInterval) + config := awsSDK.NewConfig() + if cfg.AWSDynamoDBRegion != "" { + config = config.WithRegion(cfg.AWSDynamoDBRegion) + } + r, err = registry.NewDynamoDBRegistry(p, cfg.TXTOwnerID, dynamodb.New(awsSession, config), cfg.AWSDynamoDBTable, cfg.TXTCacheInterval) case "noop": r, err = registry.NewNoopRegistry(p) case "txt": diff --git a/pkg/apis/externaldns/types.go b/pkg/apis/externaldns/types.go index a45d9ad30..0b022ef6e 100644 --- a/pkg/apis/externaldns/types.go +++ b/pkg/apis/externaldns/types.go @@ -93,6 +93,7 @@ type Config struct { AWSPreferCNAME bool AWSZoneCacheDuration time.Duration AWSSDServiceCleanup bool + AWSDynamoDBRegion string AWSDynamoDBTable string AzureConfigFile string AzureResourceGroup string @@ -256,6 +257,7 @@ var defaultConfig = &Config{ AWSPreferCNAME: false, AWSZoneCacheDuration: 0 * time.Second, AWSSDServiceCleanup: false, + AWSDynamoDBRegion: "", AWSDynamoDBTable: "external-dns", AzureConfigFile: "/etc/kubernetes/azure.json", AzureResourceGroup: "", @@ -581,6 +583,7 @@ func (cfg *Config) ParseFlags(args []string) error { app.Flag("txt-wildcard-replacement", "When using the TXT registry, a custom string that's used instead of an asterisk for TXT records corresponding to wildcard DNS records (optional)").Default(defaultConfig.TXTWildcardReplacement).StringVar(&cfg.TXTWildcardReplacement) app.Flag("txt-encrypt-enabled", "When using the TXT registry, set if TXT records should be encrypted before stored (default: disabled)").BoolVar(&cfg.TXTEncryptEnabled) app.Flag("txt-encrypt-aes-key", "When using the TXT registry, set TXT record decryption and encryption 32 byte aes key (required when --txt-encrypt=true)").Default(defaultConfig.TXTEncryptAESKey).StringVar(&cfg.TXTEncryptAESKey) + app.Flag("dynamodb-region", "When using the DynamoDB registry, the AWS region of the DynamoDB table (optional)").Default(cfg.AWSDynamoDBRegion).StringVar(&cfg.AWSDynamoDBRegion) app.Flag("dynamodb-table", "When using the DynamoDB registry, the name of the DynamoDB table (default: \"external-dns\")").Default(defaultConfig.AWSDynamoDBTable).StringVar(&cfg.AWSDynamoDBTable) // Flags related to the main control loop