Skip to content

Commit

Permalink
Add objectSelector to webhookconfiguration (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
guru1306 authored Feb 20, 2021
1 parent 84a1dd9 commit 690ee41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions templates/injector-mutating-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ webhooks:
namespaceSelector:
{{ toYaml .Values.injector.namespaceSelector | indent 6}}
{{ end }}
{{- if .Values.injector.objectSelector }}
objectSelector:
{{ toYaml .Values.injector.objectSelector | indent 6}}
{{ end }}
{{- with .Values.injector.failurePolicy }}
failurePolicy: {{.}}
{{ end }}
Expand Down
23 changes: 23 additions & 0 deletions test/unit/injector-mutating-webhook.bats
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "injector/MutatingWebhookConfiguration: objectSelector empty by default" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/injector-mutating-webhook.yaml \
--set 'injector.enabled=true' \
--namespace foo \
. | tee /dev/stderr |
yq '.webhooks[0].objectSelector' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "injector/MutatingWebhookConfiguration: can set objectSelector" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/injector-mutating-webhook.yaml \
--set 'injector.enabled=true' \
--set 'injector.objectSelector.matchLabels.injector=true' \
. | tee /dev/stderr |
yq '.webhooks[0].objectSelector.matchLabels.injector' | tee /dev/stderr)

[ "${actual}" = "true" ]
}

@test "injector/MutatingWebhookConfiguration: failurePolicy 'Ignore' by default" {
cd `chart_dir`
local actual=$(helm template \
Expand Down
9 changes: 9 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ injector:
# matchLabels:
# sidecar-injector: enabled
namespaceSelector: {}
# objectSelector is the selector for restricting the webhook to only
# specific labels.
# See https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#matching-requests-objectselector
# for more details.
# Example:
# objectSelector:
# matchLabels:
# vault-sidecar-injector: enabled
objectSelector: {}

# Configures failurePolicy of the webhook. The "unspecified" default behaviour deoends on the
# API Version of the WebHook.
Expand Down

0 comments on commit 690ee41

Please sign in to comment.