Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / openstack-cleanup-orphaned-k8s-clusters.sh
index 33fcaa6..0491334 100644 (file)
@@ -60,21 +60,12 @@ cluster_in_jenkins() {
 
 # shellcheck disable=SC1090
 source ~/lf-env.sh
-# Check if openstack venv was previously created
-if [ -f "/tmp/.os_lf_venv" ]; then
-    os_lf_venv=$(cat "/tmp/.os_lf_venv")
-fi
 
-if [ -d "${os_lf_venv}" ] && [ -f "${os_lf_venv}/bin/openstack" ]; then
-    echo "Re-use existing venv: ${os_lf_venv}"
-    PATH=$os_lf_venv/bin:$PATH
-else
-    lf-activate-venv --python python3 \
-        kubernetes \
-        python-heatclient \
-        python-openstackclient \
-        python-magnumclient
-fi
+lf-activate-venv --python python3 \
+    kubernetes \
+    python-heatclient \
+    python-openstackclient \
+    python-magnumclient
 
 #########################
 ## FETCH ACTIVE BUILDS ##
@@ -96,6 +87,11 @@ for CLUSTER_NAME in "${OS_COE_CLUSTERS[@]}"; do
     if cluster_in_jenkins "$CLUSTER_NAME" $jenkins_urls; then
         # No need to delete stacks if there exists an active build for them
         continue
+    elif [[ "$CLUSTER_NAME" == *-managed-prod-k8s-* ]] || \
+         [[ "$CLUSTER_NAME" == *-managed-test-k8s-* ]]; then
+        # Don't destroy long lived managed k8s clusters used in Jenkins jobs
+        echo "Not deleting managed cluster: $CLUSTER_NAME"
+        continue
     else
         echo "Deleting orphaned k8s cluster: $CLUSTER_NAME"
         openstack --os-cloud "$os_cloud" coe cluster delete "$CLUSTER_NAME"