Skip to content

Commit 3e7c5cd

Browse files
authored
fix(cloudflare): set comments properly (#5582)
* fix(cloudflare): Set comments properly * Use cloudflare.StringPtr to enable comment removal
1 parent 73b8fb0 commit 3e7c5cd

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pkg/apis/externaldns/types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ type Config struct {
115115
CloudflareCustomHostnamesCertificateAuthority string
116116
CloudflareRegionalServices bool
117117
CloudflareRegionKey string
118-
CloudflareRecordComment string
119118
CoreDNSPrefix string
120119
AkamaiServiceConsumerDomain string
121120
AkamaiClientToken string
@@ -535,7 +534,7 @@ func App(cfg *Config) *kingpin.Application {
535534
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)
536535
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)
537536
app.Flag("cloudflare-region-key", "When using the Cloudflare provider, specify the default region for Regional Services. Any value other than an empty string will enable the Regional Services feature (optional)").StringVar(&cfg.CloudflareRegionKey)
538-
app.Flag("cloudflare-record-comment", "When using the Cloudflare provider, specify the comment for the DNS records (default: '')").Default("").StringVar(&cfg.CloudflareRecordComment)
537+
app.Flag("cloudflare-record-comment", "When using the Cloudflare provider, specify the comment for the DNS records (default: '')").Default("").StringVar(&cfg.CloudflareDNSRecordsComment)
539538

540539
app.Flag("coredns-prefix", "When using the CoreDNS provider, specify the prefix name").Default(defaultConfig.CoreDNSPrefix).StringVar(&cfg.CoreDNSPrefix)
541540
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)

provider/cloudflare/cloudflare.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,20 @@ type DNSRecordsConfig struct {
173173
}
174174

175175
func (c *DNSRecordsConfig) trimAndValidateComment(dnsName, comment string, paidZone func(string) bool) string {
176-
if len(comment) > freeZoneMaxCommentLength {
177-
if !paidZone(dnsName) {
178-
log.Warnf("DNS record comment is invalid. Trimming comment of %s. To avoid endless syncs, please set it to less than %d chars.", dnsName, freeZoneMaxCommentLength)
179-
return comment[:freeZoneMaxCommentLength]
180-
} else if len(comment) > paidZoneMaxCommentLength {
181-
log.Warnf("DNS record comment is invalid. Trimming comment of %s. To avoid endless syncs, please set it to less than %d chars.", dnsName, paidZoneMaxCommentLength)
182-
return comment[:paidZoneMaxCommentLength]
183-
}
176+
if len(comment) <= freeZoneMaxCommentLength {
177+
return comment
178+
}
179+
180+
maxLength := freeZoneMaxCommentLength
181+
if paidZone(dnsName) {
182+
maxLength = paidZoneMaxCommentLength
184183
}
184+
185+
if len(comment) > maxLength {
186+
log.Warnf("DNS record comment is invalid. Trimming comment of %s. To avoid endless syncs, please set it to less than %d chars.", dnsName, maxLength)
187+
return comment[:maxLength]
188+
}
189+
185190
return comment
186191
}
187192

@@ -243,6 +248,7 @@ func updateDNSRecordParam(cfc cloudFlareChange) cloudflare.UpdateDNSRecordParams
243248
Type: cfc.ResourceRecord.Type,
244249
Content: cfc.ResourceRecord.Content,
245250
Priority: cfc.ResourceRecord.Priority,
251+
Comment: cloudflare.StringPtr(cfc.ResourceRecord.Comment),
246252
}
247253

248254
return params
@@ -257,6 +263,7 @@ func getCreateDNSRecordParam(cfc cloudFlareChange) cloudflare.CreateDNSRecordPar
257263
Type: cfc.ResourceRecord.Type,
258264
Content: cfc.ResourceRecord.Content,
259265
Priority: cfc.ResourceRecord.Priority,
266+
Comment: cfc.ResourceRecord.Comment,
260267
}
261268

262269
return params

0 commit comments

Comments
 (0)