Skip to content

Commit

Permalink
Add routing policy support to Google provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadeos-Menlo committed Jan 2, 2025
1 parent d9229d8 commit 15dea04
Show file tree
Hide file tree
Showing 7 changed files with 812 additions and 86 deletions.
54 changes: 54 additions & 0 deletions docs/tutorials/google.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Annotations

Annotations which are specific to the Google
[CloudDNS](https://cloud.google.com/dns/docs/overview) provider.

### Routing Policy

The [routing policy](https://cloud.google.com/dns/docs/routing-policies-overview)
for resource record sets managed by ExternalDNS may be specified by applying the
`external-dns.alpha.kubernetes.io/google-routing-policy` annotation on any of the
supported [sources](../sources/about.md).

#### Geolocation routing policies

Specifying a value of `geo` for the `external-dns.alpha.kubernetes.io/google-routing-policy`
annotation will enable geolocation routing for associated resource record sets. The
location attributed to resource record sets may be deduced for instances of ExternalDNS
running within the Google Cloud platform or may be specified via the `--google-location`
command-line argument. Alternatively, a location may be explicitly specified via the
`external-dns.alpha.kubernetes.io/google-location` annotation, where the value is one
of Google Cloud's [locations/regions](https://cloud.google.com/docs/geography-and-regions).

For example:
```yaml
apiVersion: externaldns.k8s.io/v1alpha1
kind: DNSEndpoint
metadata:
name: geo-example
annotations:
external-dns.alpha.kubernetes.io/google-routing-policy: "geo"
external-dns.alpha.kubernetes.io/google-location: "us-east1"
```
#### Weighted Round Robin routing policies
Specifying a value of `wrr` for the `external-dns.alpha.kubernetes.io/google-routing-policy`
annotation will enable weighted round-robin routing for associated resource record sets.
The weight to be attributed to resource record sets may be specified via the
`external-dns.alpha.kubernetes.io/google-weight` annotation, where the value is a string
representation of a floating-point number. The `external-dns.alpha.kubernetes.io/set-identifier`
annotation must also be applied providing a string value representation of an index into
the list of potential responses.

For example:
```yaml
apiVersion: externaldns.k8s.io/v1alpha1
kind: DNSEndpoint
metadata:
name: wrr-example
annotations:
external-dns.alpha.kubernetes.io/google-routing-policy: "wrr"
external-dns.alpha.kubernetes.io/google-weight: "100.0"
external-dns.alpha.kubernetes.io/set-identifier: "0"
```
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func main() {
case "cloudflare":
p, err = cloudflare.NewCloudFlareProvider(domainFilter, zoneIDFilter, cfg.CloudflareProxied, cfg.DryRun, cfg.CloudflareDNSRecordsPerPage, cfg.CloudflareRegionKey)
case "google":
p, err = google.NewGoogleProvider(ctx, cfg.GoogleProject, domainFilter, zoneIDFilter, cfg.GoogleBatchChangeSize, cfg.GoogleBatchChangeInterval, cfg.GoogleZoneVisibility, cfg.DryRun)
p, err = google.NewGoogleProvider(ctx, cfg.GoogleProject, cfg.GoogleLocation, domainFilter, zoneIDFilter, cfg.GoogleBatchChangeSize, cfg.GoogleBatchChangeInterval, cfg.GoogleZoneVisibility, cfg.DryRun)
case "digitalocean":
p, err = digitalocean.NewDigitalOceanProvider(ctx, domainFilter, cfg.DryRun, cfg.DigitalOceanAPIPageSize)
case "ovh":
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 @@ -69,6 +69,7 @@ type Config struct {
Provider string
ProviderCacheTime time.Duration
GoogleProject string
GoogleLocation string
GoogleBatchChangeSize int
GoogleBatchChangeInterval time.Duration
GoogleZoneVisibility string
Expand Down Expand Up @@ -234,6 +235,7 @@ var defaultConfig = &Config{
Provider: "",
ProviderCacheTime: 0,
GoogleProject: "",
GoogleLocation: "",
GoogleBatchChangeSize: 1000,
GoogleBatchChangeInterval: time.Second,
GoogleZoneVisibility: "",
Expand Down Expand Up @@ -463,6 +465,7 @@ func (cfg *Config) ParseFlags(args []string) error {
app.Flag("zone-name-filter", "Filter target zones by zone domain (For now, only AzureDNS provider is using this flag); specify multiple times for multiple zones (optional)").Default("").StringsVar(&cfg.ZoneNameFilter)
app.Flag("zone-id-filter", "Filter target zones by hosted zone id; specify multiple times for multiple zones (optional)").Default("").StringsVar(&cfg.ZoneIDFilter)
app.Flag("google-project", "When using the Google provider, current project is auto-detected, when running on GCP. Specify other project with this. Must be specified when running outside GCP.").Default(defaultConfig.GoogleProject).StringVar(&cfg.GoogleProject)
app.Flag("google-location", "When using the Google provider, current location is auto-detected, when running on GCP. Specify location with this. May be specified when running outside GCP.").Default(defaultConfig.GoogleLocation).StringVar(&cfg.GoogleLocation)
app.Flag("google-batch-change-size", "When using the Google provider, set the maximum number of changes that will be applied in each batch.").Default(strconv.Itoa(defaultConfig.GoogleBatchChangeSize)).IntVar(&cfg.GoogleBatchChangeSize)
app.Flag("google-batch-change-interval", "When using the Google provider, set the interval between batch changes.").Default(defaultConfig.GoogleBatchChangeInterval.String()).DurationVar(&cfg.GoogleBatchChangeInterval)
app.Flag("google-zone-visibility", "When using the Google provider, filter for zones with this visibility (optional, options: public, private)").Default(defaultConfig.GoogleZoneVisibility).EnumVar(&cfg.GoogleZoneVisibility, "", "public", "private")
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/externaldns/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
Compatibility: "",
Provider: "google",
GoogleProject: "",
GoogleLocation: "",
GoogleBatchChangeSize: 1000,
GoogleBatchChangeInterval: time.Second,
GoogleZoneVisibility: "",
Expand Down Expand Up @@ -142,6 +143,7 @@ var (
Compatibility: "mate",
Provider: "google",
GoogleProject: "project",
GoogleLocation: "location",
GoogleBatchChangeSize: 100,
GoogleBatchChangeInterval: time.Second * 2,
GoogleZoneVisibility: "private",
Expand Down Expand Up @@ -271,6 +273,7 @@ func TestParseFlags(t *testing.T) {
"--compatibility=mate",
"--provider=google",
"--google-project=project",
"--google-location=location",
"--google-batch-change-size=100",
"--google-batch-change-interval=2s",
"--google-zone-visibility=private",
Expand Down Expand Up @@ -391,6 +394,7 @@ func TestParseFlags(t *testing.T) {
"EXTERNAL_DNS_COMPATIBILITY": "mate",
"EXTERNAL_DNS_PROVIDER": "google",
"EXTERNAL_DNS_GOOGLE_PROJECT": "project",
"EXTERNAL_DNS_GOOGLE_LOCATION": "location",
"EXTERNAL_DNS_GOOGLE_BATCH_CHANGE_SIZE": "100",
"EXTERNAL_DNS_GOOGLE_BATCH_CHANGE_INTERVAL": "2s",
"EXTERNAL_DNS_GOOGLE_ZONE_VISIBILITY": "private",
Expand Down
Loading

0 comments on commit 15dea04

Please sign in to comment.