Currently (v0.5.0) the +kubebuilder:webhook marker does not support setting an objectSelector on a webhook. objectSelector is especially handy when mutating or validating core types. For example, I want to be able to set an environment variable on a subset of pods in a particular namespace, but not my controller manager pod, which runs in the same namespace and runs the webhook server.
I realize that the docs recommend running the webhook server in a separate namespace and scoping the validation to the target namespace to avoid deadlock, but that's not feasible for various reasons. Setting a label on the pods I want to mutate works perfectly fine but there's no way to do it (that I know of) without breaking my workflow, which involves generating the MutatingWebhookConfiguration with markers and patching it with kustomize in one shot. (I'm using a lightly modified version of what kubebuilder init provides.) I could patch the objectSelector field if it were there in the generated config.
I propose something as simple as an optional objectSelectorLabel=string that generates the following:
objectSelector:
matchLabels:
foo: patchMe
Where foo is the user-provided string and patchMe is some default that the user can patch.
I'm happy to put something together if there's an appetite for it.
Currently (v0.5.0) the
+kubebuilder:webhookmarker does not support setting anobjectSelectoron a webhook.objectSelectoris especially handy when mutating or validating core types. For example, I want to be able to set an environment variable on a subset of pods in a particular namespace, but not my controller manager pod, which runs in the same namespace and runs the webhook server.I realize that the docs recommend running the webhook server in a separate namespace and scoping the validation to the target namespace to avoid deadlock, but that's not feasible for various reasons. Setting a label on the pods I want to mutate works perfectly fine but there's no way to do it (that I know of) without breaking my workflow, which involves generating the MutatingWebhookConfiguration with markers and patching it with kustomize in one shot. (I'm using a lightly modified version of what
kubebuilder initprovides.) I could patch the objectSelector field if it were there in the generated config.I propose something as simple as an optional
objectSelectorLabel=stringthat generates the following:Where
foois the user-provided string andpatchMeis some default that the user can patch.I'm happy to put something together if there's an appetite for it.