Skip to content

Commit 63d7669

Browse files
committed
Fixed cleaning up namespaces in openshift
1 parent d237fe7 commit 63d7669

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

scripts/evergreen/e2e/e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ echo "TEST_NAME is set to: ${TEST_NAME}"
123123

124124
delete_operator "${NAMESPACE}"
125125

126-
# We'll have the task running for the alloca ted time, minus the time it took us
126+
# We'll have the task running for the allocated time, minus the time it took us
127127
# to get all the way here, assuming configuring and deploying the operator can
128128
# take a bit of time. This is needed because Evergreen kills the process *AND*
129129
# Docker containers running on the host when it hits a timeout. Under these

scripts/funcs/kubernetes

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ create_image_registries_secret() {
9898
context=$1
9999
namespace=$2
100100
secret_name=$3
101-
101+
102102
# Detect the correct config file path based on container runtime
103103
local config_file
104104
local temp_config_file=""
105105
if command -v podman &> /dev/null && (podman info &> /dev/null || sudo podman info &> /dev/null); then
106106
# For Podman, use root's auth.json since minikube uses sudo podman
107107
config_file="/root/.config/containers/auth.json"
108108
echo "Using Podman config: ${config_file}"
109-
109+
110110
# Create a temporary copy that the current user can read
111111
temp_config_file=$(mktemp)
112112
sudo cp "${config_file}" "${temp_config_file}"
@@ -117,7 +117,7 @@ create_image_registries_secret() {
117117
config_file="${HOME}/.docker/config.json"
118118
echo "Using Docker config: ${config_file}"
119119
fi
120-
120+
121121
# shellcheck disable=SC2154
122122
if kubectl --context "${context}" get namespace "${namespace}"; then
123123
kubectl --context "${context}" -n "${namespace}" delete secret "${secret_name}" --ignore-not-found
@@ -127,7 +127,7 @@ create_image_registries_secret() {
127127
else
128128
echo "Skipping creating pull secret in ${context}/${namespace}. The namespace doesn't exist yet."
129129
fi
130-
130+
131131
# Clean up temporary file
132132
if [[ -n "${temp_config_file}" ]] && [[ -f "${temp_config_file}" ]]; then
133133
rm -f "${temp_config_file}"
@@ -156,6 +156,26 @@ create_image_registries_secret() {
156156
fi
157157
}
158158

159+
force_delete_all_resources_from_namespace() {
160+
resource_type="$1"
161+
namespace="$2"
162+
163+
echo "Attempting normal deletion of ${resource_type} in ${namespace}..."
164+
kubectl delete "${resource_type}" --all -n "${namespace}" --wait=true --timeout=10s || true
165+
166+
# Check if any resources are still stuck
167+
echo "Checking if any resources are still stuck:"
168+
kubectl get "${resource_type}" -n "${namespace}" --no-headers -o custom-columns=":metadata.name" || true
169+
resources=$(kubectl get "${resource_type}" -n "${namespace}" --no-headers -o custom-columns=":metadata.name" 2>/dev/null || true)
170+
171+
for resource in ${resources}; do
172+
echo "${resource_type}/${resource} is still present, force deleting..."
173+
174+
kubectl patch "${resource_type}" "${resource}" -n "${namespace}" -p '{"metadata":{"finalizers":null}}' --type=merge || true
175+
kubectl delete "${resource_type}" "${resource}" -n "${namespace}" --force --grace-period=0 || true
176+
done
177+
}
178+
159179
reset_namespace() {
160180
context=$1
161181
namespace=$2
@@ -166,19 +186,23 @@ reset_namespace() {
166186

167187
set +e
168188

169-
helm uninstall --kube-context="${context}" mongodb-kubernetes-operator || true &
170-
helm uninstall --kube-context="${context}" mongodb-kubernetes-operator-multi-cluster || true &
171-
172189
# Cleans the namespace. Note, that fine-grained cleanup is performed instead of just deleting the namespace as it takes
173190
# considerably less time
174191
title "Cleaning Kubernetes resources in context: ${context}"
175192

176193
ensure_namespace "${namespace}"
177194

178-
kubectl delete --context "${context}" mdb --all -n "${namespace}" || true
179-
kubectl delete --context "${context}" mdbu --all -n "${namespace}" || true
180-
kubectl delete --context "${context}" mdbmc --all -n "${namespace}" || true
181-
kubectl delete --context "${context}" om --all -n "${namespace}" || true
195+
force_delete_all_resources_from_namespace "mdb" "${namespace}"
196+
force_delete_all_resources_from_namespace "mdbu" "${namespace}"
197+
force_delete_all_resources_from_namespace "mdbc" "${namespace}"
198+
force_delete_all_resources_from_namespace "mdbmc" "${namespace}"
199+
force_delete_all_resources_from_namespace "om" "${namespace}"
200+
force_delete_all_resources_from_namespace "clustermongodbroles" "${namespace}"
201+
202+
echo "Sleeping to allow the operator to perform cleanups"
203+
sleep 10
204+
helm uninstall --kube-context="${context}" mongodb-kubernetes-operator || true &
205+
helm uninstall --kube-context="${context}" mongodb-kubernetes-operator-multi-cluster || true &
182206

183207
# Openshift variant runs all tests sequentially. In order to avoid clashes between tests, we need to wait till
184208
# the namespace is gone. This trigger OpenShift Project deletion, which is a "Namespace on Steroids" and it takes

0 commit comments

Comments
 (0)