-
Notifications
You must be signed in to change notification settings - Fork 17
/
run_e2e_module_upgrade_tests.sh
executable file
·230 lines (158 loc) · 10 KB
/
run_e2e_module_upgrade_tests.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
#!/usr/bin/env bash
# This script has the following arguments:
# - link to the binary image registry (required),
# - tag for the upgrade binary image (required),
# - tag for the base binary image (optional),
# ./run_e2e_module_upgrade_tests.sh europe-docker.pkg.dev/kyma-project/prod/btp-manager v1.0.0
#
# The script requires the following environment variable set - these values are used to create unique SI and SB names:
# GITHUB_RUN_ID - a unique number for each workflow run within a repository
# GITHUB_JOB - the ID of the current job from the workflow
# The script requires the following environment variables - these should be real credentials base64 encoded:
# SM_CLIENT_ID - client ID
# SM_CLIENT_SECRET - client secret
# SM_URL - service manager url
# SM_TOKEN_URL - token url
# standard bash error handling
set -o nounset # treat unset variables as an error and exit immediately.
set -o errexit # exit immediately when a command fails.
set -E # needs to be set if we want the ERR trap
set -o pipefail # prevents errors in a pipeline from being masked
[[ -z ${GITHUB_RUN_ID} ]] && echo "required variable GITHUB_RUN_ID not set" && exit 1
[[ -z ${GITHUB_JOB} ]] && echo "required variable GITHUB_JOB not set" && exit 1
REGISTRY=${1}
NEW_TAG=${2}
if [[ $# -eq 3 ]]; then
# base version explicitly stated
BASE_RELEASE=${3}
elif [[ $# -eq 2 ]]; then
# upgrade from the latest
REPOSITORY=${REPOSITORY:-kyma-project/btp-manager}
GITHUB_URL=https://api.github.com/repos/${REPOSITORY}
BASE_RELEASE=$(curl -sS "${GITHUB_URL}/releases/latest" | jq -r '.tag_name')
else
echo "wrong number of arguments" && exit 1
fi
NEW_IMAGE_REF=${REGISTRY}:${NEW_TAG}
YAML_DIR="scripts/testing/yaml"
# installing prerequisites, on production environment these are present before chart is used
kubectl apply -f ./deployments/prerequisites.yaml
# creating secret
[ -n "${SM_CLIENT_ID}" ] && [ -n "${SM_CLIENT_SECRET}" ] && [ -n "${SM_URL}" ] && [ -n "${SM_TOKEN_URL}" ] || (echo "Missing credentials - failing test" && exit 1)
envsubst <${YAML_DIR}/e2e-test-secret.yaml | kubectl apply -f -
# fetch the latest manifest and install btp-manager in current cluster
echo -e "\n--- Running base version: ${BASE_RELEASE}"
BASE_MANIFEST_FILE="btp-manager.base.yaml"
scripts/get_manifest.sh "${BASE_RELEASE}" >${BASE_MANIFEST_FILE}
if head ${BASE_MANIFEST_FILE}|grep -q "Not Found"; then
echo "::error ::Cannot get manifest for base release: ${BASE_RELEASE}" && exit 1
fi
kubectl apply -f ${BASE_MANIFEST_FILE}
rm ${BASE_MANIFEST_FILE}
# check if deployment is available
while [[ $(kubectl get deployment/btp-manager-controller-manager -n kyma-system -o 'jsonpath={..status.conditions[?(@.type=="Available")].status}') != "True" ]];
do echo -e "\n--- Waiting for deployment to be available"; sleep 5; done
echo -e "\n--- Deployment available"
echo -e "\n---Installing BTP operator"
kubectl apply -f ${YAML_DIR}/e2e-test-btpoperator.yaml
while [[ $(kubectl get btpoperators/e2e-test-btpoperator -o json| jq '.status.conditions[] | select(.type=="Ready") |.status+.reason'|xargs) != "TrueReconcileSucceeded" ]];
do echo -e "\n--- Waiting for BTP Operator to be ready and reconciled"; sleep 5; done
echo -e "\n--- BTP Operator is ready"
# verifying whether service instance and service binding crds were created
echo -e "\n--- Checking if serviceinstances and servicebindings CRDs are created"
CRDS=$(kubectl get crds|awk '/(servicebindings|serviceinstances)/{print $1}')
if [[ $(wc -w <<< ${CRDS}) -ne 2 ]]
then
echo "Missing CR definitions - failing tests"
exit 1
fi
SI_NAME=auditlog-management-si-${GITHUB_JOB}-${GITHUB_RUN_ID}
SB_NAME=auditlog-management-sb-${GITHUB_JOB}-${GITHUB_RUN_ID}
export SI_NAME
export SB_NAME
echo -e "\n--- Creating ServiceInstance: ${SI_NAME}"
envsubst <${YAML_DIR}/e2e-test-service-instance.yaml | kubectl apply -f -
echo -e "\n--- Creating ServiceBinding: ${SB_NAME}"
envsubst <${YAML_DIR}/e2e-test-service-binding.yaml | kubectl apply -f -
while [[ $(kubectl get serviceinstances.services.cloud.sap.com/${SI_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]];
do echo -e "\n--- Waiting for ServiceInstance to be ready"; sleep 5; done
echo -e "\n--- ServiceInstance is ready"
while [[ $(kubectl get servicebindings.services.cloud.sap.com/${SB_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]];
do echo -e "\n--- Waiting for ServiceBinding to be ready"; sleep 5; done
echo -e "\n--- ServiceBinding is ready"
echo -e "\n--- Upgrading the module"
echo -e "\n--- Running version: ${NEW_TAG}"
IMG=${NEW_IMAGE_REF} make deploy
# check if deployment is available
while [[ $(kubectl get deployment/btp-manager-controller-manager -n kyma-system -o 'jsonpath={..status.conditions[?(@.type=="Available")].status}') != "True" ]];
do echo -e "\n--- Waiting for deployment to be available"; sleep 5; done
echo -e "\n--- Deployment available"
while [[ $(kubectl get btpoperators/e2e-test-btpoperator -o json| jq '.status.conditions[] | select(.type=="Ready") |.status+.reason'|xargs) != "TrueReconcileSucceeded" ]];
do echo -e "\n--- Waiting for BTP Operator to be ready and reconciled"; sleep 5; done
echo -e "\n--- BTP Operator is ready"
echo -e "\n--- Checking readiness of previously created ServiceInstance and ServiceBinding"
while [[ $(kubectl get serviceinstances.services.cloud.sap.com/${SI_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]];
do echo -e "\n--- Waiting for ServiceInstance to be ready"; sleep 5; done
echo -e "\n--- ServiceInstance is ready"
while [[ $(kubectl get servicebindings.services.cloud.sap.com/${SB_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]];
do echo -e "\n--- Waiting for ServiceBinding to be ready"; sleep 5; done
echo -e "\n--- ServiceBinding is ready"
SB_NAME=auditlog-management-sb2-${GITHUB_JOB}-${GITHUB_RUN_ID}
echo -e "\n--- Creating new ServiceBinding: ${SB_NAME}"
envsubst <${YAML_DIR}/e2e-test-service-binding.yaml | kubectl apply -f -
while [[ $(kubectl get servicebindings.services.cloud.sap.com/${SB_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]];
do echo -e "\n--- Waiting for new ServiceBinding to be ready"; sleep 5; done
echo -e "\n--- New ServiceBinding is ready"
echo -e "\n--- Upgrade succeeded"
echo -e "\n--- Uninstalling..."
# remove btp-operator (ServiceInstance and ServiceBinding should be deleted as well)
kubectl delete btpoperators/e2e-test-btpoperator &
echo -e "\n--- Checking deprovisioning without force delete label"
while [[ $(kubectl get btpoperators/e2e-test-btpoperator -o json| jq '.status.conditions[] | select(.type=="Ready") |.status+.reason'|xargs) != "FalseServiceInstancesAndBindingsNotCleaned" ]];
do echo -e "\n--- Waiting for ServiceInstancesAndBindingsNotCleaned reason"; sleep 5; done
echo -e "\n--- Condition reason is correct"
echo -e "\n--- Checking if ServiceInstance still exists"
[[ "$(kubectl get serviceinstances.services.cloud.sap.com/${SI_NAME} 2>&1)" = *"Error from server (NotFound)"* ]] \
&& echo "ServiceInstance was removed when it shouldn't have been" && exit 1
echo -e "\n--- Checking if ServiceInstance is in Ready state"
[[ $(kubectl get serviceinstances.services.cloud.sap.com/${SI_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]] \
&& echo "ServiceInstance is not in Ready state" && exit 1
echo -e "\n--- ServiceInstance exists and is in Ready state"
SB_NAME=auditlog-management-sb-${GITHUB_JOB}-${GITHUB_RUN_ID}
echo -e "\n--- Checking if ServiceBinding still exists"
[[ "$(kubectl get servicebindings.services.cloud.sap.com/${SB_NAME} 2>&1)" = *"Error from server (NotFound)"* ]] \
&& echo "ServiceBinding was removed when it shouldn't have been" && exit 1
echo -e "\n--- Checking if ServiceBinding is in Ready state"
[[ $(kubectl get servicebindings.services.cloud.sap.com/${SB_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]] \
&& echo "ServiceBinding is not in Ready state" && exit 1
echo -e "\n--- ServiceBinding exists and is in Ready state"
SB_NAME=auditlog-management-sb2-${GITHUB_JOB}-${GITHUB_RUN_ID}
echo -e "\n--- Checking if new ServiceBinding still exists"
[[ "$(kubectl get servicebindings.services.cloud.sap.com/${SB_NAME} 2>&1)" = *"Error from server (NotFound)"* ]] \
&& echo "New ServiceBinding was removed when it shouldn't have been" && exit 1
echo -e "\n--- Checking if new ServiceBinding is in Ready state"
[[ $(kubectl get servicebindings.services.cloud.sap.com/${SB_NAME} -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]] \
&& echo "New ServiceBinding is not in Ready state" && exit 1
echo -e "\n--- New ServiceBinding exists and is in Ready state"
echo -e "\n--- Deprovisioning safety measures work"
echo -e "\n--- Adding force delete label"
kubectl label -f ${YAML_DIR}/e2e-test-btpoperator.yaml force-delete=true
echo -e "\n--- Checking deprovisioning with force delete label"
while [[ "$(kubectl get btpoperators/e2e-test-btpoperator 2>&1)" != *"Error from server (NotFound)"* ]];
do echo -e "\n--- Waiting for BtpOperator CR to be removed"; sleep 5; done
echo -e "\n--- BtpOperator CR has been removed"
echo -e "\n--- Checking if ServiceInstance CRD was removed"
[[ "$(kubectl get crd serviceinstances 2>&1)" != *"Error from server (NotFound)"* ]] \
&& echo "ServiceInstance CRD still exists when it should have been removed" && exit 1
echo -e "\n--- ServiceInstance CRD has been removed"
echo -e "\n--- Checking if ServiceBinding CRD was removed"
[[ "$(kubectl get crd servicebindings 2>&1)" != *"Error from server (NotFound)"* ]] \
&& echo "ServiceBinding CRD still exists when it should have been removed" && exit 1
echo -e "\n--- ServiceBinding CRD has been removed"
echo -e "\n--- BTP Operator deprovisioning succeeded"
echo -e "\n--- Uninstalling BTP Manager"
# uninstall btp-manager
make undeploy
#clean up and ignore errors
kubectl delete -f ./examples/btp-manager-secret.yaml || echo "ignoring failure during secret removal"
kubectl delete -f ./deployments/prerequisites.yaml || echo "ignoring failure during prerequisites removal"