Skip to content

[WIP] Gateway API support for ingress-shim - #4121

Closed
jakexks wants to merge 7 commits into
cert-manager:masterfrom
jakexks:certificate-shim
Closed

jakexks wants to merge 7 commits into
cert-manager:masterfrom
jakexks:certificate-shim

Conversation

@jakexks

@jakexks jakexks commented Jun 18, 2021 •

Copy link
Copy Markdown
Member
⚠ Closed in favor of #4158

What this PR does / why we need it: cert-manager aims to make issuing ACME certificates for public endpoints as painless as possible. A popular use-case is to annotate ingress definitions, which cert-manager's ingress-shim uses to create Certificates automatically.

As part of #4118, we aim to add support for the sig-network community's Gateway API as a way to solve http-01 challenges. cert-manager should be able to read annotations from Gateways and turn these into Certificates just as it currently can with Ingresses

Which issue this PR fixes: Fixes #4119

Special notes for your reviewer:
the sync.go diff has become large enough that Github hides it by default.

Release note:

Added a new optional controller: gateway-shim. cert-manager now supports automatic creation of ACME certificates for the sig-network Gateway API Gateway, when annotated similarly to existing support for Ingresses.

@jetstack-bot jetstack-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 18, 2021
@jetstack-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jakexks

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 18, 2021
@jakexks
jakexks force-pushed the certificate-shim branch 3 times, most recently from 9c22449 to 6bd72c0 Compare June 21, 2021 12:55
@jetstack-bot jetstack-bot added area/deploy Indicates a PR modifies deployment configuration size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 22, 2021
This commit lays the groundwork for supporting multiple shims - Ingress specific code has been replace with more generic runtime.Object or metav1.Object code.

Signed-off-by: Jake Sanders <[email protected]>
@jakexks
jakexks force-pushed the certificate-shim branch from 7497d0b to 56d484b Compare June 23, 2021 08:30
Comment on lines -235 to +237
IngressShimOptions: controller.IngressShimOptions{
CertificateShimOptions: controller.CertificateShimOptions{

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 remember hearing that "ingress shim" was not an appropriate name and that "certificate shim" made more sense. Could you document that somewhere? E.g. in the website since end-users may also wonder why we are calling it that 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, after the feedback from the last retro this should not be merged without a matching PR to the documentation

jakexks added 3 commits June 23, 2021 09:50
Signed-off-by: Jake Sanders <[email protected]>
Signed-off-by: Jake Sanders <[email protected]>
Signed-off-by: Jake Sanders <[email protected]>
@jakexks
jakexks force-pushed the certificate-shim branch from 56d484b to b25469c Compare June 23, 2021 09:01
Comment thread pkg/controller/certificate-shim/sync.go Resolved
Comment on lines +169 to +178
if l.TLS.CertificateRef.Group != "core" {
errs = append(
errs,
fmt.Errorf(
"unsupported certificateRef.group, want %s got %s",
"core",
l.TLS.CertificateRef.Group,
),
)
}

@maelvls maelvls Jun 23, 2021 •

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.

question: should we also look at the TLS block on the HTTPRoute? From this thread:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍 I will have to comb over the semantics of gateways and routes and then write a bunch of tests

func (c *controller) validateObject(obj metav1.Object) []error {
switch o := obj.(type) {
case *networkingv1beta1.Ingress:
// check for duplicate values of networkingv1beta1.IngressTLS.SecretName

@maelvls maelvls Jun 23, 2021 •

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.

question: why do we need to bail out when two TLS blocks contain the same secretName? I can't figure that out (apologies for commenting on old code!)

Comment thread pkg/controller/certificate-shim/sync.go Resolved

func (c *controller) Sync(ctx context.Context, ing *networkingv1beta1.Ingress) error {
log := logf.WithResource(logf.FromContext(ctx), ing)
func (c *controller) Sync(ctx context.Context, obj runtime.Object) error {

@maelvls maelvls Jun 23, 2021 •

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.

This reconciliation function focuses on multiple object types (Ingress + Gateway + HTTPRoute in the future).

The positive side is that we get a bit of code deduplication.

On the negative side, we are making things blurrier for the reader due to having another level of indirection (i.e., the new "generic lister").

I might be missing something: why not have a separate Sync function for each kind (Ingress, Gateway, and soon HTTPRoute)? Is it too costly in terms of boilerplate?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A couple of thoughts from me: It's written with the future in mind (this could help with supporting multiple ingress versions at once). Also most of the functionality is the same (reading the annotations), the only difference is parsing the reference to TLS secrets

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For what it's worth, I started this WIP by writing duplicate functions and I thought it was worse.

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.

Could we adjust this to be two distinct controllers, but where there is duplicate logic, factor that into standalone library functions instead? This will be easier to maintain long term, including when/if we ever create alternate ingress-shim's too (rather than having to constantly add more complex switching logic into this one controller)

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 started working on this idea. As a first step, I opened #4149

@jakexks jakexks left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Some of my own thoughts

Comment thread WORKSPACE
protobuf_deps()

## Load rules_go and dependencies
## Load rules_go and dependencies

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This replaces a unicode non breaking space with a normal space

--set installCRDs=true \
--set featureGates="${FEATURE_GATES:-}" \
--set "extraArgs={--dns01-recursive-nameservers=${SERVICE_IP_PREFIX}.16:53,--dns01-recursive-nameservers-only=true}" \
--set "extraArgs={--dns01-recursive-nameservers=${SERVICE_IP_PREFIX}.16:53,--dns01-recursive-nameservers-only=true,--controllers=*,--controllers=gateway-shim}" \

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As Gateway-shim is disabled by default, enable it here

check_tool kubectl
check_tool kustomize

kustomize build "github.com/kubernetes-sigs/gateway-api/config/crd?ref=$GATEWAY_API_VERSION" | \

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried for half an hour to get this with an http_archive to make the build more bazel like but gave up

gatewaylisters "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1alpha1"
)

// objectLister is the most minimal generic lister.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This isn't very nice. But I couldn't think of anything better

@maelvls maelvls Jun 24, 2021 •

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.

After thinking about lister.go, I could not think of any other way.

I thought about injecting Get() metav1.Object and List() []metav1.Object but in the end the code would be very similar with what you have written in lister.go.

I approve lister.go!

@JoshVanL JoshVanL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me :) small comment from me.

Have we ensured we have changed the wording throughout the codebase and website?

I assume we want to keep the idea of "ingress-shim", but how about in the code?

@jakexks

jakexks commented Jun 23, 2021

Copy link
Copy Markdown
Member Author

Have we ensured we have changed the wording throughout the codebase and website?

I did a minimal pass through the code but will be a bit more thorough as this evolves. Before this PR is merged we will need a matching documentation PR to the website's release-next branch.

I assume we want to keep the idea of "ingress-shim", but how about in the code?

I think the idea should be renamed to certificate-shim. However there are ingress specific annotations such as the edit-in-place one, so there will have to be documentation for both ingresses and gateways making the differences clear.

Signed-off-by: Jake Sanders <[email protected]>
@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 23, 2021
@jakexks

jakexks commented Jun 23, 2021

Copy link
Copy Markdown
Member Author

/milestone v1.5

@jetstack-bot jetstack-bot added this to the v1.5 milestone Jun 23, 2021
@jakexks

jakexks commented Jun 23, 2021

Copy link
Copy Markdown
Member Author

/kind feature

@jetstack-bot jetstack-bot added kind/feature Categorizes issue or PR as related to a new feature. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jun 23, 2021
@jakexks jakexks added the area/ingress-shim Indicates a PR or issue relates to the ingress-shim 'auto-certificate' component label Jun 23, 2021
@munnerz

munnerz commented Jun 24, 2021

Copy link
Copy Markdown
Member

I've not had a proper review of this, but I feel like this would be a lot easier to maintain if we don't try and slam two different controllers into one.

It is surprising to me that adding support for Gateway resources has involved touching so much of the existing ingress-shim code, and it makes this PR feel riskier to merge (as there's a whole load of well-used existing code that is being touched/reworked).

@munnerz

munnerz commented Jun 24, 2021

Copy link
Copy Markdown
Member

I think having a standalone one (with perhaps some shared library bits where it makes sense, e.g. for parsing annotations) will make it easier to support nuances of the two different API types in future.

@jakexks

jakexks commented Jun 24, 2021 •

Copy link
Copy Markdown
Member Author

Happy to make it separate controllers. I started this PR by doing that but felt that most of the functionality was duplicated. A library approach would also work fine.

A certificate-shim controller:

  1. Reads annotations from a resource (which will almost always be the same, except for a few very specific annotations)
  2. Extracts the TLS hostnames from it (which will almost always be different)
  3. Constructs a certificate (which is the same)

It is surprising to me that adding support for Gateway resources has involved touching so much of the existing ingress-shim code, and it makes this PR feel riskier to merge

It was mostly replacing the type signature of a function that took a *networkingv1beta1.Ingress with runtime.Object. None of the logic was touched and there is a very comprehensive set of tests in sync_test that passed before and after.

@jakexks

jakexks commented Jun 25, 2021

Copy link
Copy Markdown
Member Author

Couple of thoughts after doing something else for a day:

  • gateway-shim and ingress-shim are still separate controllers, just in one package. This might be confusing.
  • Refactoring it into 2 packages + a utility one would be easier to read and maintain, but would touch a similar amount of the ingress-shim code. Happy to do this.

@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2021
@jetstack-bot

Copy link
Copy Markdown
Contributor

@jakexks: PR needs rebase.

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.

@maelvls

maelvls commented Jul 5, 2021

Copy link
Copy Markdown
Member

Should we close this PR in favor of #4158?

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. area/deploy Indicates a PR modifies deployment configuration area/ingress-shim Indicates a PR or issue relates to the ingress-shim 'auto-certificate' component dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"gateway-shim" - Easy ACME for the sig-network Gateway API

5 participants