-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding podDistruptionBudget to connect injector (#1316)
* Adding podDistruptionBudget to connect injector
- Loading branch information
Showing
4 changed files
with
217 additions
and
0 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
26 changes: 26 additions & 0 deletions
26
charts/consul/templates/connect-injector-disruptionbudget.yaml
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,26 @@ | ||
{{- if (and .Values.connectInject.disruptionBudget.enabled (or (and (ne (.Values.connectInject.enabled | toString) "-") .Values.connectInject.enabled) (and (eq (.Values.connectInject.enabled | toString) "-") .Values.global.enabled))) }} | ||
# PodDisruptionBudget to prevent degrading the connectInject cluster through | ||
# voluntary cluster changes. | ||
{{- if .Capabilities.APIVersions.Has "policy/v1/PodDisruptionBudget" }} | ||
apiVersion: policy/v1 | ||
{{- else }} | ||
apiVersion: policy/v1beta1 | ||
{{- end }} | ||
kind: PodDisruptionBudget | ||
metadata: | ||
name: {{ template "consul.fullname" . }}-connect-injector | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
component: connect-injector | ||
spec: | ||
maxUnavailable: {{ template "consul.pdb.connectInject.maxUnavailable" . }} | ||
selector: | ||
matchLabels: | ||
app: {{ template "consul.name" . }} | ||
release: "{{ .Release.Name }}" | ||
component: connect-injector | ||
{{- end }} |
161 changes: 161 additions & 0 deletions
161
charts/consul/test/unit/connect-injector-disruptionbudget.bats
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,161 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "connect-injector/DisruptionBudget: disabled by default" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml . | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: enabled with connectInject=enabled , connectInject.disruptionBudget.enabled=true and global.enabled=true " { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: disabled with connectInject.enabled=false" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.enabled=false' \ | ||
. | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: disabled with connectInject.disruptionBudget.enabled=false" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.disruptionBudget.enabled=false' \ | ||
. | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: disabled with global.enabled=false" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'global.enabled=false' \ | ||
. | ||
} | ||
|
||
#-------------------------------------------------------------------- | ||
# maxUnavailable | ||
|
||
@test "connect-injector/DisruptionBudget: correct maxUnavailable with replicas=1" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.replicas=1' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq '.spec.maxUnavailable' | tee /dev/stderr) | ||
[ "${actual}" = "0" ] | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: correct maxUnavailable with replicas=3" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.replicas=3' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq '.spec.maxUnavailable' | tee /dev/stderr) | ||
[ "${actual}" = "1" ] | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: correct maxUnavailable with replicas=4" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.replicas=4' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq '.spec.maxUnavailable' | tee /dev/stderr) | ||
[ "${actual}" = "1" ] | ||
} | ||
|
||
|
||
@test "connect-injector/DisruptionBudget: correct maxUnavailable with replicas=5" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.replicas=5' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq '.spec.maxUnavailable' | tee /dev/stderr) | ||
[ "${actual}" = "1" ] | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: correct maxUnavailable with replicas=6" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.replicas=6' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq '.spec.maxUnavailable' | tee /dev/stderr) | ||
[ "${actual}" = "2" ] | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: correct maxUnavailable with replicas=7" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.replicas=7' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq '.spec.maxUnavailable' | tee /dev/stderr) | ||
[ "${actual}" = "2" ] | ||
} | ||
|
||
@test "connect-injector/DisruptionBudget: correct maxUnavailable with replicas=8" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--set 'connectInject.replicas=8' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq '.spec.maxUnavailable' | tee /dev/stderr) | ||
[ "${actual}" = "3" ] | ||
} | ||
|
||
#-------------------------------------------------------------------- | ||
# apiVersion | ||
|
||
@test "connect-injector/DisruptionBudget: uses policy/v1 if supported" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/connect-injector-disruptionbudget.yaml \ | ||
--api-versions 'policy/v1/PodDisruptionBudget' \ | ||
--set 'global.enabled=true' \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.disruptionBudget.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.apiVersion' | tee /dev/stderr) | ||
[ "${actual}" = "policy/v1" ] | ||
} | ||
# NOTE: can't test that it uses policy/v1beta1 if policy/v1 is *not* supported | ||
# because the supported API versions depends on the Helm version and there's | ||
# no flag to *remove* an API version so some Helm versions will always have | ||
# policy/v1 support and will always use that API version. | ||
|
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