8.4. Types of webhook admission plug-ins
Cluster administrators can call out to webhook servers through the mutating admission plug-in or the validating admission plug-in in the API server admission chain.
8.4.1. Mutating admission plug-in
The mutating admission plug-in is invoked during the mutation phase of the admission process, which allows modification of resource content before it is persisted. One example webhook that can be called through the mutating admission plug-in is the Pod Node Selector feature, which uses an annotation on a namespace to find a label selector and add it to the pod specification.
Sample mutating admission plug-in configuration
apiVersion: admissionregistration.k8s.io/v1beta1 kind: MutatingWebhookConfiguration 1 metadata: name: <webhook_name> 2 webhooks: - name: <webhook_name> 3 clientConfig: 4 service: namespace: default 5 name: kubernetes 6 path: <webhook_url> 7 caBundle: <ca_signing_certificate> 8 rules: 9 - operations: 10 - <operation> apiGroups: - "" apiVersions: - "*" resources: - <resource> failurePolicy: <policy> 11 sideEffects: None
- 1
- Specifies a mutating admission plug-in configuration.
- 2
- The name for the
MutatingWebhookConfiguration
object. Replace<webhook_name>
with the appropriate value. - 3
- The name of the webhook to call. Replace
<webhook_name>
with the appropriate value. - 4
- Information about how to connect to, trust, and send data to the webhook server.
- 5
- The namespace where the front-end service is created.
- 6
- The name of the front-end service.
- 7
- The webhook URL used for admission requests. Replace
<webhook_url>
with the appropriate value. - 8
- A PEM-encoded CA certificate that signs the server certificate that is used by the webhook server. Replace
<ca_signing_certificate>
with the appropriate certificate in base64 format. - 9
- Rules that define when the API server should use this webhook admission plug-in.
- 10
- One or more operations that trigger the API server to call this webhook admission plug-in. Possible values are
create
,update
,delete
orconnect
. Replace<operation>
and<resource>
with the appropriate values. - 11
- Specifies how the policy should proceed if the webhook server is unavailable. Replace
<policy>
with eitherIgnore
(to unconditionally accept the request in the event of a failure) orFail
(to deny the failed request). UsingIgnore
can result in unpredictable behavior for all clients.
In OpenShift Container Platform 4.5, objects created by users or control loops through a mutating admission plug-in might return unexpected results, especially if values set in an initial request are overwritten, which is not recommended.
8.4.2. Validating admission plug-in
A validating admission plug-in is invoked during the validation phase of the admission process. This phase allows the enforcement of invariants on particular API resources to ensure that the resource does not change again. The Pod Node Selector is also an example of a webhook which is called by the validating admission plug-in, to ensure that all nodeSelector
fields are constrained by the node selector restrictions on the namespace.
Sample validating admission plug-in configuration
apiVersion: admissionregistration.k8s.io/v1beta1 kind: ValidatingWebhookConfiguration 1 metadata: name: <webhook_name> 2 webhooks: - name: <webhook_name> 3 clientConfig: 4 service: namespace: default 5 name: kubernetes 6 path: <webhook_url> 7 caBundle: <ca_signing_certificate> 8 rules: 9 - operations: 10 - <operation> apiGroups: - "" apiVersions: - "*" resources: - <resource> failurePolicy: <policy> 11 sideEffects: Unknown
- 1
- Specifies a validating admission plug-in configuration.
- 2
- The name for the
ValidatingWebhookConfiguration
object. Replace<webhook_name>
with the appropriate value. - 3
- The name of the webhook to call. Replace
<webhook_name>
with the appropriate value. - 4
- Information about how to connect to, trust, and send data to the webhook server.
- 5
- The namespace where the front-end service is created.
- 6
- The name of the front-end service.
- 7
- The webhook URL used for admission requests. Replace
<webhook_url>
with the appropriate value. - 8
- A PEM-encoded CA certificate that signs the server certificate that is used by the webhook server. Replace
<ca_signing_certificate>
with the appropriate certificate in base64 format. - 9
- Rules that define when the API server should use this webhook admission plug-in.
- 10
- One or more operations that trigger the API server to call this webhook admission plug-in. Possible values are
create
,update
,delete
orconnect
. Replace<operation>
and<resource>
with the appropriate values. - 11
- Specifies how the policy should proceed if the webhook server is unavailable. Replace
<policy>
with eitherIgnore
(to unconditionally accept the request in the event of a failure) orFail
(to deny the failed request). UsingIgnore
can result in unpredictable behavior for all clients.