Skip to content

Commit

Permalink
Clean up stale Namespaces created by old tests before running CI
Browse files Browse the repository at this point in the history
* Add wildcard match for namespace cleanup function
* Delete potential existing namespaces created by conformance tests

Fixes antrea-io#4961

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
  • Loading branch information
XinShuYang committed Jun 2, 2023
1 parent f2fe1ac commit 92d4134
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions ci/jenkins/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,18 @@ function export_govc_env_var {

function clean_antrea {
echo "====== Cleanup Antrea Installation ======"
clean_up_one_ns "monitoring"
clean_up_one_ns "antrea-ipam-test-11"
clean_up_one_ns "antrea-ipam-test-12"
clean_up_one_ns "antrea-ipam-test"
clean_up_one_ns "antrea-test"
clean_ns "monitoring"
clean_ns "antrea-ipam-test-11"
clean_ns "antrea-ipam-test-12"
clean_ns "antrea-ipam-test"
clean_ns "antrea-test"
echo "====== Cleanup Conformance Namespaces ======"
clean_ns "net"
clean_ns "service"
clean_ns "x-"
clean_ns "y-"
clean_ns "z-"

# Delete antrea-prometheus first for k8s>=1.22 to avoid Pod stuck in Terminating state.
kubectl delete -f ${WORKDIR}/antrea-prometheus.yml --ignore-not-found=true || true
for antrea_yml in ${WORKDIR}/*.yml; do
Expand Down Expand Up @@ -287,12 +294,20 @@ function wait_for_antrea_windows_processes_ready {
done
}

function clean_up_one_ns {
function clean_ns {
ns=$1
kubectl get pod -n "${ns}" --no-headers=true | awk '{print $1}' | while read pod_name; do
kubectl delete pod "${pod_name}" -n "${ns}" --force --grace-period 0
done
kubectl delete ns "${ns}" --ignore-not-found=true || true
matching_ns=$(kubectl get ns | awk -v ns="${ns}" '$1 ~ ns {print $1}')

if [ -n "${matching_ns}" ]; then
echo "${matching_ns}" | while read -r ns_name; do
kubectl get pod -n "${ns_name}" --no-headers=true | awk '{print $1}' | while read pod_name; do
kubectl delete pod "${pod_name}" -n "${ns_name}" --force --grace-period 0
done
kubectl delete ns "${ns_name}" --ignore-not-found=true || true
done
else
echo "No matching namespaces $ns_name found."
fi
}

function prepare_env {
Expand Down Expand Up @@ -338,7 +353,7 @@ function revert_snapshot_windows {

function deliver_antrea_windows {
echo "====== Cleanup Antrea Installation Before Delivering Antrea Windows ======"
clean_up_one_ns "antrea-test"
clean_antrea
kubectl delete -f ${WORKDIR}/antrea-windows.yml --ignore-not-found=true || true
kubectl delete -f ${WORKDIR}/kube-proxy-windows.yml --ignore-not-found=true || true
kubectl delete daemonset antrea-agent -n kube-system --ignore-not-found=true || true
Expand Down Expand Up @@ -459,7 +474,7 @@ function deliver_antrea_windows {

function deliver_antrea_windows_containerd {
echo "====== Cleanup Antrea Installation Before Delivering Antrea Windows Containerd ======"
clean_up_one_ns "antrea-test"
clean_antrea
kubectl delete -f ${WORKDIR}/antrea-windows-containerd.yml --ignore-not-found=true || true
kubectl delete -f ${WORKDIR}/kube-proxy-windows-containerd.yml --ignore-not-found=true || true
kubectl delete daemonset antrea-agent -n kube-system --ignore-not-found=true || true
Expand Down Expand Up @@ -562,11 +577,11 @@ function deliver_antrea_windows_containerd {

function deliver_antrea {
echo "====== Cleanup Antrea Installation Before Delivering Antrea ======"
clean_up_one_ns "monitoring" || true
clean_up_one_ns "antrea-ipam-test-11" || true
clean_up_one_ns "antrea-ipam-test-12" || true
clean_up_one_ns "antrea-ipam-test" || true
clean_up_one_ns "antrea-test" || true
clean_ns "monitoring" || true
clean_ns "antrea-ipam-test-11" || true
clean_ns "antrea-ipam-test-12" || true
clean_ns "antrea-ipam-test" || true
clean_ns "antrea-test" || true
kubectl delete -f ${WORKDIR}/antrea-prometheus.yml || true
kubectl delete daemonset antrea-agent -n kube-system || true
kubectl delete -f ${WORKDIR}/antrea.yml || true
Expand Down

0 comments on commit 92d4134

Please sign in to comment.