Skip to content

Commit 15dea04

Browse files
committed
Add routing policy support to Google provider.
1 parent d9229d8 commit 15dea04

File tree

7 files changed

+812
-86
lines changed

7 files changed

+812
-86
lines changed

docs/tutorials/google.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Annotations
2+
3+
Annotations which are specific to the Google
4+
[CloudDNS](https://cloud.google.com/dns/docs/overview) provider.
5+
6+
### Routing Policy
7+
8+
The [routing policy](https://cloud.google.com/dns/docs/routing-policies-overview)
9+
for resource record sets managed by ExternalDNS may be specified by applying the
10+
`external-dns.alpha.kubernetes.io/google-routing-policy` annotation on any of the
11+
supported [sources](../sources/about.md).
12+
13+
#### Geolocation routing policies
14+
15+
Specifying a value of `geo` for the `external-dns.alpha.kubernetes.io/google-routing-policy`
16+
annotation will enable geolocation routing for associated resource record sets. The
17+
location attributed to resource record sets may be deduced for instances of ExternalDNS
18+
running within the Google Cloud platform or may be specified via the `--google-location`
19+
command-line argument. Alternatively, a location may be explicitly specified via the
20+
`external-dns.alpha.kubernetes.io/google-location` annotation, where the value is one
21+
of Google Cloud's [locations/regions](https://cloud.google.com/docs/geography-and-regions).
22+
23+
For example:
24+
```yaml
25+
apiVersion: externaldns.k8s.io/v1alpha1
26+
kind: DNSEndpoint
27+
metadata:
28+
name: geo-example
29+
annotations:
30+
external-dns.alpha.kubernetes.io/google-routing-policy: "geo"
31+
external-dns.alpha.kubernetes.io/google-location: "us-east1"
32+
```
33+
34+
#### Weighted Round Robin routing policies
35+
36+
Specifying a value of `wrr` for the `external-dns.alpha.kubernetes.io/google-routing-policy`
37+
annotation will enable weighted round-robin routing for associated resource record sets.
38+
The weight to be attributed to resource record sets may be specified via the
39+
`external-dns.alpha.kubernetes.io/google-weight` annotation, where the value is a string
40+
representation of a floating-point number. The `external-dns.alpha.kubernetes.io/set-identifier`
41+
annotation must also be applied providing a string value representation of an index into
42+
the list of potential responses.
43+
44+
For example:
45+
```yaml
46+
apiVersion: externaldns.k8s.io/v1alpha1
47+
kind: DNSEndpoint
48+
metadata:
49+
name: wrr-example
50+
annotations:
51+
external-dns.alpha.kubernetes.io/google-routing-policy: "wrr"
52+
external-dns.alpha.kubernetes.io/google-weight: "100.0"
53+
external-dns.alpha.kubernetes.io/set-identifier: "0"
54+
```

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func main() {
248248
case "cloudflare":
249249
p, err = cloudflare.NewCloudFlareProvider(domainFilter, zoneIDFilter, cfg.CloudflareProxied, cfg.DryRun, cfg.CloudflareDNSRecordsPerPage, cfg.CloudflareRegionKey)
250250
case "google":
251-
p, err = google.NewGoogleProvider(ctx, cfg.GoogleProject, domainFilter, zoneIDFilter, cfg.GoogleBatchChangeSize, cfg.GoogleBatchChangeInterval, cfg.GoogleZoneVisibility, cfg.DryRun)
251+
p, err = google.NewGoogleProvider(ctx, cfg.GoogleProject, cfg.GoogleLocation, domainFilter, zoneIDFilter, cfg.GoogleBatchChangeSize, cfg.GoogleBatchChangeInterval, cfg.GoogleZoneVisibility, cfg.DryRun)
252252
case "digitalocean":
253253
p, err = digitalocean.NewDigitalOceanProvider(ctx, domainFilter, cfg.DryRun, cfg.DigitalOceanAPIPageSize)
254254
case "ovh":

pkg/apis/externaldns/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type Config struct {
6969
Provider string
7070
ProviderCacheTime time.Duration
7171
GoogleProject string
72+
GoogleLocation string
7273
GoogleBatchChangeSize int
7374
GoogleBatchChangeInterval time.Duration
7475
GoogleZoneVisibility string
@@ -234,6 +235,7 @@ var defaultConfig = &Config{
234235
Provider: "",
235236
ProviderCacheTime: 0,
236237
GoogleProject: "",
238+
GoogleLocation: "",
237239
GoogleBatchChangeSize: 1000,
238240
GoogleBatchChangeInterval: time.Second,
239241
GoogleZoneVisibility: "",
@@ -463,6 +465,7 @@ func (cfg *Config) ParseFlags(args []string) error {
463465
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)
464466
app.Flag("zone-id-filter", "Filter target zones by hosted zone id; specify multiple times for multiple zones (optional)").Default("").StringsVar(&cfg.ZoneIDFilter)
465467
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)
468+
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)
466469
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)
467470
app.Flag("google-batch-change-interval", "When using the Google provider, set the interval between batch changes.").Default(defaultConfig.GoogleBatchChangeInterval.String()).DurationVar(&cfg.GoogleBatchChangeInterval)
468471
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")

pkg/apis/externaldns/types_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
Compatibility: "",
4444
Provider: "google",
4545
GoogleProject: "",
46+
GoogleLocation: "",
4647
GoogleBatchChangeSize: 1000,
4748
GoogleBatchChangeInterval: time.Second,
4849
GoogleZoneVisibility: "",
@@ -142,6 +143,7 @@ var (
142143
Compatibility: "mate",
143144
Provider: "google",
144145
GoogleProject: "project",
146+
GoogleLocation: "location",
145147
GoogleBatchChangeSize: 100,
146148
GoogleBatchChangeInterval: time.Second * 2,
147149
GoogleZoneVisibility: "private",
@@ -271,6 +273,7 @@ func TestParseFlags(t *testing.T) {
271273
"--compatibility=mate",
272274
"--provider=google",
273275
"--google-project=project",
276+
"--google-location=location",
274277
"--google-batch-change-size=100",
275278
"--google-batch-change-interval=2s",
276279
"--google-zone-visibility=private",
@@ -391,6 +394,7 @@ func TestParseFlags(t *testing.T) {
391394
"EXTERNAL_DNS_COMPATIBILITY": "mate",
392395
"EXTERNAL_DNS_PROVIDER": "google",
393396
"EXTERNAL_DNS_GOOGLE_PROJECT": "project",
397+
"EXTERNAL_DNS_GOOGLE_LOCATION": "location",
394398
"EXTERNAL_DNS_GOOGLE_BATCH_CHANGE_SIZE": "100",
395399
"EXTERNAL_DNS_GOOGLE_BATCH_CHANGE_INTERVAL": "2s",
396400
"EXTERNAL_DNS_GOOGLE_ZONE_VISIBILITY": "private",

0 commit comments

Comments
 (0)