forked from hashicorp/consul-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect-injector-disruptionbudget.bats
executable file
·193 lines (172 loc) · 6.93 KB
/
connect-injector-disruptionbudget.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/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.
#--------------------------------------------------------------------
# minAvailable
@test "connect-injector/DisruptionBudget: correct minAvailable when set" {
cd `chart_dir`
local tpl=$(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' \
--set 'connectInject.disruptionBudget.minAvailable=1' \
. | tee /dev/stderr)
[ $(echo "$tpl" | yq '.spec.minAvailable') = "1" ]
[ $(echo "$tpl" | yq '.spec.maxUnavailable') = "null" ]
}
@test "connect-injector/DisruptionBudget: correct minAvailable when set with maxUnavailable" {
cd `chart_dir`
local tpl=$(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' \
--set 'connectInject.disruptionBudget.minAvailable=1' \
--set 'connectInject.disruptionBudget.maxUnavailable=2' \
. | tee /dev/stderr)
[ $(echo "$tpl" | yq '.spec.minAvailable') = "1" ]
[ $(echo "$tpl" | yq '.spec.maxUnavailable') = "null" ]
}