Skip to content

Commit 4d3463d

Browse files
committed
cleanup all
1 parent 750ce8f commit 4d3463d

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

scripts/evergreen/e2e/e2e.sh

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,42 @@ run_e2e_mco_tests() {
2828
return ${test_results}
2929
}
3030

31+
dump_cluster_information() {
32+
# Dump information from all clusters.
33+
# TODO: ensure cluster name is included in log files so there is no overwriting of cross cluster files.
34+
# shellcheck disable=SC2154
35+
if [[ "${KUBE_ENVIRONMENT_NAME:-}" = "multi" ]]; then
36+
echo "Dumping diagnostics for context ${CENTRAL_CLUSTER}"
37+
dump_all "${CENTRAL_CLUSTER}" || true
38+
39+
for member_cluster in ${MEMBER_CLUSTERS}; do
40+
echo "Dumping diagnostics for context ${member_cluster}"
41+
dump_all "${member_cluster}" || true
42+
done
43+
else
44+
# Dump all the information we can from this namespace
45+
dump_all || true
46+
fi
47+
}
48+
49+
delete_operator() {
50+
local context="${1}"
51+
timeout 5s helm uninstall --kube-context="${context}" mongodb-kubernetes-operator || true
52+
}
53+
54+
cleanup_openshift_cluster(){
55+
if [[ "${TEST_RESULTS}" -ne 0 ]]; then
56+
# Mark namespace as failed to be cleaned later
57+
kubectl label "namespace/${NAMESPACE}" "evg/state=failed" --overwrite=true
58+
59+
if [ "${ALWAYS_REMOVE_TESTING_NAMESPACE-}" = "true" ]; then
60+
# Failed namespaces might cascade into more failures if the namespaces
61+
# are not being removed soon enough.
62+
reset_namespace "$(kubectl config current-context)" "${NAMESPACE}" || true
63+
fi
64+
fi
65+
}
66+
3167
if [[ -n "${KUBECONFIG:-}" && ! -f "${KUBECONFIG}" ]]; then
3268
echo "Kube configuration: ${KUBECONFIG} file does not exist!"
3369
exit 1
@@ -102,48 +138,26 @@ else
102138
timeout --foreground "${timeout_sec}" scripts/evergreen/e2e/single_e2e.sh || TEST_RESULTS=$?
103139
fi
104140

105-
# Dump information from all clusters.
106-
# TODO: ensure cluster name is included in log files so there is no overwriting of cross cluster files.
107-
# shellcheck disable=SC2154
108-
if [[ "${KUBE_ENVIRONMENT_NAME:-}" = "multi" ]]; then
109-
echo "Dumping diagnostics for context ${CENTRAL_CLUSTER}"
110-
dump_all "${CENTRAL_CLUSTER}" || true
111-
112-
for member_cluster in ${MEMBER_CLUSTERS}; do
113-
echo "Dumping diagnostics for context ${member_cluster}"
114-
dump_all "${member_cluster}" || true
115-
done
116-
else
117-
# Dump all the information we can from this namespace
118-
dump_all || true
119-
fi
120-
121-
# we only have static cluster in openshift, otherwise there is no need to mark and clean them up here
122-
if [[ ${CLUSTER_TYPE} == "openshift" ]]; then
123-
if [[ "${TEST_RESULTS}" -ne 0 ]]; then
124-
# Mark namespace as failed to be cleaned later
125-
kubectl label "namespace/${NAMESPACE}" "evg/state=failed" --overwrite=true
141+
dump_cluster_information
126142

127-
if [ "${ALWAYS_REMOVE_TESTING_NAMESPACE-}" = "true" ]; then
128-
# Failed namespaces might cascade into more failures if the namespaces
129-
# are not being removed soon enough.
130-
reset_namespace "$(kubectl config current-context)" "${NAMESPACE}" || true
131-
fi
143+
# We only have static clusters in OpenShift; otherwise, there's no need to mark and clean them up here.
144+
if [[ "${CLUSTER_TYPE}" == "openshift" ]]; then
145+
cleanup_openshift_cluster
146+
else
147+
if [[ "${KUBE_ENVIRONMENT_NAME}" == "multi" ]]; then
148+
echo "Tearing down cluster ${CENTRAL_CLUSTER}"
149+
reset_namespace "${CENTRAL_CLUSTER}" "${NAMESPACE}" || true
150+
151+
for member_cluster in ${MEMBER_CLUSTERS}; do
152+
echo "Tearing down cluster ${member_cluster}"
153+
reset_namespace "${member_cluster}" "${NAMESPACE}" || true
154+
done
132155
else
133-
if [[ "${KUBE_ENVIRONMENT_NAME}" = "multi" ]]; then
134-
echo "Tearing down cluster ${CENTRAL_CLUSTER}"
135-
reset_namespace "${CENTRAL_CLUSTER}" "${NAMESPACE}" || true
136-
137-
for member_cluster in ${MEMBER_CLUSTERS}; do
138-
echo "Tearing down cluster ${member_cluster}"
139-
reset_namespace "${member_cluster}" "${NAMESPACE}" || true
140-
done
141-
else
142-
# If the test pass, then the namespace is removed
143-
reset_namespace "$(kubectl config current-context)" "${NAMESPACE}" || true
144-
fi
156+
# If the test passed, then the namespace is removed
157+
reset_namespace "$(kubectl config current-context)" "${NAMESPACE}" || true
145158
fi
146159
fi
147160

161+
148162
# We exit with the test result to surface status to Evergreen.
149163
exit ${TEST_RESULTS}

scripts/evergreen/teardown_kubernetes_environment.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set -Eeou pipefail
44

55
source scripts/dev/set_env_context.sh
66

7-
# Gracefully shutdown the operator to ensure we can verify graceful shutdown
8-
kubectl -n "${NAMESPACE}" scale deployment "mongodb-kubernetes-operator" --replicas=0 || true
9-
sleep 5
10-
117
if [ "${KUBE_ENVIRONMENT_NAME}" = "kind" ]; then
128
echo "Deleting Kind cluster"
139
kind delete clusters --all

scripts/funcs/kubernetes

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ reset_namespace() {
149149

150150
set +e
151151

152-
helm uninstall --kube-context="${context}" mongodb-enterprise-operator || true &
153-
helm uninstall --kube-context="${context}" mongodb-community-operator || true &
154-
helm uninstall --kube-context="${context}" mongodb-enterprise-operator-multi-cluster || true &
152+
helm uninstall --kube-context="${context}" mongodb-kubernetes-operator || true &
153+
helm uninstall --kube-context="${context}" mongodb-kubernetes-operator-multi-cluster || true &
155154

156155
# Cleans the namespace. Note, that fine-grained cleanup is performed instead of just deleting the namespace as it takes
157156
# considerably less time
@@ -169,7 +168,7 @@ reset_namespace() {
169168
# a while to delete it.
170169
should_wait="false"
171170
# shellcheck disable=SC2153
172-
if [[ ${CURRENT_VARIANT_CONTEXT} == e2e_mdb_openshift_ubi_cloudqa || ${CURRENT_VARIANT_CONTEXT} == e2e_openshift_static_mdb_ubi_cloudqa ]]; then
171+
if [[ ${KUBE_ENVIRONMENT_NAME} == "openshift" ]]; then
173172
should_wait="true"
174173
echo "Removing the test namespace ${namespace}, should_wait=${should_wait}"
175174
kubectl --context "${context}" delete "namespace/${namespace}" --wait="${should_wait}" || true

0 commit comments

Comments
 (0)