Skip to content

Commit b53e5f8

Browse files
committed
feat(cloudflare): Enable DNS record Comment and Tags
1 parent 2481c07 commit b53e5f8

File tree

5 files changed

+166
-128
lines changed

5 files changed

+166
-128
lines changed

controller/execute.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/http"
2323
"os"
2424
"os/signal"
25+
"strings"
2526
"syscall"
2627
"time"
2728

@@ -205,7 +206,10 @@ func Execute() {
205206
Enabled: cfg.CloudflareCustomHostnames,
206207
MinTLSVersion: cfg.CloudflareCustomHostnamesMinTLSVersion,
207208
CertificateAuthority: cfg.CloudflareCustomHostnamesCertificateAuthority,
208-
})
209+
},
210+
cfg.CloudflareRecordComment,
211+
strings.Split(cfg.CloudflareRecordTags, ","),
212+
)
209213
case "google":
210214
p, err = google.NewGoogleProvider(ctx, cfg.GoogleProject, domainFilter, zoneIDFilter, cfg.GoogleBatchChangeSize, cfg.GoogleBatchChangeInterval, cfg.GoogleZoneVisibility, cfg.DryRun)
211215
case "digitalocean":

docs/flags.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
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) |
9696
| `--cloudflare-region-key=CLOUDFLARE-REGION-KEY` | When using the Cloudflare provider, specify the region (default: earth) |
97+
| `--cloudflare-record-comment=""` | When using the Cloudflare provider, specify the comment for the DNS records (default: '') |
98+
| `--cloudflare-record-tags=""` | When using the Cloudflare provider, specify the tags for the DNS records as a comma-separated string (default: '') |
9799
| `--coredns-prefix="/skydns/"` | When using the CoreDNS provider, specify the prefix name |
98100
| `--akamai-serviceconsumerdomain=""` | When using the Akamai provider, specify the base URL (required when --provider=akamai and edgerc-path not specified) |
99101
| `--akamai-client-token=""` | When using the Akamai provider, specify the client token (required when --provider=akamai and edgerc-path not specified) |

pkg/apis/externaldns/types.go

Lines changed: 130 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ type Config struct {
112112
CloudflareCustomHostnamesCertificateAuthority string
113113
CloudflareDNSRecordsPerPage int
114114
CloudflareRegionKey string
115+
CloudflareRecordComment string
116+
CloudflareRecordTags string
115117
CoreDNSPrefix string
116118
AkamaiServiceConsumerDomain string
117119
AkamaiClientToken string
@@ -256,129 +258,130 @@ var defaultConfig = &Config{
256258
CloudflareDNSRecordsPerPage: 100,
257259
CloudflareProxied: false,
258260
CloudflareRegionKey: "earth",
259-
260-
CombineFQDNAndAnnotation: false,
261-
Compatibility: "",
262-
ConnectorSourceServer: "localhost:8080",
263-
CoreDNSPrefix: "/skydns/",
264-
CRDSourceAPIVersion: "externaldns.k8s.io/v1alpha1",
265-
CRDSourceKind: "DNSEndpoint",
266-
DefaultTargets: []string{},
267-
DigitalOceanAPIPageSize: 50,
268-
DomainFilter: []string{},
269-
DryRun: false,
270-
ExcludeDNSRecordTypes: []string{},
271-
ExcludeDomains: []string{},
272-
ExcludeTargetNets: []string{},
273-
ExcludeUnschedulable: true,
274-
ExoscaleAPIEnvironment: "api",
275-
ExoscaleAPIKey: "",
276-
ExoscaleAPISecret: "",
277-
ExoscaleAPIZone: "ch-gva-2",
278-
ExposeInternalIPV6: true,
279-
FQDNTemplate: "",
280-
GatewayLabelFilter: "",
281-
GatewayName: "",
282-
GatewayNamespace: "",
283-
GlooNamespaces: []string{"gloo-system"},
284-
GoDaddyAPIKey: "",
285-
GoDaddyOTE: false,
286-
GoDaddySecretKey: "",
287-
GoDaddyTTL: 600,
288-
GoogleBatchChangeInterval: time.Second,
289-
GoogleBatchChangeSize: 1000,
290-
GoogleProject: "",
291-
GoogleZoneVisibility: "",
292-
IBMCloudConfigFile: "/etc/kubernetes/ibmcloud.json",
293-
IBMCloudProxied: false,
294-
IgnoreHostnameAnnotation: false,
295-
IgnoreIngressRulesSpec: false,
296-
IgnoreIngressTLSSpec: false,
297-
IngressClassNames: nil,
298-
InMemoryZones: []string{},
299-
Interval: time.Minute,
300-
KubeConfig: "",
301-
LabelFilter: labels.Everything().String(),
302-
LogFormat: "text",
303-
LogLevel: logrus.InfoLevel.String(),
304-
ManagedDNSRecordTypes: []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME},
305-
MetricsAddress: ":7979",
306-
MinEventSyncInterval: 5 * time.Second,
307-
Namespace: "",
308-
NAT64Networks: []string{},
309-
NS1Endpoint: "",
310-
NS1IgnoreSSL: false,
311-
OCIConfigFile: "/etc/kubernetes/oci.yaml",
312-
OCIZoneCacheDuration: 0 * time.Second,
313-
OCIZoneScope: "GLOBAL",
314-
Once: false,
315-
OVHApiRateLimit: 20,
316-
OVHEnableCNAMERelative: false,
317-
OVHEndpoint: "ovh-eu",
318-
PDNSAPIKey: "",
319-
PDNSServer: "http://localhost:8081",
320-
PDNSServerID: "localhost",
321-
PDNSSkipTLSVerify: false,
322-
PiholeApiVersion: "5",
323-
PiholePassword: "",
324-
PiholeServer: "",
325-
PiholeTLSInsecureSkipVerify: false,
326-
PluralCluster: "",
327-
PluralProvider: "",
328-
PodSourceDomain: "",
329-
Policy: "sync",
330-
Provider: "",
331-
ProviderCacheTime: 0,
332-
PublishHostIP: false,
333-
PublishInternal: false,
334-
RegexDomainExclusion: regexp.MustCompile(""),
335-
RegexDomainFilter: regexp.MustCompile(""),
336-
Registry: "txt",
337-
RequestTimeout: time.Second * 30,
338-
RFC2136BatchChangeSize: 50,
339-
RFC2136GSSTSIG: false,
340-
RFC2136Host: []string{""},
341-
RFC2136Insecure: false,
342-
RFC2136KerberosPassword: "",
343-
RFC2136KerberosRealm: "",
344-
RFC2136KerberosUsername: "",
345-
RFC2136LoadBalancingStrategy: "disabled",
346-
RFC2136MinTTL: 0,
347-
RFC2136Port: 0,
348-
RFC2136SkipTLSVerify: false,
349-
RFC2136TAXFR: true,
350-
RFC2136TSIGKeyName: "",
351-
RFC2136TSIGSecret: "",
352-
RFC2136TSIGSecretAlg: "",
353-
RFC2136UseTLS: false,
354-
RFC2136Zone: []string{},
355-
ServiceTypeFilter: []string{},
356-
SkipperRouteGroupVersion: "zalando.org/v1",
357-
Sources: nil,
358-
TargetNetFilter: []string{},
359-
TencentCloudConfigFile: "/etc/kubernetes/tencent-cloud.json",
360-
TencentCloudZoneType: "",
361-
TLSCA: "",
362-
TLSClientCert: "",
363-
TLSClientCertKey: "",
364-
TraefikDisableLegacy: false,
365-
TraefikDisableNew: false,
366-
TransIPAccountName: "",
367-
TransIPPrivateKeyFile: "",
368-
TXTCacheInterval: 0,
369-
TXTEncryptAESKey: "",
370-
TXTEncryptEnabled: false,
371-
TXTNewFormatOnly: false,
372-
TXTOwnerID: "default",
373-
TXTPrefix: "",
374-
TXTSuffix: "",
375-
TXTWildcardReplacement: "",
376-
UpdateEvents: false,
377-
WebhookProviderReadTimeout: 5 * time.Second,
378-
WebhookProviderURL: "http://localhost:8888",
379-
WebhookProviderWriteTimeout: 10 * time.Second,
380-
WebhookServer: false,
381-
ZoneIDFilter: []string{},
261+
CloudflareRecordComment: "",
262+
CloudflareRecordTags: "",
263+
CombineFQDNAndAnnotation: false,
264+
Compatibility: "",
265+
ConnectorSourceServer: "localhost:8080",
266+
CoreDNSPrefix: "/skydns/",
267+
CRDSourceAPIVersion: "externaldns.k8s.io/v1alpha1",
268+
CRDSourceKind: "DNSEndpoint",
269+
DefaultTargets: []string{},
270+
DigitalOceanAPIPageSize: 50,
271+
DomainFilter: []string{},
272+
DryRun: false,
273+
ExcludeDNSRecordTypes: []string{},
274+
ExcludeDomains: []string{},
275+
ExcludeTargetNets: []string{},
276+
ExcludeUnschedulable: true,
277+
ExoscaleAPIEnvironment: "api",
278+
ExoscaleAPIKey: "",
279+
ExoscaleAPISecret: "",
280+
ExoscaleAPIZone: "ch-gva-2",
281+
ExposeInternalIPV6: true,
282+
FQDNTemplate: "",
283+
GatewayLabelFilter: "",
284+
GatewayName: "",
285+
GatewayNamespace: "",
286+
GlooNamespaces: []string{"gloo-system"},
287+
GoDaddyAPIKey: "",
288+
GoDaddyOTE: false,
289+
GoDaddySecretKey: "",
290+
GoDaddyTTL: 600,
291+
GoogleBatchChangeInterval: time.Second,
292+
GoogleBatchChangeSize: 1000,
293+
GoogleProject: "",
294+
GoogleZoneVisibility: "",
295+
IBMCloudConfigFile: "/etc/kubernetes/ibmcloud.json",
296+
IBMCloudProxied: false,
297+
IgnoreHostnameAnnotation: false,
298+
IgnoreIngressRulesSpec: false,
299+
IgnoreIngressTLSSpec: false,
300+
IngressClassNames: nil,
301+
InMemoryZones: []string{},
302+
Interval: time.Minute,
303+
KubeConfig: "",
304+
LabelFilter: labels.Everything().String(),
305+
LogFormat: "text",
306+
LogLevel: logrus.InfoLevel.String(),
307+
ManagedDNSRecordTypes: []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME},
308+
MetricsAddress: ":7979",
309+
MinEventSyncInterval: 5 * time.Second,
310+
Namespace: "",
311+
NAT64Networks: []string{},
312+
NS1Endpoint: "",
313+
NS1IgnoreSSL: false,
314+
OCIConfigFile: "/etc/kubernetes/oci.yaml",
315+
OCIZoneCacheDuration: 0 * time.Second,
316+
OCIZoneScope: "GLOBAL",
317+
Once: false,
318+
OVHApiRateLimit: 20,
319+
OVHEnableCNAMERelative: false,
320+
OVHEndpoint: "ovh-eu",
321+
PDNSAPIKey: "",
322+
PDNSServer: "http://localhost:8081",
323+
PDNSServerID: "localhost",
324+
PDNSSkipTLSVerify: false,
325+
PiholeApiVersion: "5",
326+
PiholePassword: "",
327+
PiholeServer: "",
328+
PiholeTLSInsecureSkipVerify: false,
329+
PluralCluster: "",
330+
PluralProvider: "",
331+
PodSourceDomain: "",
332+
Policy: "sync",
333+
Provider: "",
334+
ProviderCacheTime: 0,
335+
PublishHostIP: false,
336+
PublishInternal: false,
337+
RegexDomainExclusion: regexp.MustCompile(""),
338+
RegexDomainFilter: regexp.MustCompile(""),
339+
Registry: "txt",
340+
RequestTimeout: time.Second * 30,
341+
RFC2136BatchChangeSize: 50,
342+
RFC2136GSSTSIG: false,
343+
RFC2136Host: []string{""},
344+
RFC2136Insecure: false,
345+
RFC2136KerberosPassword: "",
346+
RFC2136KerberosRealm: "",
347+
RFC2136KerberosUsername: "",
348+
RFC2136LoadBalancingStrategy: "disabled",
349+
RFC2136MinTTL: 0,
350+
RFC2136Port: 0,
351+
RFC2136SkipTLSVerify: false,
352+
RFC2136TAXFR: true,
353+
RFC2136TSIGKeyName: "",
354+
RFC2136TSIGSecret: "",
355+
RFC2136TSIGSecretAlg: "",
356+
RFC2136UseTLS: false,
357+
RFC2136Zone: []string{},
358+
ServiceTypeFilter: []string{},
359+
SkipperRouteGroupVersion: "zalando.org/v1",
360+
Sources: nil,
361+
TargetNetFilter: []string{},
362+
TencentCloudConfigFile: "/etc/kubernetes/tencent-cloud.json",
363+
TencentCloudZoneType: "",
364+
TLSCA: "",
365+
TLSClientCert: "",
366+
TLSClientCertKey: "",
367+
TraefikDisableLegacy: false,
368+
TraefikDisableNew: false,
369+
TransIPAccountName: "",
370+
TransIPPrivateKeyFile: "",
371+
TXTCacheInterval: 0,
372+
TXTEncryptAESKey: "",
373+
TXTEncryptEnabled: false,
374+
TXTNewFormatOnly: false,
375+
TXTOwnerID: "default",
376+
TXTPrefix: "",
377+
TXTSuffix: "",
378+
TXTWildcardReplacement: "",
379+
UpdateEvents: false,
380+
WebhookProviderReadTimeout: 5 * time.Second,
381+
WebhookProviderURL: "http://localhost:8888",
382+
WebhookProviderWriteTimeout: 10 * time.Second,
383+
WebhookServer: false,
384+
ZoneIDFilter: []string{},
382385
}
383386

384387
// NewConfig returns new Config object
@@ -530,12 +533,16 @@ func App(cfg *Config) *kingpin.Application {
530533
app.Flag("tencent-cloud-config-file", "When using the Tencent Cloud provider, specify the Tencent Cloud configuration file (required when --provider=tencentcloud)").Default(defaultConfig.TencentCloudConfigFile).StringVar(&cfg.TencentCloudConfigFile)
531534
app.Flag("tencent-cloud-zone-type", "When using the Tencent Cloud provider, filter for zones with visibility (optional, options: public, private)").Default(defaultConfig.TencentCloudZoneType).EnumVar(&cfg.TencentCloudZoneType, "", "public", "private")
532535

536+
// Flags related to Cloudflare
533537
app.Flag("cloudflare-proxied", "When using the Cloudflare provider, specify if the proxy mode must be enabled (default: disabled)").BoolVar(&cfg.CloudflareProxied)
534538
app.Flag("cloudflare-custom-hostnames", "When using the Cloudflare provider, specify if the Custom Hostnames feature will be used. Requires \"Cloudflare for SaaS\" enabled. (default: disabled)").BoolVar(&cfg.CloudflareCustomHostnames)
535539
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")
536540
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")
537541
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)
538542
app.Flag("cloudflare-region-key", "When using the Cloudflare provider, specify the region (default: earth)").StringVar(&cfg.CloudflareRegionKey)
543+
app.Flag("cloudflare-record-comment", "When using the Cloudflare provider, specify the comment for the DNS records (default: '')").Default("").StringVar(&cfg.CloudflareRecordComment)
544+
app.Flag("cloudflare-record-tags", "When using the Cloudflare provider, specify the tags for the DNS records as a comma-separated string (default: '')").Default("").StringVar(&cfg.CloudflareRecordTags)
545+
539546
app.Flag("coredns-prefix", "When using the CoreDNS provider, specify the prefix name").Default(defaultConfig.CoreDNSPrefix).StringVar(&cfg.CoreDNSPrefix)
540547
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)
541548
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)

provider/cloudflare/cloudflare.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ type CloudFlareProvider struct {
202202
DryRun bool
203203
DNSRecordsPerPage int
204204
RegionKey string
205+
RecordComment string
206+
RecordTags []string
205207
}
206208

207209
// cloudFlareChange differentiates between ChangActions
@@ -226,6 +228,8 @@ func updateDNSRecordParam(cfc cloudFlareChange) cloudflare.UpdateDNSRecordParams
226228
Proxied: cfc.ResourceRecord.Proxied,
227229
Type: cfc.ResourceRecord.Type,
228230
Content: cfc.ResourceRecord.Content,
231+
Comment: &cfc.ResourceRecord.Comment,
232+
Tags: cfc.ResourceRecord.Tags,
229233
}
230234
}
231235

@@ -253,11 +257,13 @@ func getCreateDNSRecordParam(cfc cloudFlareChange) cloudflare.CreateDNSRecordPar
253257
Proxied: cfc.ResourceRecord.Proxied,
254258
Type: cfc.ResourceRecord.Type,
255259
Content: cfc.ResourceRecord.Content,
260+
Comment: cfc.ResourceRecord.Comment,
261+
Tags: cfc.ResourceRecord.Tags,
256262
}
257263
}
258264

259265
// NewCloudFlareProvider initializes a new CloudFlare DNS based Provider.
260-
func NewCloudFlareProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, proxiedByDefault bool, dryRun bool, dnsRecordsPerPage int, regionKey string, customHostnamesConfig CustomHostnamesConfig) (*CloudFlareProvider, error) {
266+
func NewCloudFlareProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, proxiedByDefault bool, dryRun bool, dnsRecordsPerPage int, regionKey string, customHostnamesConfig CustomHostnamesConfig, recordComment string, recordTags []string) (*CloudFlareProvider, error) {
261267
// initialize via chosen auth method and returns new API object
262268
var (
263269
config *cloudflare.API
@@ -289,6 +295,8 @@ func NewCloudFlareProvider(domainFilter endpoint.DomainFilter, zoneIDFilter prov
289295
DryRun: dryRun,
290296
DNSRecordsPerPage: dnsRecordsPerPage,
291297
RegionKey: regionKey,
298+
RecordComment: recordComment,
299+
RecordTags: recordTags,
292300
}, nil
293301
}
294302

@@ -835,6 +843,8 @@ func (p *CloudFlareProvider) newCloudFlareChange(action string, ep *endpoint.End
835843
Proxied: &proxied,
836844
Type: ep.RecordType,
837845
Content: target,
846+
Comment: p.RecordComment,
847+
Tags: p.RecordTags,
838848
},
839849
RegionalHostname: regionalHostname,
840850
CustomHostnamesPrev: prevCustomHostnames,

0 commit comments

Comments
 (0)