Skip to content

feat(cloudflare): improve cloudflare regional hostnames implementation #5309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vflaux
Copy link
Contributor

@vflaux vflaux commented Apr 17, 2025

Description
Improves my previous implementation of Cloudflare Regional Services (aka Regional Hostnames) by:

  • adding a flag to enable Regional Services feature (disabled by default, enabled if region key is set)
  • supporting deletion of regional hostnames on annotation edit: removing the annotation if the default key is empty or setting it to empty string will remove the regional hostname config
  • correctly supporting differences detection with cloudflare state: periodic reconcile / restart will detect external modifications on regional hostname config
  • increasing tests coverage

This implementation use a call to list regional hostnames on the zone and use them to plan changes on cloudflare.

Checklist

  • Unit tests updated
  • End user documentation updated

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 17, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 17, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @vflaux. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 17, 2025
@vflaux vflaux force-pushed the cf_improve_regional_hostname branch 4 times, most recently from 95d3d67 to fd10d2b Compare April 17, 2025 13:09
@vflaux vflaux marked this pull request as ready for review April 17, 2025 14:16
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 17, 2025
@ivankatliarchuk
Copy link
Contributor

probably worth to create cloudflare_regional file and move logic there.

Would you be able to share manifests files and all arguments you are using and how you do integration testing?

@vflaux vflaux force-pushed the cf_improve_regional_hostname branch 4 times, most recently from 8fb6d98 to f5eb952 Compare April 22, 2025 11:25
@vflaux
Copy link
Contributor Author

vflaux commented Apr 24, 2025

@ivankatliarchuk I moved the logic & tests to their dedicated file as you suggested.

I use the following flags to test :

--events
--source=service
--source=ingress
--policy=sync
--registry=txt
--txt-owner-id=foobar
--txt-prefix=%{record_type}-
--provider=cloudflare
--cloudflare-proxied
--cloudflare-regional-hostnames
--cloudflare-region-key=xx
--ingress-class=cloudflare

I run external-dns with --cloudflare-region-key flag defined and change an ingress external-dns.alpha.kubernetes.io/cloudflare-region-key annotation.
I check the result with the /zones/:zone_id/addressing/regional_hostnames endpoint on clouflare api.

Tests :

Default regional key Ingress regional key Expected regional hostname key Result
undefined undefined none ok
undefined "" none ok
undefined "eu" "eu" ok
"us" undefined "us" ok
"us" "" none ok
"us" "eu" "eu" ok

@ivankatliarchuk
Copy link
Contributor

A lot of stuff, but not sure if there is a way to split pull request.

Do you think you could move to separate PRs

  • correctly supporting differences detection with cloudflare state: periodic reconcile / restart will detect external modifications on regional hostname config
  • increasing tests coverage

This may take time to get an approval as is

@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 Apr 24, 2025
@vflaux vflaux force-pushed the cf_improve_regional_hostname branch from f5eb952 to 1aac3ec Compare April 25, 2025 09:39
@vflaux
Copy link
Contributor Author

vflaux commented Apr 25, 2025

I opened a new PR with some changes from this one: #5329
I'm not sure if I can split this any further. The improvements in test coverage are related to the new code in this PR.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2025
@vflaux vflaux force-pushed the cf_improve_regional_hostname branch from 1aac3ec to ebb83d4 Compare April 29, 2025 19:44
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 29, 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.

let's fix linter so then we could review the rest

Could you also share manifest and end-2-end smoke tests results

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.

Would you be able to share the Kubernetes manifests and the results from your smoke tests?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 5, 2025
@vflaux vflaux force-pushed the cf_improve_regional_hostname branch from 41a2798 to d24dc42 Compare June 6, 2025 12:03
@k8s-ci-robot k8s-ci-robot added docs provider Issues or PRs related to a provider and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 6, 2025
@mloiseleur
Copy link
Collaborator

@vflaux Have you tested this PR on a real environment ?

We will make a new release next week. If you can fix the ci issue on linter, maybe it can be a part of this release.

@ivankatliarchuk Anything left on your side ?

@vflaux vflaux force-pushed the cf_improve_regional_hostname branch from d24dc42 to 628f1f8 Compare June 20, 2025 17:14
@vflaux
Copy link
Contributor Author

vflaux commented Jun 20, 2025

@ivankatliarchuk i've added new tests to cover failures cases.

@mloiseleur I've run a previous version of this PR on testing & production environments but I now use the official build again.
This was to cleanup all the regional hostnames created by external-dns as the current implementation can't do that. That's the main reason for this PR actually.
I still need to do tests on a real environment with my latest changes. I'll try to do this this weekend.

- 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
@vflaux vflaux force-pushed the cf_improve_regional_hostname branch from 628f1f8 to bbe5d42 Compare June 20, 2025 18:11
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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 20, 2025
@ivankatliarchuk
Copy link
Contributor

Just a quick note for the future — I know we created a slice for this PR already, but next time this approach could be hardly acceptable. There are too many changes packed into one: slight refactoring, new features, and behavior improvements all in a single PR. This increases the risk significantly. A lot can go wrong in a scenario like this. From PC looks manageable, from phone - not really 😳

The bright side is the test coverage bump. Will see where or not we could trust or unit test framework ;-)

Worth to update the PR description if it's not up to date.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 21, 2025
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 22, 2025
@mloiseleur
Copy link
Collaborator

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 Jun 22, 2025
@k8s-ci-robot k8s-ci-robot merged commit 7108979 into kubernetes-sigs:master Jun 22, 2025
14 checks passed
schwajo pushed a commit to schwajo/external-dns that referenced this pull request Jun 24, 2025
…5309)

- 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

Co-authored-by: Michel Loiseleur <[email protected]>
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. docs 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. provider Issues or PRs related to a provider size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants