Commit 87bcd283 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason
Browse files

Merge branch 'pass-old_postgres_enabled-to-scale' into 'master'

Fix: `scale` creates legacy PostgreSQL regardless of the current channel

See merge request gitlab-org/cluster-integration/auto-deploy-image!126
parents 115197a7 d2db2e77
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ publish-dryrun:
  script:
    - semantic-release -d |tee output.log
    # Check if the bundled chart version matches the next auto-deploy-image version.
    - git diff @..@^ --name-only | grep 'assets/auto-deploy-app' || echo 'This change does not contain changes for the chart. Skip the validation' && exit 0
    - next_release_version=$(cat output.log | grep -oP "The next release version is \K.*$") || true
    - bundled_chart_version=$(cat assets/auto-deploy-app/Chart.yaml | grep -oP "version:\s*\K.*$")
    - echo "next_release_version is $next_release_version"
+29 −0
Original line number Diff line number Diff line
@@ -332,6 +332,35 @@ test-deploy-postgresql-channel-1:
    - helm get values production --output json | grep "postgres://user:testing-password@production-postgres:5432/production"
    - ./test/verify-deployment-database production production-postgres

test-scale-does-not-create-old-postgres:
  extends: test-deploy
  script:
    - auto-deploy initialize_tiller
    - auto-deploy download_chart
    - auto-deploy deploy
    - auto-deploy scale
    - exist=$(auto-deploy check_old_postgres_exist)
    - |
      if [[ "$exist" != "false" ]]; then
        echo "Old Postgres should not exist"
        exit 1
      fi

test-scale-does-not-delete-old-postgres:
  extends: test-deploy
  script:
    - export AUTO_DEVOPS_POSTGRES_CHANNEL=1
    - auto-deploy initialize_tiller
    - auto-deploy download_chart
    - auto-deploy deploy
    - auto-deploy scale
    - exist=$(auto-deploy check_old_postgres_exist)
    - |
      if [[ "$exist" != "true" ]]; then
        echo "Old Postgres should exist"
        exit 1
      fi

test-deploy-does-not-delete-old-postgres-by-default:
  extends: test-deploy
  script:
+25 −0
Original line number Diff line number Diff line
@@ -406,10 +406,18 @@ function scale() {
  local replicas
  replicas=$(get_replicas "$track" "$percentage")

  # NOTE: This is a patch for Helm2 that `--reuse-values` option is not respected
  # in the subchart. This causes a problem that `scale` always creates legacy PostgreSQL
  # instance even if it's unnecessary.
  # See more https://gitlab.com/gitlab-org/gitlab/-/issues/209045#note_422968926
  local old_postgres_enabled
  old_postgres_enabled=$(check_old_postgres_exist)

  if [[ -n "$(helm ls -q "^$name$")" ]]; then
    helm upgrade --reuse-values \
      --wait \
      --set replicaCount="$replicas" \
      --set postgresql.enabled="$old_postgres_enabled" \
      --namespace="$KUBE_NAMESPACE" \
      "$name" \
      chart/
@@ -500,6 +508,22 @@ function deploy_name() {
  echo $name
}

# In the past, we're creating postgres instance via the auto-deploy-app chart (see requirements.yaml),
# these instances called old postgreses in Auto Deploy context.
# This approach was discontinued in favor of new postgres installation as channel 2.
function check_old_postgres_exist() {
  local stable_name
  stable_name=$(deploy_name stable)

  value=$( (helm get values --output json "$stable_name" || echo '{}') | jq '.postgresql.enabled')

  if [[ "$value" == "true" ]]; then
    echo "true"
  else
    echo "false"
  fi
}

# shellcheck disable=SC2086 # double quote to prevent globbing
# shellcheck disable=SC2153 # incorrectly thinks replicas vs REPLICAS is a misspelling
function get_replicas() {
@@ -561,5 +585,6 @@ case $option in
  create_application_secret) create_application_secret "${@:2}" ;;
  deploy_name) deploy_name "${@:2}" ;;
  get_replicas) get_replicas "${@:2}" ;;
  check_old_postgres_exist) check_old_postgres_exist ;;
  *) exit 1 ;;
esac