Commit ec15b0e9 authored by Thong Kuah's avatar Thong Kuah
Browse files

Merge branch 'set-default-postgres-channel-to-2' into 'master'

feat: Set AUTO_DEVOPS_POSTGRES_CHANNEL to 2 by default

See merge request gitlab-org/cluster-integration/auto-deploy-image!72
parents c76b587b 791d2dc1
Loading
Loading
Loading
Loading
+25 −17
Original line number Diff line number Diff line
@@ -90,6 +90,18 @@ test-auto_database_url:
    POSTGRES_PASSWORD: testing-password
    POSTGRES_DB: $CI_ENVIRONMENT_SLUG
  script:
    # default is channel 2
    - auto_database_url=$(auto-deploy auto_database_url)
    - export expected_url="postgres://user:testing-password@production-postgresql:5432/production"
    - |
      if [[ $auto_database_url != $expected_url ]]; then
        echo "\$auto_database_url = '${auto_database_url}', want '${expected_url}'"
        exit 1
      fi
    - export AUTO_DEVOPS_POSTGRES_CHANNEL=a
    - auto-deploy auto_database_url && expected_error || failed_as_expected
    # test that channel 1 still works
    - export AUTO_DEVOPS_POSTGRES_CHANNEL=1
    - auto_database_url=$(auto-deploy auto_database_url)
    - export expected_url="postgres://user:testing-password@production-postgres:5432/production"
    - |
@@ -97,6 +109,7 @@ test-auto_database_url:
        echo "\$auto_database_url = '${auto_database_url}', want '${expected_url}'"
        exit 1
      fi
    # test explicit channel 2 just in case
    - export AUTO_DEVOPS_POSTGRES_CHANNEL=2
    - auto_database_url=$(auto-deploy auto_database_url)
    - export expected_url="postgres://user:testing-password@production-postgresql:5432/production"
@@ -224,7 +237,6 @@ test-install-postgres:
    POSTGRES_USER: user
    POSTGRES_PASSWORD: testing-password
    POSTGRES_DB: $CI_ENVIRONMENT_SLUG
    POSTGRES_VERSION: 9.6.16
  script:
    - auto-deploy initialize_tiller
    - auto-deploy download_chart
@@ -247,15 +259,14 @@ test-deploy:
    POSTGRES_PASSWORD: testing-password
    POSTGRES_ENABLED: "true"
    POSTGRES_DB: $CI_ENVIRONMENT_SLUG
    POSTGRES_VERSION: 9.6.2
    HELM_HOST: "localhost:44134"
  script:
    - auto-deploy initialize_tiller
    - auto-deploy download_chart
    - auto-deploy deploy
    - helm get production
    - helm get values production --output json | grep "postgres://user:testing-password@production-postgres:5432/production"
    - ./test/verify-deployment-database production production-postgres
    - helm get values production --output json | grep "postgres://user:testing-password@production-postgresql:5432/production"
    - ./test/verify-deployment-database production postgresql

test-deploy-atomic:
  extends: test-deploy
@@ -284,19 +295,18 @@ test-deploy-non-atomic:
    - export KUBE_INGRESS_BASE_DOMAIN=example.com
    - auto-deploy deploy && exit 1 || echo "Second release failed as expected"

test-deploy-postgresql-beta:
test-deploy-postgresql-channel-1:
  extends: test-deploy
  variables:
    <<: *deploy-variables
    AUTO_DEVOPS_POSTGRES_CHANNEL: 2
    POSTGRES_VERSION: 9.6.16
    AUTO_DEVOPS_POSTGRES_CHANNEL: 1
  script:
    - auto-deploy initialize_tiller
    - auto-deploy download_chart
    - auto-deploy deploy
    - helm get production
    - helm get values production --output json | grep "postgres://user:testing-password@production-postgresql:5432/production"
    - ./test/verify-deployment-database production postgresql
    - helm get values production --output json | grep "postgres://user:testing-password@production-postgres:5432/production"
    - ./test/verify-deployment-database production production-postgres

test-deploy-does-not-delete-old-postgres-by-default:
  extends: test-deploy
@@ -307,9 +317,8 @@ test-deploy-does-not-delete-old-postgres-by-default:
    - export AUTO_DEVOPS_POSTGRES_CHANNEL=1
    - auto-deploy deploy
    - ./test/verify-deployment-database production production-postgres
    # test that the deploy job fails
    - export POSTGRES_VERSION='9.6.16'
    - export AUTO_DEVOPS_POSTGRES_CHANNEL=2
    # test that the deploy job fails with default channel:2
    - unset AUTO_DEVOPS_POSTGRES_CHANNEL
    - auto-deploy deploy && expected_error || failed_as_expected
    # assert that postgres still exists
    - ./test/verify-deployment-database production production-postgres
@@ -338,7 +347,6 @@ test-deploy-k8s-1.16:
      alias: k3s
  variables:
    AUTO_DEVOPS_POSTGRES_CHANNEL: 2
    POSTGRES_VERSION: 9.6.16
  before_script:
    - curl k3s:8081?service=k3s > k3s.yaml
    - export KUBECONFIG=$(pwd)/k3s.yaml
@@ -392,8 +400,8 @@ test-delete:
    - auto-deploy delete
    - helm get production && expected_error || failed_as_expected

test-delete-postgresql-beta:
  extends: test-deploy-postgresql-beta
test-delete-postgresql:
  extends: test-deploy
  script:
    - auto-deploy initialize_tiller
    - auto-deploy download_chart
@@ -404,8 +412,8 @@ test-delete-postgresql-beta:
    - helm get production && expected_error || failed_as_expected
    - helm get production-postgresql && expected_error || failed_as_expected

test-delete-canary-postgresql-beta:
  extends: test-deploy-postgresql-beta
test-delete-canary-postgresql:
  extends: test-deploy
  script:
    - auto-deploy initialize_tiller
    - auto-deploy download_chart
+29 −3
Original line number Diff line number Diff line
@@ -4,10 +4,15 @@

export TILLER_NAMESPACE=$KUBE_NAMESPACE
export HELM_HOST="localhost:44134"
export AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE=/tmp/auto-deploy-environment-values.yaml
export RELEASE_NAME=${HELM_RELEASE_NAME:-$CI_ENVIRONMENT_SLUG}
export POSTGRESQL_RELEASE_NAME="${RELEASE_NAME}-postgresql"
export AUTO_DEVOPS_POSTGRES_CHANNEL=${AUTO_DEVOPS_POSTGRES_CHANNEL:-"1"}
export AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE=/tmp/auto-deploy-environment-values.yaml
export AUTO_DEVOPS_POSTGRES_CHANNEL=${AUTO_DEVOPS_POSTGRES_CHANNEL:-"2"}
if [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "2" ]]; then
  export POSTGRES_VERSION="${POSTGRES_VERSION:-"9.6.16"}"
elif [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "1" ]]; then
  export POSTGRES_VERSION="${POSTGRES_VERSION:-"9.6.2"}"
fi

function check_kube_domain() {
  if [[ -z "$KUBE_INGRESS_BASE_DOMAIN" ]]; then
@@ -108,6 +113,12 @@ function auto_database_url() {
}

function install_postgresql() {
  if [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" != "2" ]]; then
    echo "Separate postgres chart is only supported for AUTO_DEVOPS_POSTGRES_CHANNEL:2"

    exit 1
  fi

  if [[ "$POSTGRES_VERSION" == "9.6.2" ]]; then
    echo "The minimum supported image tag for AUTO_DEVOPS_POSTGRES_CHANNEL:2 is 9.6.16"

@@ -147,7 +158,22 @@ function deploy() {
  if [[ "$POSTGRES_ENABLED" == "true" && "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "2" ]]; then
    old_postgres_already_enabled=$( (helm get values --output json "$stable_name" || echo '{}') | jq '.postgresql.enabled')
    if [[ -z "$AUTO_DEVOPS_POSTGRES_DELETE_V1" ]] && [[ "$old_postgres_already_enabled" == "true" ]]; then
      echo 'Detected an existing V1 PostgreSQL database that would have been deleted. To proceed and delete this V1 PostgreSQL database, set AUTO_DEVOPS_POSTGRES_DELETE_V1 to a non-empty value and redeploy.'
      echo 'Detected an existing PostgreSQL database installed on the
deprecated channel 1, but the current channel is set to 2. The default
channel changed to 2 in of GitLab 13.0.

- To continue using the channel 1 PostgreSQL database, set
  AUTO_DEVOPS_POSTGRES_CHANNEL to 1 and redeploy

- OR, to proceed with deleting the channel 1 PostgreSQL database
  and install a fresh channel 2 database, set AUTO_DEVOPS_POSTGRES_DELETE_V1
  to a non-empty value and redeploy.

  WARNING: This will PERMANENTLY DELETE the existing channel 1 database.

  For details on backing up your database and upgrading channels, see
  https://docs.gitlab.com/ee/topics/autodevops/upgrading_postgresql.html'

      exit 1
    fi