@@ -5,7 +5,8 @@ load helpers
5
5
BATS_TESTS_DIR=test/bats/tests/azure
6
6
WAIT_TIME=60
7
7
SLEEP_TIME=1
8
- NAMESPACE=kube-system
8
+ NAMESPACE=default
9
+ PROVIDER_NAMESPACE=kube-system
9
10
NODE_SELECTOR_OS=linux
10
11
BASE64_FLAGS=" -w 0"
11
12
if [[ " $OSTYPE " == * " darwin" * ]]; then
@@ -38,51 +39,49 @@ setup() {
38
39
# install the azure provider using the helm charts
39
40
helm repo add csi-provider-azure https://azure.github.io/secrets-store-csi-driver-provider-azure/charts
40
41
helm repo update
41
- helm upgrade --install csi csi-provider-azure/csi-secrets-store-provider-azure --namespace $NAMESPACE \
42
+ helm upgrade --install csi csi-provider-azure/csi-secrets-store-provider-azure --namespace $PROVIDER_NAMESPACE \
42
43
--set " secrets-store-csi-driver.install=false" \
43
44
--set " windows.enabled=$TEST_WINDOWS " \
44
45
--set " logVerbosity=5" \
45
46
--set " logFormatJSON=true" \
46
47
47
48
# wait for azure-csi-provider pod to be running
48
- kubectl wait --for=condition=Ready --timeout=150s pods -l app=csi-secrets-store-provider-azure --namespace $NAMESPACE
49
+ kubectl wait --for=condition=Ready --timeout=150s pods -l app=csi-secrets-store-provider-azure --namespace $PROVIDER_NAMESPACE
49
50
}
50
51
51
52
@test " deploy azure secretproviderclass crd" {
52
- envsubst < $BATS_TESTS_DIR /azure_v1_secretproviderclass.yaml | kubectl apply -f -
53
+ envsubst < $BATS_TESTS_DIR /azure_v1_secretproviderclass.yaml | kubectl apply -n $NAMESPACE - f -
53
54
54
- kubectl wait --for condition=established --timeout=60s crd/secretproviderclasses.secrets-store.csi.x-k8s.io
55
-
56
- cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure -o yaml | grep azure"
55
+ cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure -n $NAMESPACE -o yaml | grep azure"
57
56
wait_for_process $WAIT_TIME $SLEEP_TIME " $cmd "
58
57
}
59
58
60
59
@test " CSI inline volume test with pod portability" {
61
- envsubst < $BATS_TESTS_DIR /pod-secrets-store-inline-volume-crd.yaml | kubectl apply -f -
60
+ envsubst < $BATS_TESTS_DIR /pod-secrets-store-inline-volume-crd.yaml | kubectl apply -n $NAMESPACE - f -
62
61
63
62
# The wait timeout is set to 300s only for this first pod in test to accomadate for the node-driver-registrar
64
63
# registration retries on windows nodes. Based on previous tests on windows nodes, the node-driver-registrar was
65
64
# restarted 5 times before succeeding which resulted in a wait timeout of 300s.
66
- kubectl wait --for=condition=Ready --timeout=300s pod/secrets-store-inline-crd
65
+ kubectl wait --for=condition=Ready --timeout=300s -n $NAMESPACE pod/secrets-store-inline-crd
67
66
68
- run kubectl get pod/secrets-store-inline-crd
67
+ run kubectl get pod/secrets-store-inline-crd -n $NAMESPACE
69
68
assert_success
70
69
}
71
70
72
71
@test " CSI inline volume test with pod portability - read azure kv secret from pod" {
73
- wait_for_process $WAIT_TIME $SLEEP_TIME " kubectl exec secrets-store-inline-crd -- cat /mnt/secrets-store/$SECRET_NAME | grep '${SECRET_VALUE} '"
72
+ wait_for_process $WAIT_TIME $SLEEP_TIME " kubectl exec secrets-store-inline-crd -n $NAMESPACE - - cat /mnt/secrets-store/$SECRET_NAME | grep '${SECRET_VALUE} '"
74
73
75
- result=$( kubectl exec secrets-store-inline-crd -- cat /mnt/secrets-store/$SECRET_NAME )
74
+ result=$( kubectl exec secrets-store-inline-crd -n $NAMESPACE - - cat /mnt/secrets-store/$SECRET_NAME )
76
75
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
77
76
}
78
77
79
78
@test " CSI inline volume test with pod portability - unmount succeeds" {
80
79
# On Linux a failure to unmount the tmpfs will block the pod from being
81
80
# deleted.
82
- run kubectl delete pod secrets-store-inline-crd
81
+ run kubectl delete pod secrets-store-inline-crd -n $NAMESPACE
83
82
assert_success
84
83
85
- run kubectl wait --for=delete --timeout=${WAIT_TIME} s pod/secrets-store-inline-crd
84
+ run kubectl wait --for=delete --timeout=${WAIT_TIME} s pod/secrets-store-inline-crd -n $NAMESPACE
86
85
assert_success
87
86
88
87
# Sleep to allow time for logs to propagate.
@@ -99,55 +98,53 @@ setup() {
99
98
}
100
99
101
100
@test " Sync with K8s secrets - create deployment" {
102
- envsubst < $BATS_TESTS_DIR /azure_synck8s_v1_secretproviderclass.yaml | kubectl apply -f -
103
-
104
- kubectl wait --for condition=established --timeout=60s crd/secretproviderclasses.secrets-store.csi.x-k8s.io
101
+ envsubst < $BATS_TESTS_DIR /azure_synck8s_v1_secretproviderclass.yaml | kubectl apply -n $NAMESPACE -f -
105
102
106
- cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-sync -o yaml | grep azure"
103
+ cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-sync -n $NAMESPACE - o yaml | grep azure"
107
104
wait_for_process $WAIT_TIME $SLEEP_TIME " $cmd "
108
105
109
- envsubst < $BATS_TESTS_DIR /deployment-synck8s-azure.yaml | kubectl apply -f -
110
- envsubst < $BATS_TESTS_DIR /deployment-two-synck8s-azure.yaml | kubectl apply -f -
106
+ envsubst < $BATS_TESTS_DIR /deployment-synck8s-azure.yaml | kubectl apply -n $NAMESPACE - f -
107
+ envsubst < $BATS_TESTS_DIR /deployment-two-synck8s-azure.yaml | kubectl apply -n $NAMESPACE - f -
111
108
112
- kubectl wait --for=condition=Ready --timeout=90s pod -l app=busybox
109
+ kubectl wait --for=condition=Ready --timeout=90s -n $NAMESPACE pod -l app=busybox
113
110
}
114
111
115
112
@test " Sync with K8s secrets - read secret from pod, read K8s secret, read env var, check secret ownerReferences with multiple owners" {
116
- POD=$( kubectl get pod -l app=busybox -o jsonpath=" {.items[0].metadata.name}" )
113
+ POD=$( kubectl get pod -l app=busybox -n $NAMESPACE - o jsonpath=" {.items[0].metadata.name}" )
117
114
118
- result=$( kubectl exec $POD -- cat /mnt/secrets-store/secretalias)
115
+ result=$( kubectl exec $POD -n $NAMESPACE - - cat /mnt/secrets-store/secretalias)
119
116
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
120
117
121
- result=$( kubectl get secret foosecret -o jsonpath=" {.data.username}" | base64 -d)
118
+ result=$( kubectl get secret foosecret -n $NAMESPACE - o jsonpath=" {.data.username}" | base64 -d)
122
119
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
123
120
124
- result=$( kubectl exec $POD -- printenv | grep SECRET_USERNAME) | awk -F" =" ' { print $2}'
121
+ result=$( kubectl exec $POD -n $NAMESPACE - - printenv | grep SECRET_USERNAME) | awk -F" =" ' { print $2}'
125
122
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
126
123
127
- result=$( kubectl get secret foosecret -o jsonpath=" {.metadata.labels.environment}" )
124
+ result=$( kubectl get secret foosecret -n $NAMESPACE - o jsonpath=" {.metadata.labels.environment}" )
128
125
[[ " ${result// $' \r ' } " == " ${LABEL_VALUE} " ]]
129
126
130
- result=$( kubectl get secret foosecret -o jsonpath=" {.metadata.labels.secrets-store\.csi\.k8s\.io/managed}" )
127
+ result=$( kubectl get secret foosecret -n $NAMESPACE - o jsonpath=" {.metadata.labels.secrets-store\.csi\.k8s\.io/managed}" )
131
128
[[ " ${result// $' \r ' } " == " true" ]]
132
129
133
130
run wait_for_process $WAIT_TIME $SLEEP_TIME " compare_owner_count foosecret default 2"
134
131
assert_success
135
132
}
136
133
137
134
@test " Sync with K8s secrets - delete deployment, check owner ref updated, check secret deleted" {
138
- run kubectl delete -f $BATS_TESTS_DIR /deployment-synck8s-azure.yaml
135
+ run kubectl delete -n $NAMESPACE - f $BATS_TESTS_DIR /deployment-synck8s-azure.yaml
139
136
assert_success
140
137
141
138
run wait_for_process $WAIT_TIME $SLEEP_TIME " compare_owner_count foosecret default 1"
142
139
assert_success
143
140
144
- run kubectl delete -f $BATS_TESTS_DIR /deployment-two-synck8s-azure.yaml
141
+ run kubectl delete -n $NAMESPACE - f $BATS_TESTS_DIR /deployment-two-synck8s-azure.yaml
145
142
assert_success
146
143
147
144
run wait_for_process $WAIT_TIME $SLEEP_TIME " check_secret_deleted foosecret default"
148
145
assert_success
149
146
150
- envsubst < $BATS_TESTS_DIR /azure_synck8s_v1_secretproviderclass.yaml | kubectl delete -f -
147
+ envsubst < $BATS_TESTS_DIR /azure_synck8s_v1_secretproviderclass.yaml | kubectl delete -n $NAMESPACE - f -
151
148
}
152
149
153
150
@test " Test Namespaced scope SecretProviderClass - create deployment" {
@@ -156,9 +153,7 @@ setup() {
156
153
157
154
envsubst < $BATS_TESTS_DIR /azure_v1_secretproviderclass_ns.yaml | kubectl apply -f -
158
155
159
- kubectl wait --for condition=established --timeout=60s crd/secretproviderclasses.secrets-store.csi.x-k8s.io
160
-
161
- cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-sync -o yaml | grep azure"
156
+ cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-sync -n $NAMESPACE -o yaml | grep azure"
162
157
wait_for_process $WAIT_TIME $SLEEP_TIME " $cmd "
163
158
164
159
cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-sync -n test-ns -o yaml | grep azure"
@@ -212,46 +207,44 @@ setup() {
212
207
}
213
208
214
209
@test " deploy multiple azure secretproviderclass crd" {
215
- envsubst < $BATS_TESTS_DIR /azure_v1_multiple_secretproviderclass.yaml | kubectl apply -f -
216
-
217
- kubectl wait --for condition=established --timeout=60s crd/secretproviderclasses.secrets-store.csi.x-k8s.io
210
+ envsubst < $BATS_TESTS_DIR /azure_v1_multiple_secretproviderclass.yaml | kubectl apply -n $NAMESPACE -f -
218
211
219
- cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-spc-0 -o yaml | grep azure-spc-0"
212
+ cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-spc-0 -n $NAMESPACE - o yaml | grep azure-spc-0"
220
213
wait_for_process $WAIT_TIME $SLEEP_TIME " $cmd "
221
214
222
- cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-spc-1 -o yaml | grep azure-spc-1"
215
+ cmd=" kubectl get secretproviderclasses.secrets-store.csi.x-k8s.io/azure-spc-1 -n $NAMESPACE - o yaml | grep azure-spc-1"
223
216
wait_for_process $WAIT_TIME $SLEEP_TIME " $cmd "
224
217
}
225
218
226
219
@test " deploy pod with multiple secret provider class" {
227
- envsubst < $BATS_TESTS_DIR /pod-azure-inline-volume-multiple-spc.yaml | kubectl apply -f -
220
+ envsubst < $BATS_TESTS_DIR /pod-azure-inline-volume-multiple-spc.yaml | kubectl apply -n $NAMESPACE - f -
228
221
229
- kubectl wait --for=condition=Ready --timeout=60s pod/secrets-store-inline-multiple-crd
222
+ kubectl wait --for=condition=Ready --timeout=60s pod/secrets-store-inline-multiple-crd -n $NAMESPACE
230
223
231
- run kubectl get pod/secrets-store-inline-multiple-crd
224
+ run kubectl get pod/secrets-store-inline-multiple-crd -n $NAMESPACE
232
225
assert_success
233
226
}
234
227
235
228
@test " CSI inline volume test with multiple secret provider class" {
236
- result=$( kubectl exec secrets-store-inline-multiple-crd -- cat /mnt/secrets-store-0/secretalias)
229
+ result=$( kubectl exec secrets-store-inline-multiple-crd -n $NAMESPACE - - cat /mnt/secrets-store-0/secretalias)
237
230
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
238
231
239
- result=$( kubectl exec secrets-store-inline-multiple-crd -- cat /mnt/secrets-store-1/secretalias)
232
+ result=$( kubectl exec secrets-store-inline-multiple-crd -n $NAMESPACE - - cat /mnt/secrets-store-1/secretalias)
240
233
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
241
234
242
- result=$( kubectl get secret foosecret-0 -o jsonpath=" {.data.username}" | base64 -d)
235
+ result=$( kubectl get secret foosecret-0 -n $NAMESPACE - o jsonpath=" {.data.username}" | base64 -d)
243
236
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
244
237
245
- result=$( kubectl exec secrets-store-inline-multiple-crd -- printenv | grep SECRET_USERNAME_0) | awk -F" =" ' { print $2}'
238
+ result=$( kubectl exec secrets-store-inline-multiple-crd -n $NAMESPACE - - printenv | grep SECRET_USERNAME_0) | awk -F" =" ' { print $2}'
246
239
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
247
240
248
241
run wait_for_process $WAIT_TIME $SLEEP_TIME " compare_owner_count foosecret-0 default 1"
249
242
assert_success
250
243
251
- result=$( kubectl get secret foosecret-1 -o jsonpath=" {.data.username}" | base64 -d)
244
+ result=$( kubectl get secret foosecret-1 -n $NAMESPACE - o jsonpath=" {.data.username}" | base64 -d)
252
245
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
253
246
254
- result=$( kubectl exec secrets-store-inline-multiple-crd -- printenv | grep SECRET_USERNAME_1) | awk -F" =" ' { print $2}'
247
+ result=$( kubectl exec secrets-store-inline-multiple-crd -n $NAMESPACE - - printenv | grep SECRET_USERNAME_1) | awk -F" =" ' { print $2}'
255
248
[[ " ${result// $' \r ' } " == " ${SECRET_VALUE} " ]]
256
249
257
250
run wait_for_process $WAIT_TIME $SLEEP_TIME " compare_owner_count foosecret-1 default 1"
0 commit comments