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

Optional ability to use the host name defined on an ingress's annotations *instead* of its hosts stanza #1696

Conversation

dansimone
Copy link
Contributor

@dansimone dansimone commented Jul 29, 2020

There are situations where it would be useful to have external-dns create entries based on the "external-dns.alpha.kubernetes.io/hostname" annotation on an ingress, but not on the hosts defined in the hosts stanza. The current external-dns behavior is to create both entries.

Some examples where this would be useful:

  • This open issue: Ingress: external-dns.alpha.kubernetes.io/hostname: force usage #1053
  • A similar situation where one defines a wildcard DNS entry via annotation for multiple ingresses whose host names (hosts stanza) are covered by the wildcard entry. In this case, only the wildcard entry is desired in DNS. The hosts stanza on the ingress, in this case, is only used by an ingress-controller for its routing.

Possible approaches to implement this behavior:

  1. Globally-scoped parameter: Introduce a new command line parameter: "prefer-ingress-hostname-annotation". If not set, no functional changes occur. If set, then for all ingresses, when processing the ingress host names, if a host name annotation is specified, it is used instead of those from the hosts stanza.
  2. Ingress-scoped annotation: Introduce a new optional annotation that can be placed on specific ingresses. If not specified, then no functional changes occur. If set on an ingress, then the same behavior as Document design: features and annotations #1 will occur for records related to that ingress.
  3. Both 1 and 2.

This current PR goes with approach 2 (originally proposed by @cryptk) - IMO that is the smallest footprint way of implementing this. 1 and 3 involve a new command line parameter, some function argument changes, etc. It's easily doable though, if desired. I'll defer to feedback from the maintainers on whether to go with 1 or 3.

The current PR adds the annotation described by this included update to the FAQ:

1. For ingress objects ExternalDNS will create a DNS record based on the hosts specified for the ingress object, as well as the `external-dns.alpha.kubernetes.io/hostname` annotation.  For services ExternalDNS will look for the annotation `external-dns.alpha.kubernetes.io/hostname` on the service and use the corresponding value.
    - For ingresses, you can optionally force ExternalDNS to create records based on _either_ the hosts specified or the `external-dns.alpha.kubernetes.io/hostname` annotation.  This behavior is controlled by
      setting the `external-dns.alpha.kubernetes.io/ingress-hostname-source` annotation on that ingress to either `defined-hosts-only` or `annotation-only`. 

Unit tests added to verify the behavior.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 29, 2020
@dansimone
Copy link
Contributor Author

dansimone commented Jul 29, 2020

@andrecastro and @cryptk FYI on this PR - I was forced to reopen the previous PR with a fresh PR.

@dansimone
Copy link
Contributor Author

/assign @njuettner for review and feedback on the approaches mentioned in the description.

Also, I may need help understanding the code coverage failure. The 17 lines of code I added to ingress.go are covered by a new unit test. But it appears that ingress.go (as a whole) is being reported as having 0 lines covered for some reason, which looks like a general problem with the code coverage job to me.

@Dirrk
Copy link

Dirrk commented Aug 7, 2020

/retest

@k8s-ci-robot
Copy link
Contributor

@Dirrk: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@seanmalloy
Copy link
Member

/kind feature

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 14, 2020
@maxenglander
Copy link

Thanks for this PR @dansimone! I need this :)

A use case I have is that I have some Ingress objects which I want external-dns to create Route 53 entries for, and other Ingress objects that have DNS records managed outside of external-dns. I don't want external-dns to touch that second set of Ingress objects at all.

Right now (correct me if I'm wrong) I think I would have to update all of my Ingress objects to have a value like none, before I can safely enable ingress source. That's not the end of the world of course, but ideally, I think I'd like the option to specify a --default-ingress-hostname-source command flag and set it to none, or some other value indicating that I want the default behavior to be "leave these ingresses alone!"

Don't have to make those changes in this PR of course, just expressing my interest in this PR in general, and my particular use case for the current or a future PR.

@cubic3d
Copy link

cubic3d commented Aug 24, 2020

All my ingresses define a root domain(example.com) and wildcard domain (*.example.com) in the tls section. Additionally the actual subdomain for the host. External-dns tries always to update all 3 records - I see no other setting to avoid the generation from the tls section.

@dansimone
Copy link
Contributor Author

@cubic3d - yep, your case is similar to mine.

Side note - I have another PR out to get external-dns's support for wildcard DNS entries working generically, since it doesn't work currently except with some specific providers : #1695).

@dansimone
Copy link
Contributor Author

@maxenglander - for your case, to get external-dns to not even look at your ingress at all, you could omit all of the external-dns.alpha.kubernetes.io annotations, like "external-dns.alpha.kubernetes.io/target". I confirmed that just now in my environment (although I am running with quite a few patches on external-dns, so take that with a grain of salt!)

This MR here would be for a case where you do want external-dns to act on your ingress, but not to create DNS entries for both the annotation section and the hosts stanza.

@dansimone
Copy link
Contributor Author

@hjacobs, @njuettner - whenever you guys get a chance to look at this, it's freshly synced with master and passing CI.

@dansimone
Copy link
Contributor Author

/assign @njuettner

@maxenglander
Copy link

Thanks for the reply @dansimone. I found that when I have an Ingress with a host stanza external-dns will try to create a DNS record, even in the absence of any external-dns annotation.

It's possible there was something else going on or some other misconfiguration I had to produce that result, but it does seem to be expected based on these docs.

I'll take another look though.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 24, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 25, 2020
@dansimone
Copy link
Contributor Author

It looks like a PR in the same ballpark as this got merged a few days ago: #1645 However that change makes a global setting, and this PR allows the flexibility per-ingress (via a new annotation). I've synced up my branch with master, and both changes should play nice together.

@artem-nefedov
Copy link

This feature is exactly what we need.
Hope to see this merged soon.

@dansimone
Copy link
Contributor Author

@hjacobs, @njuettner please let me know when you get a chance to look at this.

Copy link
Member

@njuettner njuettner left a comment

Choose a reason for hiding this comment

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

LGTM, some minor nits. If addressed I'm happy to merge it 👍

docs/faq.md Outdated Show resolved Hide resolved
docs/faq.md Outdated Show resolved Hide resolved
source/ingress.go Outdated Show resolved Hide resolved
@dansimone
Copy link
Contributor Author

Thanks for the feedback, @njuettner. Let me know how the latest looks to you.

@dansimone
Copy link
Contributor Author

I just resolved the above conversations, @njuettner, let me know if this looks alright.

@tuusberg
Copy link

tuusberg commented Dec 14, 2020

@dansimone thanks for implementing it. Would this feature allow ignoring certain Kubernetes resources?
e.g. If I don't want to create DNS records for every Ingress host?

@danopia
Copy link

danopia commented Dec 16, 2020

@tuusberg

ignoring certain Kubernetes resources

Sounds like you might want an annotation filter there, which has been available and is pretty common to use. I use an annotation filter that overlaps with the ingressclass annotation but you can filter on whatever custom annotation you want

dan.simone@oracle.com added 3 commits January 4, 2021 15:39
@dansimone
Copy link
Contributor Author

Ok, a new (minor doc) conflict just popped up. Resolved. @njuettner, please review.

Copy link
Contributor

@jlamillan jlamillan left a comment

Choose a reason for hiding this comment

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

I've tested this out and it works well.

source/ingress.go Outdated Show resolved Hide resolved
source/ingress.go Outdated Show resolved Hide resolved
source/source.go Show resolved Hide resolved
source/source.go Outdated Show resolved Hide resolved
@vsetka
Copy link

vsetka commented Feb 25, 2021

Can we merge this, please?

@dansimone
Copy link
Contributor Author

@njuettner I just went ahead and closed this comment: #1696 (comment) But I'm looking for input on the pros and cons that I pointed out above, although I went with your suggestion for now.

@dansimone dansimone requested a review from njuettner May 8, 2021 03:53
@arobie1992
Copy link

Is there any expected inclusion date for this feature?

Copy link
Member

@njuettner njuettner 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 14, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dansimone, jlamillan, njuettner

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 14, 2021
@k8s-ci-robot k8s-ci-robot merged commit 2f78d09 into kubernetes-sigs:master Jun 14, 2021
@marko-espi
Copy link

in which version this is going to be released?

@danopia
Copy link

danopia commented Aug 25, 2021

Github's UI indicates that this is present in v0.9.0.
Screenshot 2021-08-25 10 04 53

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. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet