Repository navigation
Support loading webhook config from versioned file - #4546
Conversation
|
Hi @munnerz. Thanks for your PR. I'm waiting for a jetstack member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
d7bcab4 to
e2f0bf6
Compare
|
/kind feature |
|
An example configuration that can now be loaded with |
|
/test all |
|
/test pull-cert-manager-bazel |
irbekrm
left a comment
There was a problem hiding this comment.
I've read through the code and the upstream docs for component configuration- looks like a really useful change and it was an interesting read 👍🏼 Thanks for linking the upstream doc.
I've also tried to deploy with using with some options provided via WebhookConfiguration.
I've added a couple of comments, mostly questions.
A few more things:
-
I think it would be good to make using the
WebhookConfigurationvia helm- at the moment there is no option to specifiy volumes to be mounted to webhook. Arguably, we could maybe even add a configmap template forWebhookConfigurationthat would probably also serve as documentation as to what fields there are -
Assuming that we want to eventually deprecate the flags and only use the
WebhookConfiguration, what would be the way forward with this? Do we just go with the standard way of deprecating all flags in favour of theWebhookConfigurationand should we aim for theWebhookConfigurationto be v1 at that point? -
I wonder if there is some way how we could force the webhook to reload when the configmap's contents change. Or, perhaps we don't care about this because eventually we'll be watching the
WebhookConfiguration? (I'm still not clear on how boostrapping will work in this setup)
|
/milestone v1.7 |
e2f0bf6 to
0da2819
Compare
I'm in two minds on this, largely because if we expose this as a CRD in future, then we won't be able to have users configure it via the Helm chart (as Helm doesn't play well with deploying instances of a CRD at the same time as installing the CRD itself). I'm +1 on making this easier, and naturally Helm does make sense, but given this is an optional feature for now I think it'd be easier to provide a ConfigMap example that is well documented, and have users create the ConfigMap if they do want to make use of this config API type (we can have the chart deploy with an
Yep that's the way I've seen k8s do it
Yep this would be useful - for now given this is alpha, I've opted to go incrementally with all this stuff. |
ConfigMap makes sense, but I think we need to allow to specify a volume to be mounted for webhook deployment via Helm chart. |
My plan was to not expose this as a config option in the Helm chart, and instead update the Helm chart to always configure the webhook with a volume/volumeMount for a ConfigMap with a 'known name' such as |
irbekrm
left a comment
There was a problem hiding this comment.
I've played around with this PR for a while and it all looks good to me:
- by default when deployed with Helm a configmap will be created, but will be empty and
--configflag will not be passed - if
.values.configis set the fields from there will be synced to the configmap and--configflag will be passed to webhook - since the contents of
.values.configisn't validated and the apiversion needs to be set by user, adding a new api field should not break the helm values - with the static manifests, it is up to the users to create a configmap with the
WebhookConfiguration, mount the volume and set the--configflag - at the moment there is no mechanism to ensure that webhook will reload the config when the contents of the configmap has changed. This may be solved in the future by having the webhook watch a
WebhookConfigurationCR
Looks good to me, I'd be happy to lgtm except for the minor nit with apiversion in values file!
I guess we'll be also wanting to add to website docs how to configure this
| # Flags will override options that are set here. | ||
| config: | ||
| # apiVersion: config.cert-manager.io/v1alpha1 | ||
| # kind: WebhookConfiguration |
There was a problem hiding this comment.
Nit: it may have been useful to put all possible fields here, but commented out so users don't have to look elsewhere to discover the structure
wallrj
left a comment
There was a problem hiding this comment.
I can't get the config file to work.
Here's how I tested:
$ ./devel/cluster/create.sh
$ ./devel/addon/gatewayapi/install.sh
$ ./devel/addon/certmanager/install.sh
# Then
$ cat ../values.yaml
global:
logLevel: 3
installCRDs: true
webhook:
config:
apiVersion: config.webhook.cert-manager.io/v1alpha1
kind: WebhookConfiguration
securePort: 8443
enablePprof: true
$ helm upgrade cert-manager bazel-bin/deploy/charts/cert-manager/cert-manager.tgz --namespace cert-manager --create-namespace --values ../values.yaml --wait --install
Error: UPGRADE FAILED: timed out waiting for the condition
The webhook process logs an error:
kubectl -n cert-manager logs cert-manager-webhook-5c9bdf6fc8-gswwm
E1202 17:17:32.653241 1 webhook.go:166] cert-manager/webhook "msg"="Failed to load webhook config file" "error"="failed to load webhook config file /var/cert-manager/config/config.yaml, error failed to decode: no kind \"WebhookConfiguration\" is registered for version \"config.webhook.cert-manager.io/v1alpha1\" in scheme \"pkg/runtime/scheme.go:100\"" "path"="/var/cert-manager/config/config.yaml"
And the configmap looks like this:
kubectl -n cert-manager get cm cert-manager-webhook -o yaml
apiVersion: v1
data:
config.yaml: |2
apiVersion: config.webhook.cert-manager.io/v1alpha1
enablePprof: true
kind: WebhookConfiguration
securePort: 8443
kind: ConfigMap
metadata:
annotations:
meta.helm.sh/release-name: cert-manager
meta.helm.sh/release-namespace: cert-manager
creationTimestamp: "2021-12-02T17:16:35Z"
labels:
app: webhook
app.kubernetes.io/component: webhook
app.kubernetes.io/instance: cert-manager
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: webhook
name: cert-manager-webhook
namespace: cert-manager
resourceVersion: "906"
uid: 71c9599e-e537-4eea-999b-d12f7dd581f6
Any idea what I'm doing wrong?
|
@wallrj The API group should be |
|
Yep. That was it. It's working now: |
Signed-off-by: James Munnelly <[email protected]>
Signed-off-by: James Munnelly <[email protected]>
…onfig Signed-off-by: James Munnelly <[email protected]>
Yeah I wonder if we're better to not create it at all... not sure. Needs some thought, but I think we can follow up later.
👍 correct!
Yeah we can look at a follow up for this. Either annotating pods with a hash of the config provided (which I think is a common Helm pattern) or improving the webhook to actually handle reloads when it changes 😄 |
|
Retesting after cert-manager/testing#612 /test pull-cert-manager-e2e-v1-22 |
irbekrm
left a comment
There was a problem hiding this comment.
I've read again through the code and it makes sense to me 👍🏼
We should probably add some docs for it on the website too.
Lgtm-ing with a hold so Richard can review
/hold
/lgtm
| {{- end }} | ||
| {{ if not $config.tlsConfig -}} | ||
| {{- $tlsConfig := default $config.tlsConfig "" }} | ||
| {{ if or (not $config.tlsConfig) (and (not $tlsConfig.dynamic) (not $tlsConfig.filesystem) ) -}} |
wallrj
left a comment
There was a problem hiding this comment.
I skimmed through the code and asked a few questions.
Nothing that should stop merging this, except to say that I think it's a bit premature to deprecate the securePort value of the Helm chart.
I'm not convinced that Helm users should care what port the webhook process listens on,
only what port the webhook Pod and perhaps the webhook service use,
neither of which can be changed from the WebhookConfiguration file.
| port: 443 | ||
| protocol: TCP | ||
| targetPort: {{ .Values.webhook.securePort }} | ||
| targetPort: "https" |
There was a problem hiding this comment.
Is https a good name? I'd have thought it better to call it webhook to clearly distinguish it from metrics or pprof ports.
Perhaps this name was already used and can't be changed....I'll read on.
There was a problem hiding this comment.
This was the name of the port previously - I am just changing the chart to use it to reference the port on the backend instead of hardcoding it into the service (which would complicate logic in this template): https://github.com/jetstack/cert-manager/pull/4546/files#diff-1eb646b61f7c20d254f00af700b9bea3f330419d0bb97b0234f58170aedabcdaR81
I think https makes sense as it makes it clear it is a secure service (IMO).
| # rules or requiring NET_BIND_SERVICE capabilities to bind port numbers <1000. | ||
| # This should be uncommented and set as a default by the chart once we graduate | ||
| # the apiVersion of WebhookConfiguration past v1alpha1. | ||
| # securePort: 10250 |
There was a problem hiding this comment.
I can't think of a use case for wanting to change the listening port of the webhook process, when deployed with helm.
Only time I'd want to change this is when running the process locally on my laptop.
If run in a cluster, the process will always be run in a docker container and it won't matter what port the process listens on. Only matters which port is mapped to this in the PodTemplate, and then only on GKE private clusters.
There was a problem hiding this comment.
The containerPort bit doesn't remap ports - it just 'names' a port on the Pod (for the Service to then send traffic to). So we do need a way for users to configure this (for ex private GKE clusters). Things like ECS (or maybe it was Lightsail? not sure) also have issues with 10250 if I recall correctly, due to pods running in hostNetwork there & a conflict with the local kubelet.
There was a problem hiding this comment.
You're right. Sorry. I was muddling Kubernetes networking with docker run -p port mapping. Thinking that Kubernetes always did some sort of port forwarding.
| # DEPRECATED: use webhook.config.securePort instead. | ||
| securePort: 10250 |
There was a problem hiding this comment.
It seems a bit premature to deprecate this.
I personally think that this is the correct field and that the Helm chart shouldn't attempt to configure either the --secure-port flag or the securePort field in the config file.
There was a problem hiding this comment.
It seems a bit premature to deprecate this.
👍 I'll remove this line
I personally think that this is the correct field and that the Helm chart shouldn't attempt to configure either the --secure-port flag or the securePort field in the config file.
Not 100% sure what you mean by this, but this isn't any kind of net-addition to the chart as we've always supported changing the listening port of the container (in order to allow people to workaround any environment specific quirks)
It is possible to change the listen port of the process - that's exactly what |
Signed-off-by: James Munnelly <[email protected]>
wallrj
left a comment
There was a problem hiding this comment.
This looks good to me.
Many of my last review comments about securePort were mistaken (see below).
Some remaining questions:
- Will you be introducing a feature flag for this configuration file stuff?
- Is there any code here which has been copied from Kubernetes? And if so, perhaps we should add links to the upstream code: for our own benefit so that we can easily check upstream to see what improvements they've made in this area, and to give some copyright credit to the original authors.
Those could be addressed in later PRs if necessary (before next release) in which case unhold and merge this as-is.
/lgtm
/approve
| # rules or requiring NET_BIND_SERVICE capabilities to bind port numbers <1000. | ||
| # This should be uncommented and set as a default by the chart once we graduate | ||
| # the apiVersion of WebhookConfiguration past v1alpha1. | ||
| # securePort: 10250 |
There was a problem hiding this comment.
You're right. Sorry. I was muddling Kubernetes networking with docker run -p port mapping. Thinking that Kubernetes always did some sort of port forwarding.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: irbekrm, munnerz, wallrj The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
It was decided to not have a feature flag for this, given it requires explicitly enabling anyway to get this turned on. Also, when looking in the upstream project, there was not a feature flag for the config file work (only for the dynamic config work where the the configuration is read from an actual CRD in the apiserver)
There's not any code that's been copied 1:1 - the majority of this is 'inspired by' the upstream work, and follows the component-base/configuration guidelines. Thanks for all the reviews everyone! /hold cancel |
What this PR does / why we need it:
This PR adds support for loading configuration following the
k8s.io/component-baserecommendations (https://docs.google.com/document/d/1FdaEJUEh091qf5B98HM6_8MS764iXrxxigNIdwHYW9c/edit#heading=h.ctbveyrh07ch).It adds a new type,
WebhookConfiguration, which today contains a field for each of the current options we expose as flags.This will allow us to e.g. rename fields, as well as pave the way for dynamically loading config (i.e. one day these types could be used as CRDs, with our various components watching for their own config objects).
Special notes for your reviewer:
Most of the complexity in this is within
cmd/webhookand is there to handle 'layering' of configuration. In accordance with component-base recommendations, all options specified as flags on the CLI by the user will always take precedence over the equivalent field in the WebhookConfiguration object.Release note:
/cc @wallrj