Commit 132e6c9f authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '53812-review-apps-check-whether-release-exists-before-attempting-stop_review' into 'master'

Ensure we abort the cleanup if release is empty

Closes #53812

See merge request gitlab-org/gitlab-ce!22992
parents fc776063 4383c794
...@@ -179,20 +179,34 @@ function delete() { ...@@ -179,20 +179,34 @@ function delete() {
track="${1-stable}" track="${1-stable}"
name="$CI_ENVIRONMENT_SLUG" name="$CI_ENVIRONMENT_SLUG"
if [ -z "$CI_ENVIRONMENT_SLUG" ]; then
echo "No release given, aborting the delete!"
return
fi
if [[ "$track" != "stable" ]]; then if [[ "$track" != "stable" ]]; then
name="$name-$track" name="$name-$track"
fi fi
if ! deployExists "${KUBE_NAMESPACE}" "${name}"; then
echo "The release $name doesn't exist, aborting the cleanup!"
return
fi
echo "Deleting release '$name'..." echo "Deleting release '$name'..."
helm delete --purge "$name" || true helm delete --purge "$name" || true
} }
function cleanup() { function cleanup() {
echo "Cleaning up $CI_ENVIRONMENT_SLUG..." if [ -z "$CI_ENVIRONMENT_SLUG" ]; then
kubectl -n "$KUBE_NAMESPACE" get ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa 2>&1 \ echo "No release given, aborting the delete!"
| grep "$CI_ENVIRONMENT_SLUG" \ return
| awk '{print $1}' \ fi
| xargs kubectl -n "$KUBE_NAMESPACE" delete \
echo "Cleaning up '$CI_ENVIRONMENT_SLUG'..."
kubectl -n "$KUBE_NAMESPACE" delete \
ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa \
-l release="$CI_ENVIRONMENT_SLUG" \
|| true || true
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment