Skip to content
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

feat: added support per dns cf proxy #4325

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Tazer
Copy link

@Tazer Tazer commented Mar 20, 2024

Description

We have a use case where we want to have 1 domain proxied through cloudflare and another one not proxied via cloudflare but using the same service

So in this PR we are adding the possibility to pass a domain list in the external-dns.alpha.kubernetes.io/cloudflare-proxied

So it's still possible to pass
external-dns.alpha.kubernetes.io/cloudflare-proxied: true/false

but also
external-dns.alpha.kubernetes.io/cloudflare-proxied: example.com,bar.com

The setup we are going todo is like this:

external-dns.alpha.kubernetes.io/hostname: example.com,api.example.com
external-dns.alpha.kubernetes.io/cloudflare-proxied: example.com

Checklist

  • Unit tests updated
  • End user documentation updated

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 20, 2024
Copy link

linux-foundation-easycla bot commented Mar 20, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign johngmyers for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Mar 20, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @Tazer!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/external-dns has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@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 Mar 20, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @Tazer. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 20, 2024
@Tazer Tazer marked this pull request as ready for review March 20, 2024 10:38
@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 Mar 20, 2024
@mloiseleur
Copy link
Contributor

Thanks for this PR. The test looks good.
Would you please add:

  1. some documentation on this
  2. an other test with multiple cloudflare-proxied domains

I'm unsure to understand why you needed to make a deepcopy in endpoint.go, since this PR is not modifying any property.

Would you please detail what is the behavior you observed without the deepcopy ?

@mloiseleur
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 Mar 21, 2024
@Tazer
Copy link
Author

Tazer commented Mar 21, 2024

Thanks for this PR. The test looks good. Would you please add:

  1. some documentation on this
  2. an other test with multiple cloudflare-proxied domains

I'm unsure to understand why you needed to make a deepcopy in endpoint.go, since this PR is not modifying any property.

Would you please detail what is the behavior you observed without the deepcopy ?

First of all thanks for checking it out. @mloiseleur

will look at documentation and additional test tomorrow.

Let me explain the deepcopy need.

As we are using this functionality:

external-dns.alpha.kubernetes.io/hostname: example.com,api.example.com

on a kubernetes service.

The following code will run:

		providerSpecific, setIdentifier := getProviderSpecificAnnotations(svc.Annotations)
		var hostnameList []string
		var internalHostnameList []string

		hostnameList = getHostnamesFromAnnotations(svc.Annotations)
		for _, hostname := range hostnameList {
			endpoints = append(endpoints, sc.generateEndpoints(svc, hostname, providerSpecific, setIdentifier, false)...)
		}

so the tricky part here is that providerSpecific is a slice (underlying a pointer) and that is past to both endpoints in the list after the split by getHostnamesFromAnnotations(svc.Annotations)

source: https://github.com/kubernetes-sigs/external-dns/blob/master/source/service.go#L395

And in the cloudflare provider we have this code:

func (p *CloudFlareProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
	adjustedEndpoints := []*endpoint.Endpoint{}
	for _, e := range endpoints {
		proxied := shouldBeProxied(e, p.proxiedByDefault)
		if proxied {
			e.RecordTTL = 0
		}
		e.SetProviderSpecificProperty(source.CloudflareProxiedKey, strconv.FormatBool(proxied))

		adjustedEndpoints = append(adjustedEndpoints, e)
	}
	return adjustedEndpoints, nil
}

And it will loop both of the endpoints. but on the first itirate it will call

e.SetProviderSpecificProperty(source.CloudflareProxiedKey, strconv.FormatBool(proxied))

Without DeepCopy, it will modify the slice referenced in both endpoints. This is basically setting external-dns.alpha.kubernetes.io/cloudflare-proxied: false (or true), meaning whatever gets evaluated first will set the proxied value to true or false and remove the external-dns.alpha.kubernetes.io/cloudflare-proxied: example.com

source: https://github.com/kubernetes-sigs/external-dns/blob/master/provider/cloudflare/cloudflare.go#L386

So the DeepCopy is needed, I guess the only thing is if it's the right place.I wanted to minimize code changes.

@Tazer
Copy link
Author

Tazer commented Mar 22, 2024

@mloiseleur added docs & additional tests also explained the reasoning on DeepClone
#4325 (comment)

@mloiseleur
Copy link
Contributor

Thanks @Tazer, it's clear.

You made quite a good job in order to avoid a breaking change 👍 .
I have to admit also I have doubts about this approach 🤔. First, it comes with impact : some users are handling thousands of records with external-dns and second, more important, should we really do that ?

I mean, sometimes, avoiding a breaking change may cause more harm than good.

In a fictional world where external-dns.alpha.kubernetes.io/hostname has only one entry (like in CloudFlare UI), setting proxied with a bool makes sense.

In the real world where external-dns.alpha.kubernetes.io/hostname may contains multiple entries, I don't see how this proxied annotations can be a bool.

Wdyt about:

  1. Changing external-dns.alpha.kubernetes.io/proxied from a bool to a string
  2. Format of this string could then be
    a. "true|all": proxy all hostnames
    b. "false|none": no proxy for all hostname
    c. "example.com,bar.com": proxy only for example.com and bar.com

cc @cxuu @aoz-turk @johngmyers @danie1sullivan as last PR authors on cloudflare
cc @szuecs @Raffo

@szuecs
Copy link
Contributor

szuecs commented Apr 25, 2024

@mloiseleur I think we can change it from bool to string if this helps. For backwards compatibility we could try to cast as bool and if it's not ok we assume a string.

@Tazer wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants