Skip to content

Allow ingressClass to be specified for ingress-shim - #454

Closed
bbetter173 wants to merge 13 commits into
cert-manager:masterfrom
bbetter173:master
Closed

bbetter173 wants to merge 13 commits into
cert-manager:masterfrom
bbetter173:master

Conversation

@bbetter173

@bbetter173 bbetter173 commented Apr 12, 2018 •

Copy link
Copy Markdown

What this PR does / why we need it:
This allows an Ingress to be annotated with 'certmanager.k8s.io/ingress-class: nginx', which signals that any Certificates created for this Ingress resource that use HTTP01 challenges should use ingressClass: instead of ingress:

Which issue this PR fixes fixes #235, fixes #454

Special notes for your reviewer:

I'm not overly familiar with Go, so I expect there might be some things I need to tidy up. I'm not convinced the presence of the annotation should trigger a sync, either. Please let me know if you'd like something changed.

Release note:

@jetstack-bot

Copy link
Copy Markdown
Contributor

@HeWhoWas: Adding do-not-merge/release-note-label-needed because the release note process has not been followed.

Details

One of the following labels is required "release-note", "release-note-action-required", or "release-note-none".
Please see: https://git.k8s.io/community/contributors/devel/pull-requests.md#write-release-notes-if-needed.

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.

@jetstack-bot jetstack-bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Apr 12, 2018
@jetstack-bot
jetstack-bot requested a review from kragniz April 12, 2018 11:53
@jetstack-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: kragniz

Assign the PR to them by writing /assign @kragniz in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@jetstack-bot jetstack-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 12, 2018
@munnerz

munnerz commented Apr 12, 2018

Copy link
Copy Markdown
Member

Thanks for this PR!

So given we actually know the ingress class for a particular ingress already, I'm not sure we need to allow the user to specify a custom ingress class to be used.

Instead, we could introduce a certmanager.k8s.io/edit-in-place annotation.

If this annotation is not set to "true": set the ingress class field to that of the Ingress being processed
If this annotation is set to "true": set the ingress field (as we do today).

What do you think? I'm not certain exposing the ingress class field in its entirety is required. ingress-shim is meant to provide a 'user friendly' abstraction to make things easy in 9/10 usecases, and if a user needs some advanced functionality they can fall back to creating the Certificate themselves.

Comment thread docs/reference/ingress-shim.rst Outdated
* ``certmanager.k8s.io/ingress-class: ""`` - by default, if the
'kubernetes.io/tls-acme' annotation is set to "True", the resulting Certificate
is created with 'ingest: <name>' in the acme spec. If present, this annotation
will alter this behaviour and supply 'ingestClass: <value>' when creating the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/ingest/ingress/g

Comment thread docs/reference/ingress-shim.rst Outdated
specified as arguments to the ingress-shim container.

* ``certmanager.k8s.io/ingress-class: ""`` - by default, if the
'kubernetes.io/tls-acme' annotation is set to "True", the resulting Certificate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"True" should be "true"

@bbetter173

Copy link
Copy Markdown
Author

So given we actually know the ingress class for a particular ingress already, I'm not sure we need to allow the user to specify a custom ingress class to be used.

True.

Instead, we could introduce a certmanager.k8s.io/edit-in-place annotation.

If this annotation is not set to "true": set the ingress class field to that of the Ingress being processed If this annotation is set to "true": set the ingress field (as we do today).

What do you think? I'm not certain exposing the ingress class field in its entirety is required. ingress-shim is meant to provide a 'user friendly' abstraction to make things easy in 9/10 usecases, and if a user needs some advanced functionality they can fall back to creating the Certificate themselves.

Sounds good!

Comment thread cmd/ingress-shim/controller/sync.go Outdated
} else {
ingressClass, ok := ingAnnotations["kubernetes.io/ingress.class"]
if !ok {
return fmt.Errorf("unable to determine class of ingress %s", ing.Name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure we should error here - according to the ingress spec, it is valid to have a ingress without a class. In this instance, all ingress controllers will act on the ingress resource.

Right now, if a user does not specify ingress or ingressClass on the Certificate resource, an ingress will be created that does not specify ingress class. We should probably do the same here too (i.e. if edit-in-place is not specified, and ingress class isn't specified, just leave the ingress/ingressClass fields blank)

Comment thread cmd/ingress-shim/controller/sync.go Outdated
tlsACMEAnnotation = "kubernetes.io/tls-acme"
// editInPlaceAnnotation is used to toggle the use of ingressClass instead
// of ingress on the created Certificate resource
editInPlaceAnnotation = "certmanager.k8s.io/edit-in-place"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably prefix this with acme-http01 to bring it in-line with other annotations, e.g. certmanager.k8s.io/acme-http01-edit-in-place. It's quite wordy, but it is more specific (and I'd hope more obvious to the user what it is for?)

…hout setting either ingress or ingressClass.
Comment thread docs/reference/ingress-shim.rst Outdated
set to http01, and the ingress has the 'kubernetes.io/tls-acme: true'
annotation, this controls whether the ingress is modified 'in-place', or a new
one created specifically for the http01 challenge. Must be 'true' or 'false'.
Defaults to 'false'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps worth noting that any value other than 'true' is classed as 'false'

@munnerz

munnerz commented Apr 12, 2018

Copy link
Copy Markdown
Member

Can you also fix unit tests and add a new unit test for this functionality? It should be clear how from the contents of sync_test.go 😄

/ok-to-test

@jetstack-bot jetstack-bot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 12, 2018
@jetstack-bot

Copy link
Copy Markdown
Contributor

@HeWhoWas: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
cert-manager-quick-verify 23169ed link /test verify
cert-manager-e2e-v1-8 23169ed link /test e2e v1.8
cert-manager-e2e-v1-7 23169ed link /test e2e v1.7
cert-manager-e2e-v1-9 23169ed link /test e2e v1.9

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

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. I understand the commands that are listed here.

@bbetter173

Copy link
Copy Markdown
Author

@munnerz - This is where I start to fall down a little bit, I'm not sure why the tests are failing and it's not totally obvious to me how to add more unit tests, sorry. I'm happy to learn, but I'll need a bit of direction if you're wiling.

@munnerz

munnerz commented Apr 13, 2018

Copy link
Copy Markdown
Member

@HeWhoWas so if you take a look here: https://github.com/jetstack/cert-manager/blob/master/cmd/ingress-shim/controller/sync_test.go#L76-L126

That's an example of a single test for the sync function.

You can add your own test cases in there, and also update the existing one that's failing.

You will only need to adjust the Name, Ingress and ExpectedCreate fields in those structures. You should define:

  • One test case where the ingress has the annotation you've added set, and then input the expected 'desired' certificate resource.

  • One test case where the ingress has the annotation you've added set to something other than 'true'

  • Fix up the existing test case that does not define the annotation (I think you need to add an ingress class to the Ingress resource, and ensure that ingressClass is set to the same value as the ingress class on the ingress)

Hope that helps - if not, I can put a commit on top of your PR that updates the tests for you, which should hopefully help for next time 😄

@bbetter173

Copy link
Copy Markdown
Author

Hey @munnerz - I've been trying to get the time to flesh out the tests, but it appears that going forwards we won't be using the ingress shim and instead use multiple dnsNames for a single certificate.

In short, it's unlikely I'll get the time to complete this PR. If you don't mind adding the tests, please do, otherwise I'll just close this off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http01 is defeated by Ingress auth, cert-manager should have option to create own Ingress when using ingress-shim

4 participants