Skip to content

Commit ebb83d4

Browse files
committed
improve cloudflare regional hostname implementation
- add flag to enable regional hostname feature - support deletion of regional hostname on annotation edit - correctly support differences detection with cloudflare state - increased tests coverage
1 parent ba64e8b commit ebb83d4

File tree

9 files changed

+1119
-703
lines changed

9 files changed

+1119
-703
lines changed

controller/execute.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ func Execute() {
200200
cfg.CloudflareProxied,
201201
cfg.DryRun,
202202
cfg.CloudflareDNSRecordsPerPage,
203-
cfg.CloudflareRegionKey,
203+
cloudflare.RegionalServicesConfig{
204+
Enabled: cfg.CloudflareRegionalServices || cfg.CloudflareRegionKey != "",
205+
RegionKey: cfg.CloudflareRegionKey,
206+
},
204207
cloudflare.CustomHostnamesConfig{
205208
Enabled: cfg.CloudflareCustomHostnames,
206209
MinTLSVersion: cfg.CloudflareCustomHostnamesMinTLSVersion,

docs/flags.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
| `--cloudflare-custom-hostnames-min-tls-version=1.0` | When using the Cloudflare provider with the Custom Hostnames, specify which Minimum TLS Version will be used by default. (default: 1.0, options: 1.0, 1.1, 1.2, 1.3) |
9494
| `--cloudflare-custom-hostnames-certificate-authority=google` | When using the Cloudflare provider with the Custom Hostnames, specify which Cerrtificate Authority will be used by default. (default: google, options: google, ssl_com, lets_encrypt) |
9595
| `--cloudflare-dns-records-per-page=100` | When using the Cloudflare provider, specify how many DNS records listed per page, max possible 5,000 (default: 100) |
96-
| `--cloudflare-region-key=CLOUDFLARE-REGION-KEY` | When using the Cloudflare provider, specify the region (default: earth) |
96+
| `--[no-]cloudflare-regional-services` | When using the Cloudflare provider, specify if Regional Services feature will be used (default: disabled) |
97+
| `--cloudflare-region-key=CLOUDFLARE-REGION-KEY` | When using the Cloudflare provider, specify the default region for Regional Services (optional) |
9798
| `--coredns-prefix="/skydns/"` | When using the CoreDNS provider, specify the prefix name |
9899
| `--akamai-serviceconsumerdomain=""` | When using the Akamai provider, specify the base URL (required when --provider=akamai and edgerc-path not specified) |
99100
| `--akamai-client-token=""` | When using the Akamai provider, specify the client token (required when --provider=akamai and edgerc-path not specified) |

docs/tutorials/cloudflare.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ spec:
128128
- --provider=cloudflare
129129
- --cloudflare-proxied # (optional) enable the proxy feature of Cloudflare (DDOS protection, CDN...)
130130
- --cloudflare-dns-records-per-page=5000 # (optional) configure how many DNS records to fetch per request
131+
- --cloudflare-regional-services # (optional) enable the regional hostname feature that configure which region can decrypt HTTPS requests
131132
- --cloudflare-region-key="eu" # (optional) configure which region can decrypt HTTPS requests
132133
env:
133134
- name: CF_API_KEY
@@ -204,6 +205,7 @@ spec:
204205
- --provider=cloudflare
205206
- --cloudflare-proxied # (optional) enable the proxy feature of Cloudflare (DDOS protection, CDN...)
206207
- --cloudflare-dns-records-per-page=5000 # (optional) configure how many DNS records to fetch per request
208+
- --cloudflare-regional-services # (optional) enable the regional hostname feature that configure which region can decrypt HTTPS requests
207209
- --cloudflare-region-key="eu" # (optional) configure which region can decrypt HTTPS requests
208210
env:
209211
- name: CF_API_KEY
@@ -303,10 +305,17 @@ Using the `external-dns.alpha.kubernetes.io/cloudflare-proxied: "true"` annotati
303305

304306
## Setting cloudflare-region-key to configure regional services
305307

306-
Using the `external-dns.alpha.kubernetes.io/cloudflare-region-key` annotation on your ingress, you can restrict which data centers can decrypt and serve HTTPS traffic. A list of available options can be seen [here](https://developers.cloudflare.com/data-localization/regional-services/get-started/).
307-
Currently, requires SuperAdmin or Admin role.
308+
Automatic configuration of Cloudflare Regional Services is enabled by the --cloudflare-regional-services flag.
309+
Regional Services restrict which data centers can decrypt and serve HTTPS traffic.
310+
A default region can be defined using the --cloudflare-region-key flag.
311+
312+
A list of available regions can be seen [here](https://developers.cloudflare.com/data-localization/regional-services/get-started/).
313+
314+
Using the `external-dns.alpha.kubernetes.io/cloudflare-region-key` annotation on your ingress, you can specify the region for that record.
308315

309-
If not set the value will default to `global`.
316+
An empty string will result in no regional hostname configured.
317+
318+
Currently, requires SuperAdmin or Admin role.
310319

311320
## Setting cloudflare-custom-hostname
312321

pkg/apis/externaldns/types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type Config struct {
111111
CloudflareCustomHostnamesMinTLSVersion string
112112
CloudflareCustomHostnamesCertificateAuthority string
113113
CloudflareDNSRecordsPerPage int
114+
CloudflareRegionalServices bool
114115
CloudflareRegionKey string
115116
CoreDNSPrefix string
116117
AkamaiServiceConsumerDomain string
@@ -255,6 +256,7 @@ var defaultConfig = &Config{
255256
CloudflareCustomHostnamesMinTLSVersion: "1.0",
256257
CloudflareDNSRecordsPerPage: 100,
257258
CloudflareProxied: false,
259+
CloudflareRegionalServices: false,
258260
CloudflareRegionKey: "earth",
259261

260262
CombineFQDNAndAnnotation: false,
@@ -535,7 +537,8 @@ func App(cfg *Config) *kingpin.Application {
535537
app.Flag("cloudflare-custom-hostnames-min-tls-version", "When using the Cloudflare provider with the Custom Hostnames, specify which Minimum TLS Version will be used by default. (default: 1.0, options: 1.0, 1.1, 1.2, 1.3)").Default("1.0").EnumVar(&cfg.CloudflareCustomHostnamesMinTLSVersion, "1.0", "1.1", "1.2", "1.3")
536538
app.Flag("cloudflare-custom-hostnames-certificate-authority", "When using the Cloudflare provider with the Custom Hostnames, specify which Cerrtificate Authority will be used by default. (default: google, options: google, ssl_com, lets_encrypt)").Default("google").EnumVar(&cfg.CloudflareCustomHostnamesCertificateAuthority, "google", "ssl_com", "lets_encrypt")
537539
app.Flag("cloudflare-dns-records-per-page", "When using the Cloudflare provider, specify how many DNS records listed per page, max possible 5,000 (default: 100)").Default(strconv.Itoa(defaultConfig.CloudflareDNSRecordsPerPage)).IntVar(&cfg.CloudflareDNSRecordsPerPage)
538-
app.Flag("cloudflare-region-key", "When using the Cloudflare provider, specify the region (default: earth)").StringVar(&cfg.CloudflareRegionKey)
540+
app.Flag("cloudflare-regional-services", "When using the Cloudflare provider, specify if Regional Services feature will be used (default: disabled)").Default(strconv.FormatBool(defaultConfig.CloudflareRegionalServices)).BoolVar(&cfg.CloudflareRegionalServices)
541+
app.Flag("cloudflare-region-key", "When using the Cloudflare provider, specify the default region for Regional Services (optional)").StringVar(&cfg.CloudflareRegionKey)
539542
app.Flag("coredns-prefix", "When using the CoreDNS provider, specify the prefix name").Default(defaultConfig.CoreDNSPrefix).StringVar(&cfg.CoreDNSPrefix)
540543
app.Flag("akamai-serviceconsumerdomain", "When using the Akamai provider, specify the base URL (required when --provider=akamai and edgerc-path not specified)").Default(defaultConfig.AkamaiServiceConsumerDomain).StringVar(&cfg.AkamaiServiceConsumerDomain)
541544
app.Flag("akamai-client-token", "When using the Akamai provider, specify the client token (required when --provider=akamai and edgerc-path not specified)").Default(defaultConfig.AkamaiClientToken).StringVar(&cfg.AkamaiClientToken)

pkg/apis/externaldns/types_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ var (
188188
CloudflareCustomHostnamesMinTLSVersion: "1.3",
189189
CloudflareCustomHostnamesCertificateAuthority: "google",
190190
CloudflareDNSRecordsPerPage: 5000,
191+
CloudflareRegionalServices: true,
191192
CloudflareRegionKey: "us",
192193
CoreDNSPrefix: "/coredns/",
193194
AkamaiServiceConsumerDomain: "oooo-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net",
@@ -301,6 +302,7 @@ func TestParseFlags(t *testing.T) {
301302
"--cloudflare-custom-hostnames-min-tls-version=1.3",
302303
"--cloudflare-custom-hostnames-certificate-authority=google",
303304
"--cloudflare-dns-records-per-page=5000",
305+
"--cloudflare-regional-services",
304306
"--cloudflare-region-key=us",
305307
"--coredns-prefix=/coredns/",
306308
"--akamai-serviceconsumerdomain=oooo-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net",
@@ -432,6 +434,7 @@ func TestParseFlags(t *testing.T) {
432434
"EXTERNAL_DNS_CLOUDFLARE_CUSTOM_HOSTNAMES_MIN_TLS_VERSION": "1.3",
433435
"EXTERNAL_DNS_CLOUDFLARE_CUSTOM_HOSTNAMES_CERTIFICATE_AUTHORITY": "google",
434436
"EXTERNAL_DNS_CLOUDFLARE_DNS_RECORDS_PER_PAGE": "5000",
437+
"EXTERNAL_DNS_CLOUDFLARE_REGIONAL_SERVICES": "1",
435438
"EXTERNAL_DNS_CLOUDFLARE_REGION_KEY": "us",
436439
"EXTERNAL_DNS_COREDNS_PREFIX": "/coredns/",
437440
"EXTERNAL_DNS_AKAMAI_SERVICECONSUMERDOMAIN": "oooo-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net",

0 commit comments

Comments
 (0)