2019-12-19 15:57:51 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load _helpers
|
|
|
|
|
|
|
|
@test "injector/MutatingWebhookConfiguration: enabled by default" {
|
|
|
|
cd `chart_dir`
|
|
|
|
local actual=$(helm template \
|
2020-02-06 16:44:38 +00:00
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
2019-12-19 15:57:51 +00:00
|
|
|
. | tee /dev/stderr |
|
|
|
|
yq 'length > 0' | tee /dev/stderr)
|
|
|
|
[ "${actual}" = "true" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "injector/MutatingWebhookConfiguration: disable with global.enabled false" {
|
|
|
|
cd `chart_dir`
|
2020-02-06 16:44:38 +00:00
|
|
|
local actual=$( (helm template \
|
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
2019-12-19 15:57:51 +00:00
|
|
|
--set 'global.enabled=false' \
|
2020-02-06 16:44:38 +00:00
|
|
|
. || echo "---") | tee /dev/stderr |
|
2019-12-19 15:57:51 +00:00
|
|
|
yq 'length > 0' | tee /dev/stderr)
|
|
|
|
[ "${actual}" = "false" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "injector/MutatingWebhookConfiguration: disable with injector.enabled false" {
|
|
|
|
cd `chart_dir`
|
2020-02-06 16:44:38 +00:00
|
|
|
local actual=$( (helm template \
|
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
2019-12-19 15:57:51 +00:00
|
|
|
--set 'injector.enabled=false' \
|
2020-02-06 16:44:38 +00:00
|
|
|
. || echo "---") | tee /dev/stderr |
|
2019-12-19 15:57:51 +00:00
|
|
|
yq 'length > 0' | tee /dev/stderr)
|
|
|
|
[ "${actual}" = "false" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "injector/MutatingWebhookConfiguration: namespace is set" {
|
|
|
|
cd `chart_dir`
|
|
|
|
local actual=$(helm template \
|
2020-02-06 16:44:38 +00:00
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
2019-12-19 15:57:51 +00:00
|
|
|
--set 'injector.enabled=true' \
|
|
|
|
--namespace foo \
|
|
|
|
. | tee /dev/stderr |
|
|
|
|
yq '.webhooks[0].clientConfig.service.namespace' | tee /dev/stderr)
|
|
|
|
[ "${actual}" = "\"foo\"" ]
|
|
|
|
}
|
|
|
|
|
2020-07-14 13:53:33 +00:00
|
|
|
@test "injector/MutatingWebhookConfiguration: caBundle is empty string" {
|
2019-12-19 15:57:51 +00:00
|
|
|
cd `chart_dir`
|
|
|
|
local actual=$(helm template \
|
2020-02-06 16:44:38 +00:00
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
2019-12-19 15:57:51 +00:00
|
|
|
--set 'injector.enabled=true' \
|
|
|
|
--namespace foo \
|
|
|
|
. | tee /dev/stderr |
|
|
|
|
yq '.webhooks[0].clientConfig.caBundle' | tee /dev/stderr)
|
2020-07-14 13:53:33 +00:00
|
|
|
[ "${actual}" = "\"\"" ]
|
2019-12-19 15:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "injector/MutatingWebhookConfiguration: namespaceSelector empty by default" {
|
|
|
|
cd `chart_dir`
|
|
|
|
local actual=$(helm template \
|
2020-02-06 16:44:38 +00:00
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
2019-12-19 15:57:51 +00:00
|
|
|
--set 'injector.enabled=true' \
|
|
|
|
--namespace foo \
|
|
|
|
. | tee /dev/stderr |
|
|
|
|
yq '.webhooks[0].namespaceSelector' | tee /dev/stderr)
|
|
|
|
[ "${actual}" = "null" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "injector/MutatingWebhookConfiguration: can set namespaceSelector" {
|
|
|
|
cd `chart_dir`
|
|
|
|
local actual=$(helm template \
|
2020-02-06 16:44:38 +00:00
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
2019-12-19 15:57:51 +00:00
|
|
|
--set 'injector.enabled=true' \
|
|
|
|
--set 'injector.namespaceSelector.matchLabels.injector=true' \
|
|
|
|
. | tee /dev/stderr |
|
|
|
|
yq '.webhooks[0].namespaceSelector.matchLabels.injector' | tee /dev/stderr)
|
|
|
|
|
|
|
|
[ "${actual}" = "true" ]
|
|
|
|
}
|
2020-10-13 13:20:06 +00:00
|
|
|
|
2021-02-20 04:02:04 +00:00
|
|
|
@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" ]
|
|
|
|
}
|
|
|
|
|
2020-12-07 15:18:25 +00:00
|
|
|
@test "injector/MutatingWebhookConfiguration: failurePolicy 'Ignore' by default" {
|
2020-10-13 13:20:06 +00:00
|
|
|
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].failurePolicy' | tee /dev/stderr)
|
2020-12-07 15:18:25 +00:00
|
|
|
[ "${actual}" = "\"Ignore\"" ]
|
2020-10-13 13:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "injector/MutatingWebhookConfiguration: can set failurePolicy" {
|
|
|
|
cd `chart_dir`
|
|
|
|
local actual=$(helm template \
|
|
|
|
--show-only templates/injector-mutating-webhook.yaml \
|
|
|
|
--set 'injector.enabled=true' \
|
|
|
|
--set 'injector.failurePolicy=Fail' \
|
|
|
|
. | tee /dev/stderr |
|
|
|
|
yq '.webhooks[0].failurePolicy' | tee /dev/stderr)
|
|
|
|
|
|
|
|
[ "${actual}" = "\"Fail\"" ]
|
|
|
|
}
|