Commit a470dd3e authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'fix-review-cleanup' into 'master'

ci: Require a missing file in review-cleanup

See merge request gitlab-org/gitlab!76734
parents 783ce2d8 dfa4770e
......@@ -105,4 +105,4 @@ review-stop:
stage: deploy
needs: []
script:
- delete_k8s_release_namespace
- delete_namespace
......@@ -9,12 +9,13 @@ review-cleanup:
action: stop
before_script:
- source scripts/utils.sh
- source scripts/review_apps/review-apps.sh
- source scripts/review_apps/gcp_cleanup.sh
- install_gitlab_gem
- setup_gcp_dependencies
script:
- delete_release
- delete_k8s_release_namespace
- delete_namespace
- ruby -rrubygems scripts/review_apps/automated_cleanup.rb
- gcp_cleanup
......
[[ "$TRACE" ]] && set -x
function namespace_exists() {
local namespace="${1}"
local namespace_exists
echoinfo "Checking if ${namespace} exists..." true
kubectl describe namespace "${namespace}" >/dev/null 2>&1
namespace_exists=$?
if [ $namespace_exists -eq 0 ]; then
echoinfo "Namespace ${namespace} found."
else
echoerr "Namespace ${namespace} NOT found."
fi
return $namespace_exists
}
function deploy_exists() {
local namespace="${1}"
local release="${2}"
......@@ -73,17 +91,20 @@ function delete_failed_release() {
# Cleanup and previous installs, as FAILED and PENDING_UPGRADE will cause errors with `upgrade`
if previous_deploy_failed "${namespace}" "${release}" ; then
echoinfo "Review App deployment in bad state, cleaning up namespace ${release}"
delete_k8s_release_namespace
delete_namespace
else
echoinfo "Review App deployment in good state"
fi
fi
}
function delete_k8s_release_namespace() {
function delete_namespace() {
local namespace="${CI_ENVIRONMENT_SLUG}"
kubectl delete namespace "${namespace}" --wait
if namespace_exists "${namespace}"; then
echoinfo "Deleting namespace ${namespace}..." true
kubectl delete namespace "${namespace}" --wait
fi
}
function get_pod() {
......@@ -170,9 +191,10 @@ function check_kube_domain() {
function ensure_namespace() {
local namespace="${1}"
echoinfo "Ensuring the ${namespace} namespace exists..." true
kubectl describe namespace "${namespace}" || kubectl create namespace "${namespace}"
if ! namespace_exists "${namespace}"; then
echoinfo "Creating namespace ${namespace}..." true
kubectl create namespace "${namespace}"
fi
}
function label_namespace() {
......
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