Skip to content

Conversation

7onn
Copy link
Contributor

@7onn 7onn commented May 16, 2025

Description
This will add a flags to be used on the Cloudflare provider for making comment available for DNS records. That's helpful when you already have a lot of records and you'd like to track what external-dns is provisioning there and why.

Comment can be set as follows

  • As a program flag --cloudflare-record-comment="Ingresses for my domain"
  • Or as Ingress annotations, taking precedence over the program args
annotations:
  external-dns.alpha.kubernetes.io/cloudflare-record-comment: "An Ingress for my-app"

Fixes #3934

This is a subset of #5359
Tags were posing issues to work without causing a config drift and endless syncs; Will address these separately on a subsequent pull request.

Checklist

  • Unit tests updated
  • End user documentation updated

@k8s-ci-robot k8s-ci-robot requested review from mloiseleur and szuecs May 16, 2025 09:13
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 16, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @7onn. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 16, 2025
@ivankatliarchuk
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 16, 2025
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest is reviewed here #5359

Comment on lines 865 to 882
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to move this logic under struct? To reduce complexity of current method?

Example

func (cfg DNSRecordsConfig) trimAndValidateComment( isPaidZone bool, comment, dnsName string) string {
	if len(comment) > freeZoneMaxCommentLength {
		if !isPaidZone {
			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)
			return comment[:freeZoneMaxCommentLength-1]
		} else if len(comment) > paidZoneMaxCommentLength {
			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)
			return comment[:paidZoneMaxCommentLength-1]
		}
	}
	return comment
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated! :) also improved the new test cases by iterating comment cases and covering all possibilities.

@ivankatliarchuk
Copy link
Contributor

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 16, 2025
@7onn 7onn force-pushed the 7onn/cloudflare-record-comments branch from 302ca0a to 3b44372 Compare May 16, 2025 10:34
@7onn 7onn requested a review from ivankatliarchuk May 16, 2025 10:35
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

I suggest to open a PR with documentation/examples update. If no plans to add docs as part of this PR

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 16, 2025
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 16, 2025
@7onn 7onn requested a review from ivankatliarchuk May 16, 2025 13:36
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Comment on lines +205 to +212
if !paidZone(dnsName) {
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)
return comment[:freeZoneMaxCommentLength]
} else if len(comment) > paidZoneMaxCommentLength {
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)
return comment[:paidZoneMaxCommentLength]
}
}
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional, as there are so many comments already. depends on readability/personal preference, but sometimes it's easier to read when there is a reduced nesting

example

if len(comment) <= freeZoneMaxCommentLength { return # early return }
if / else {}

which will be something like with early return

if len(comment) <= freeZoneMaxCommentLength {
	return comment
}

maxLength := freeZoneMaxCommentLength
if paidZone(dnsName) {
	maxLength = paidZoneMaxCommentLength
}

if len(comment) > maxLength {
	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)
	return comment[:maxLength]
}

return comment

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 16, 2025
Copy link
Collaborator

@mloiseleur mloiseleur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ivankatliarchuk, mloiseleur

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 19, 2025
@k8s-ci-robot k8s-ci-robot merged commit 14ea503 into kubernetes-sigs:master May 19, 2025
13 of 14 checks passed
@mrozentsvayg
Copy link
Contributor

mrozentsvayg commented Aug 15, 2025

there seems to be a bug preventing the cmd line flag --cloudflare-record-comment to work - it's stored in CloudflareRecordComment, but another introduced (and unset) CloudflareDNSRecordsComment is being used instead.
the flag is also not covered by tests unfortunately.

@7onn please let me know if you'll pick it up from there, or prefer the issue to be created or me to fix it

@7onn
Copy link
Contributor Author

7onn commented Aug 18, 2025

there seems to be a bug preventing the cmd line flag --cloudflare-record-comment to work - it's stored in CloudflareRecordComment, but another introduced (and unset) CloudflareDNSRecordsComment is being used instead. the flag is also not covered by tests unfortunately.

@7onn please let me know if you'll pick it up from there, or prefer the issue to be created or me to fix it

it was fixed already! just waiting for a patch!!! https://github.com/kubernetes-sigs/external-dns/pull/5582/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cloudflare: support comment field
5 participants