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

Adding support for Traefik to respect the K8s ingress class annotation #1182

Merged
merged 12 commits into from
Mar 3, 2017

Conversation

regner
Copy link
Contributor

@regner regner commented Feb 22, 2017

This is a first pass of making Traefik understand and respect the kubernetes.io/ingress.class annotation in Kubernetes.

There is a discussion in #1163 about how this should be handled. The objective of this PR is to have Traefik respond to the annotation in the same way other ingress controllers such as NGINX handle it. That being:

  • Use ingress that have an annotation matching "traefik"
  • Use ingress that have an annotation matching "" (a blank string)
  • Use ingress that do not have the annotation at all
  • Ignore all ingress that have an annotation of anything else

There is also discussion in the above mentioned issue about support for configuring what the annotation matches, for example being able to say "accept annotations that match traefik-internal" instead of matching on traefik. There doesn't seem to be clear consensus on how that should be handled. I think that should be spun out as a separate issue and done in isolation of this PR.

Fixes #1163

Pinging @emilevauge @SantoDE @errm @dtomcej @vdemeester

@regner
Copy link
Contributor Author

regner commented Feb 23, 2017

Test failures seem unrelated. Something to do with timing out while pulling the golang container. Is there an easy way to retrigger that?

@dtomcej
Copy link
Contributor

dtomcej commented Feb 23, 2017

Weird. Restarted.

@regner
Copy link
Contributor Author

regner commented Feb 23, 2017

Thanks! Much appreciated.

@regner
Copy link
Contributor Author

regner commented Feb 23, 2017

Well, apparently my tests are not properly formatted. Taking a look now.

@regner
Copy link
Contributor Author

regner commented Feb 24, 2017

Moved the test for if an ingress should be processed into a separate function and made it a switch case. The code is a bit more verbose but i think a lot more clear as to its intentions. With that I think this is ready. :D

@regner
Copy link
Contributor Author

regner commented Feb 28, 2017

I believe this is ready for review. Sorry if I am spamming with the pings :)

Pinging @emilevauge @SantoDE @errm @dtomcej @vdemeester

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

Left a few more comments. :)

You can control which ingress Træfɪk cares about by using the "kubernetes.io/ingress.class"
annotation. By default if the annotation is not set at all Træfɪk will include the
ingress. If the annotation is set to another other than traefik or a blank string
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want to say s/another/anything/ .

PassHostHeader = false
default:
log.Warnf("Unknown value of %s for traefik.frontend.passHostHeader, falling back to %s", passHostHeaderAnnotation, PassHostHeader)
if shouldProcessIngress(ingressClass) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Can we do

if !shouldProcessIngress(ingressClass) {
  continue
}

in order to avoid going even further nested to help readability?

switch ingressClass {
case "":
return true
case "traefik":
Copy link
Contributor

Choose a reason for hiding this comment

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

You can merge this case with the previous like

case "traefik", "":
  return true

(The comma separator is like a logical OR.)

@regner
Copy link
Contributor Author

regner commented Mar 1, 2017

Thanks once again for the comments @timoreimann, I was unaware of the comma usage in the switch statements.

Made the requested changes. :)

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

Such reduced diff, much wow! 🎉

LGTM.

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

Hey @regner great work !
LGTM :)

Copy link
Contributor

@errm errm left a comment

Choose a reason for hiding this comment

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

Very nice LGTM

@timoreimann
Copy link
Contributor

@regner let's sync and merge. Looking forward to using this. :-)

@timoreimann timoreimann merged commit f530284 into traefik:master Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

traefik doesn't respect kubernetes.io/ingress.class
6 participants