external-dns icon indicating copy to clipboard operation
external-dns copied to clipboard

feat: added support per dns cf proxy

Open Tazer opened this issue 11 months ago • 12 comments

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

  • [x] Unit tests updated
  • [x] End user documentation updated

Tazer avatar Mar 20 '24 09:03 Tazer

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: Tazer / name: Patrik (a667d82c9bf2efff46843b319658a9f84f1a0082, d139597e5a343f0cd03034e404fd651112236586, 82fa497130c09df2651df0319a7325df04c6146f, df5d200265777e8419280d4dc8d08f0f70cfb263)

[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 avatar Mar 20 '24 09:03 k8s-ci-robot

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. :smiley:

k8s-ci-robot avatar Mar 20 '24 09:03 k8s-ci-robot

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 avatar Mar 20 '24 09:03 k8s-ci-robot

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 avatar Mar 21 '24 13:03 mloiseleur

/ok-to-test

mloiseleur avatar Mar 21 '24 13:03 mloiseleur

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 avatar Mar 21 '24 20:03 Tazer

@mloiseleur added docs & additional tests also explained the reasoning on DeepClone https://github.com/kubernetes-sigs/external-dns/pull/4325#issuecomment-2013644409

Tazer avatar Mar 22 '24 09:03 Tazer

Thanks @Tazer, it's clear.

You made quite a good job in order to avoid a breaking change :+1: . I have to admit also I have doubts about this approach :thinking:. 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

mloiseleur avatar Mar 25 '24 08:03 mloiseleur

@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?

szuecs avatar Apr 25 '24 14:04 szuecs

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jul 24 '24 15:07 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Aug 23 '24 16:08 k8s-triage-robot