Selectors
Selectors can be used to limit which requests can be intercepted by the webhook based on the labels. Two types of selectors can be specified in MutatingWebhookConfiguration i.e. ObjectSelector and NamespaceSelector.
Both ObjectSelector and NamespaceSelector can use matchLabels and matchExpressions to specify the selectors. You can check working with kubernetes objects and labels for more details.
ObjectSelector
ObjectSelector
is used to specify the label based selectors for the objects (pod) for which the requests are required to be intercepted.
Example: Using matchLabels, objectSelector can be specified as follows:
objectSelector:
matchLabels:
tier: backend
With this selectors the requests for objects (pod) with label tier = backend will be intercepted.
Using matchExpressions, objectSelector can be specified as follows:
objectSelector:
matchExpressions:
- key: tier
operator: In
values: ["frontend","backend"]
With this selectors the requests for objects (pod) with label tier = backend or tier = frontend will be intercepted.
NamespaceSelector
NamespaceSelector
is used to specify the label based selectors for the namespaces.
Example: Using matchLabels, namespaceSelector can be specified as follows:
namespaceSelector:
matchLabels:
environment: development
With this selectors the requests for objects (pods) with label tier = backend will be intercepted.
Using matchExpressions, namespaceSelector can be specified as follows:
namespaceSelector:
matchExpressions:
- key: tier
operator: In
values: ["development","staging"]
Note: If you have configured selectors i.e.
Object selector
&Namespace selector
while deploying theLM-K8s-Webhook
, then you need to make sure that your pods and corresponding namespace satisfy the configured selectors.
- You can check the examples page to get an idea of using these selectors.