-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to set multiple webhooks on the same path
If we define different webhooks with the same value on the "path" field, then these webhooks will be called in sequence when the server receives a request for the given path. The resulting "accept" responses will be ANDed and the patches will be concatenated. Notice that a given webhook will see the patches from the previous webhooks already applied to the object that it must inspect.
- Loading branch information
1 parent
f81225f
commit 462df0f
Showing
5 changed files
with
112 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
request: | ||
path: /my-webhook | ||
body: | ||
apiVersion: admission.k8s.io/v1 | ||
kind: AdmissionReview | ||
request: | ||
uid: "1234" | ||
object: | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: experimental-descheduler | ||
namespace: kube-system | ||
labels: | ||
app.kubernetes.io/name: descheduler | ||
app.kubernetes.io/version: "0.27.1" | ||
|
||
webhook_config: | ||
apiVersion: generic-webhook/v1beta1 | ||
kind: GenericWebhookConfig | ||
webhooks: | ||
- name: my-webhook-1 | ||
path: /my-webhook | ||
actions: | ||
# Refuse the request if the name is "random-name" | ||
- condition: .metadata.name == "random-name" | ||
accept: false | ||
# Otherwise, accept it and add a label | ||
- accept: true | ||
patch: | ||
- op: add | ||
path: .metadata.labels | ||
value: | ||
myLabel: myValue | ||
|
||
- name: my-webhook-2 | ||
path: /my-webhook | ||
actions: | ||
# Add another label if myLabel is present. This only happens if the previous | ||
# call to my-webhook-1 went through the second action | ||
- condition: .metadata.labels.myLabel == "myValue" | ||
patch: | ||
- op: add | ||
path: .metadata.labels | ||
value: | ||
otherLabel: otherValue | ||
|
||
cases: | ||
- patches: [] | ||
expected_response: | ||
apiVersion: admission.k8s.io/v1 | ||
kind: AdmissionReview | ||
response: | ||
uid: "1234" | ||
allowed: True | ||
patchType: JSONPatch | ||
patch: | ||
- op: add | ||
path: /metadata/labels | ||
value: | ||
myLabel: myValue | ||
- op: add | ||
path: /metadata/labels | ||
value: | ||
otherLabel: otherValue | ||
|
||
- patches: | ||
- key: [request, body, request, object, metadata, name] | ||
value: random-name | ||
expected_response: | ||
apiVersion: admission.k8s.io/v1 | ||
kind: AdmissionReview | ||
response: | ||
uid: "1234" | ||
allowed: False |