-
Notifications
You must be signed in to change notification settings - Fork 7
/
alias-test.sh
executable file
·253 lines (225 loc) · 11.5 KB
/
alias-test.sh
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
print_error() {
printf "\033[1;31m%s\033[0m\n" "$1"
}
print_success() {
printf "\033[1;32m%s\033[0m\n" "$1"
}
test_number=1
echo
echo "---------------------------------------------"
echo " ALIAS TESTS"
echo "---------------------------------------------"
alias k='labeler kubectl'
alias h='labeler helm'
echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'creator' annotation, in default namespace, no --overwrite ---"
echo "k apply -f ../examples/kubectl/pass --l-annotation=creator='John Doe' --context=kind-kind --namespace=default"
if ! k apply -f ../examples/kubectl/pass --l-annotation=creator='John Doe' --context=kind-kind --namespace=default; then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'creator' annotation, in default namespace, with --overwrite ---"
echo "k apply -f ../examples/kubectl/pass --l-annotation=creator='Jane Doe' --context=kind-kind --namespace=default --overwrite"
if ! k apply -f ../examples/kubectl/pass --l-annotation=creator='Jane Doe' --context=kind-kind --namespace=default --overwrite; then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'creator' AND 'description' annotation (multi-annotation), in default namespace, with --overwrite ---"
echo "k apply -f ../examples/kubectl/pass --l-annotation=creator='John Doe',description='testing 123' --context=kind-kind --namespace=default --overwrite"
if ! k apply -f ../examples/kubectl/pass --l-annotation=creator='John Doe',description='testing 123' --context=kind-kind --namespace=default --overwrite; then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'sample' label, in default namespace, no --overwrite ---"
echo "k apply -f ../examples/kubectl/pass -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default"
if ! k apply -f ../examples/kubectl/pass -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default; then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'sample' label, in default namespace, with --overwrite ---"
echo "k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite"
if ! k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite; then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'sample' label, in temp namespace, with --overwrite ---"
k create namespace temp
echo "k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=temp --overwrite"
if ! k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=temp --overwrite; then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'sample' label, temp namespace, without --overwrite ---"
echo "k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=temp"
if ! k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=temp;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize alias with 'sample-app' label, default namespace, without --overwrite ---"
echo "k apply -k ../examples/kustomize --label=app.kubernetes.io/part-of=sample-app --context=kind-kind --namespace=default"
if ! k apply -k ../examples/kustomize --label=app.kubernetes.io/part-of=sample-app --context=kind-kind --namespace=default;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize alias with 'sample-app' label, default namespace, without --overwrite ---"
echo "k apply -k ../examples/kustomize --label=app.kubernetes.io/part-of=sample-app --context=kind-kind --namespace=default"
if ! k apply -k ../examples/kustomize --label=app.kubernetes.io/part-of=sample-app --context=kind-kind --namespace=default;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize alias with 'sample' label with --overwrite ---"
echo "k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=temp --overwrite"
if ! k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=temp --overwrite;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- helm alias template mode with --create-namespace and --dry-run and 'sample-app' label ---"
echo "h --kube-context=kind-kind template sealed-secrets sealed-secrets/sealed-secrets -n sealed-secrets --create-namespace --label=app.kubernetes.io/part-of=sample-app --dry-run"
if ! h --kube-context=kind-kind template sealed-secrets sealed-secrets/sealed-secrets -n sealed-secrets --create-namespace --label=app.kubernetes.io/part-of=sample-app --dry-run;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
h --kube-context=kind-kind uninstall sealed-secrets -n sealed-secrets
echo
echo "---------------------------------------------"
echo "--- helm alias insall mode with --create-namespace and --dry-run and 'sample-app' label ---"
echo "h --kube-context=kind-kind install sealed-secrets sealed-secrets/sealed-secrets -n sealed-secrets --create-namespace --label=app.kubernetes.io/part-of=sample-app --dry-run"
if ! h --kube-context=kind-kind install sealed-secrets sealed-secrets/sealed-secrets -n sealed-secrets --create-namespace --label=app.kubernetes.io/part-of=sample-app --dry-run;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
helm --kube-context=kind-kind uninstall sealed-secrets -n sealed-secrets
echo
echo "---------------------------------------------"
echo "--- helm alias install mode with --create-namespace and 'sample-app' label ---"
echo "h --kube-context=kind-kind install sealed-secrets sealed-secrets/sealed-secrets -n sealed-secrets --create-namespace --label=app.kubernetes.io/part-of=sample-app"
if ! h --kube-context=kind-kind install sealed-secrets sealed-secrets/sealed-secrets -n sealed-secrets --create-namespace --label=app.kubernetes.io/part-of=sample-app;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
helm --kube-context=kind-kind uninstall sealed-secrets -n sealed-secrets
echo
echo "---------------------------------------------"
echo "--- kustomize with KubeStellar bindingpolicy output ---"
echo "k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-bp-name=newbp"
if ! k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-bp-name=newbp;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize with KubeStellar bindingpolicy creation (should fail unless you have WDS1 for KubeStellar on context cluster) ---"
echo "k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-bp-name=newbp --l-bp-wds=wds1"
if ! k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-bp-name=newbp --l-bp-wds=wds1;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize with OCM manifestwork output ---"
echo "k apply -f examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-mw-name=new"
if ! k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-mw-name=new;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize with OCM manifestwork creation (should fail unless you have OCM installed on context cluster) ---"
echo "k apply -f examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-mw-name=new --l-mw-create"
if ! k apply -f ../examples/kubectl/pass --label=app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-mw-name=new --l-mw-create;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize with debug output ---"
echo "k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-debug"
if ! k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-debug;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kustomize with help output ---"
echo "k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-help"
if ! k apply -k ../examples/kustomize -l app.kubernetes.io/part-of=sample --context=kind-kind --namespace=default --overwrite --l-help;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
echo
echo "---------------------------------------------"
echo "--- kubectl log ---"
echo "k logs deployment.apps/my-app-deployment -n default --context=kind-kind"
if ! k logs deployment.apps/my-app-deployment -n default --context=kind-kind;then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))
# echo
# echo "---------------------------------------------"
# echo "--- kubectl log (followed) - works! ---"
# k logs deployment.apps/coredns -n kube-system -f
# echo
# echo "---------------------------------------------"
# echo "--- kubectl edit - works! ---"
# k edit deployment.apps/coredns -n kube-system