Commit 635640e3 authored by Roman Pertl's avatar Roman Pertl Committed by Shinya Maeda
Browse files

fix: allow stopping of failed and pending helm releases

parent d5d51dda
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -389,6 +389,21 @@ test-delete:
    - auto-deploy delete
    - helm get all production && expected_error || failed_as_expected

test-delete-failed:
  extends: test-deploy
  script:
    - auto-deploy download_chart
    - auto-deploy deploy
    # make sure that the helm release deployments always fails very fast
    - export HELM_UPGRADE_EXTRA_ARGS="--timeout 1s"
    - export CI_APPLICATION_REPOSITORY=this-registry-does-not-exist.test
    - export AUTO_DEVOPS_ATOMIC_RELEASE=false
    # Deployment will fail, but we wnat to continue anyway and delete the failed application
    - auto-deploy deploy || failed_as_expected
    - helm get all production
    - auto-deploy delete
    - helm get all production && expected_error || failed_as_expected

test-delete-postgresql:
  extends: test-deploy
  script:
@@ -404,6 +419,26 @@ test-delete-postgresql:
    - pvc_after_delete=$(kubectl -n $KUBE_NAMESPACE get pvc -l release=production-postgresql)
    - if [[ -n "$pvc_after_delete" ]]; then echo "no postgresql pvc should be present"; exit 1; fi

test-delete-postgresql-failed:
  extends: test-deploy
  script:
    - auto-deploy download_chart
    - auto-deploy deploy
    # make sure that the helm release deployments always fails very fast
    - export POSTGRES_HELM_UPGRADE_EXTRA_ARGS="--timeout 1s"
    - export POSTGRES_VERSION=9.99.99
    - export AUTO_DEVOPS_ATOMIC_RELEASE=false
    # Deployment will fail, but we wnat to continue anyway and delete the failed application
    - auto-deploy deploy || failed_as_expected
    - helm get all production
    - helm get all production-postgresql
    - auto-deploy delete
    - helm get all production && expected_error || failed_as_expected
    - helm get all production-postgresql && expected_error || failed_as_expected
    - pvc_after_delete=$(kubectl -n $KUBE_NAMESPACE get pvc -l release=production-postgresql)
    - if [[ -n "$pvc_after_delete" ]]; then echo "no postgresql pvc should be present"; exit 1; fi


test-delete-canary-postgresql:
  extends: test-deploy
  script:
+8 −3
Original line number Diff line number Diff line
@@ -150,6 +150,11 @@ function install_postgresql() {
    debug_flag=('--debug')
  fi

  local atomic_flag=()
  if [[ "$AUTO_DEVOPS_ATOMIC_RELEASE" != "false" ]]; then
    atomic_flag=('--atomic')
  fi

  local postgres_helm_values_args=()
  local postgres_helm_values_file=${POSTGRES_HELM_UPGRADE_VALUES_FILE:-.gitlab/auto-deploy-postgres-values.yaml}
  if [[ -f "${postgres_helm_values_file}" ]]; then
@@ -161,7 +166,7 @@ function install_postgresql() {

  # shellcheck disable=SC2086 # POSTGRES_HELM_UPGRADE_EXTRA_ARGS -- double quote variables to prevent globbing
  helm upgrade --install \
    --atomic \
    "${atomic_flag[@]}" \
    "${debug_flag[@]}" \
    --wait \
    --version 8.2.1 \
@@ -391,7 +396,7 @@ function scale() {
function delete_postgresql() {
  local name="$POSTGRESQL_RELEASE_NAME"

  if [[ -n "$(helm ls --namespace "$KUBE_NAMESPACE" -q -f "^$name$")" ]]; then
  if [[ -n "$(helm ls --namespace "$KUBE_NAMESPACE" -q -f "^$name$" --failed --pending --deployed)" ]]; then
    helm delete "$name" --namespace "$KUBE_NAMESPACE"
    kubectl delete pvc -n "$KUBE_NAMESPACE" -l "release=$POSTGRESQL_RELEASE_NAME"
  fi
@@ -403,7 +408,7 @@ function delete() {
  local name
  name=$(deploy_name "$track")

  if [[ -n "$(helm ls --namespace "$KUBE_NAMESPACE" -q -f "^$name$")" ]]; then
  if [[ -n "$(helm ls --namespace "$KUBE_NAMESPACE" -q -f "^$name$" --failed --pending --deployed)" ]]; then
    helm delete "$name" --namespace "$KUBE_NAMESPACE"
  fi