diff --git a/.gitlab/ci/test.gitlab-ci.yml b/.gitlab/ci/test.gitlab-ci.yml index c26804f5abf455ed2fcf251a01462a2928acb5a5..d7d3ca6170ccac53a1a17f104fe1cf2f5702ef9e 100644 --- a/.gitlab/ci/test.gitlab-ci.yml +++ b/.gitlab/ci/test.gitlab-ci.yml @@ -94,45 +94,6 @@ test-deploy-name: exit 1 fi -test-auto_database_url: - <<: *test-job - variables: - CI_ENVIRONMENT_SLUG: production - POSTGRES_USER: user - 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" - - | - if [[ $auto_database_url != $expected_url ]]; then - 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" - - | - 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-get-replicas: <<: *test-job variables: @@ -318,49 +279,18 @@ test-deploy-debug: - auto-deploy download_chart - auto-deploy deploy -test-deploy-postgresql-channel-1: - extends: test-deploy - variables: - <<: *deploy-variables - AUTO_DEVOPS_POSTGRES_CHANNEL: 1 - script: - - auto-deploy download_chart - - auto-deploy deploy - - helm get all production - - 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: +test-show-warning-for-legacy-in-cluster-postgresql: extends: test-deploy script: + # Create a release/deployment - auto-deploy download_chart - # make sure old posgres deployment exists - - export AUTO_DEVOPS_POSTGRES_CHANNEL=1 - auto-deploy deploy - - ./test/verify-deployment-database production production-postgres - # 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 - -test-deploy-deletes-old-postgres-if-opt-in: - extends: test-deploy - variables: - AUTO_DEVOPS_DEPLOY_DEBUG: 1 - script: - - auto-deploy download_chart - - export AUTO_DEVOPS_POSTGRES_CHANNEL=1 - # make sure old postgres deployment exists - - auto-deploy deploy - - ./test/verify-deployment-database production production-postgres - # test that the deploy job succeeds - - export POSTGRES_VERSION='9.6.16' - - export AUTO_DEVOPS_POSTGRES_CHANNEL=2 - - export AUTO_DEVOPS_POSTGRES_DELETE_V1=1 - - auto-deploy deploy - # test that the new postgres is up - - ./test/verify-deployment-database production postgresql + # Forcibly update the release that a legacy in-cluster postgresql exists in it + - helm upgrade --reuse-values --wait --set postgresql.enabled="true" --namespace="$KUBE_NAMESPACE" "${CI_ENVIRONMENT_SLUG}" chart/ + - helm get values --namespace "$KUBE_NAMESPACE" --output json "${CI_ENVIRONMENT_SLUG}" + # It should see an error when the deployment is upgraded + - auto-deploy deploy| tee deploy.log || true + - grep -q "Detected an existing PostgreSQL database" deploy.log || exit 1 test-deploy-k8s-1.16: extends: test-deploy @@ -455,18 +385,12 @@ test-delete-canary-postgresql: test-chart-major-version-upgrade: extends: test-deploy - variables: - AUTO_DEVOPS_CHART_REPOSITORY: https://charts.gitlab.io - AUTO_DEVOPS_CHART_REPOSITORY_NAME: gitlab script: - - unset ADDITIONAL_HOSTS # The legacy chart is not compatible wildcard hosts on ADDITIONAL_HOSTS - auto-deploy initialize_tiller - # Downloading legacy v0 chart from charts.gitlab.io and the deployment should succeed - - AUTO_DEVOPS_CHART=gitlab/auto-deploy-app auto-deploy download_chart - - auto-deploy deploy - - rm -Rf chart - # Copying bundled chart from local storage and the deployment should fail + # Copying bundled chart from local storage and the deployment should succeed - auto-deploy download_chart + - auto-deploy deploy + # Modifying the chart version and the deployment should fail - "sed -i 's/version:.*/version: 10.0.0/g' chart/Chart.yaml" - cat chart/Chart.yaml - auto-deploy deploy| tee deploy.log || true diff --git a/assets/auto-deploy-app/Chart.yaml b/assets/auto-deploy-app/Chart.yaml index f72ad9936a55a9bc55f8b160a9b41b71293e2a1f..34de24069f608c0f49351255c6843a46fd7f3934 100644 --- a/assets/auto-deploy-app/Chart.yaml +++ b/assets/auto-deploy-app/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v1 description: GitLab's Auto-deploy Helm Chart name: auto-deploy-app -version: 2.0.0-beta.4 +version: 2.0.0-beta.5 icon: https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png diff --git a/assets/auto-deploy-app/README.md b/assets/auto-deploy-app/README.md index 33e793a0a189e0fb809241f072b387e6b1634cef..9b4af6fa652ee2a64ce7a682d12170ce3f7e1b9a 100644 --- a/assets/auto-deploy-app/README.md +++ b/assets/auto-deploy-app/README.md @@ -66,7 +66,6 @@ If you have any questions, please ask in ` | boolean | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | v1.0.0 ~ | | `AUTO_DEVOPS_ATOMIC_RELEASE` | integer | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | [v0.13.1](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.13.0...v0.13.1) ~ | | `AUTO_DEVOPS_MODSECURITY_SEC_RULE_ENGINE` | integer | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | [v0.3.0](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.2.2...v0.3.0) ~ | -| `AUTO_DEVOPS_POSTGRES_CHANNEL` | integer | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | [v0.12.0](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.11.0...v0.12.0) ~ | -| `AUTO_DEVOPS_POSTGRES_DELETE_V1` | integer | no | See [Upgrading PostgreSQL](https://docs.gitlab.com/ee/topics/autodevops/upgrading_postgresql.html). | [v0.13.3](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.13.2...v0.13.3) ~ | +| `AUTO_DEVOPS_POSTGRES_CHANNEL` | integer | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | [v0.12.0](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.11.0...v0.12.0) ~ v2.0.0 | +| `AUTO_DEVOPS_POSTGRES_DELETE_V1` | integer | no | See [Upgrading PostgreSQL](https://docs.gitlab.com/ee/topics/autodevops/upgrading_postgresql.html). | [v0.13.3](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.13.2...v0.13.3) ~ v2.0.0 | | `AUTO_DEVOPS_POSTGRES_MANAGED_CLASS_SELECTOR` | integer | no | See [Crossplane configuration](https://docs.gitlab.com/ee/user/clusters/crossplane.html). | [v0.7.0](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.6.0...v0.7.0) ~ | | `AUTO_DEVOPS_POSTGRES_MANAGED` | string | no | See [Crossplane configuration](https://docs.gitlab.com/ee/user/clusters/crossplane.html). | [v0.7.0](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.6.0...v0.7.0) ~ | | `CI_APPLICATION_REPOSITORY` | string | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | v0.1.0 ~ | diff --git a/src/bin/auto-deploy b/src/bin/auto-deploy index 513984ea24b5be3475589ea1c55242da40cb4bb5..a39cdbf2a08232c10ff2d42712bdac760785d325 100755 --- a/src/bin/auto-deploy +++ b/src/bin/auto-deploy @@ -7,12 +7,7 @@ set -e 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:-"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 +export POSTGRES_VERSION="${POSTGRES_VERSION:-"9.6.16"}" export ASSETS_DIR='/assets' export ASSETS_CHART_DIR="${ASSETS_DIR}/auto-deploy-app" @@ -128,26 +123,12 @@ function persist_environment_url() { function auto_database_url() { local auto_database_url - if [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "2" ]]; then - auto_database_url="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRESQL_RELEASE_NAME}:5432/${POSTGRES_DB}" - elif [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "1" ]]; then - auto_database_url="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${RELEASE_NAME}-postgres:5432/${POSTGRES_DB}" - else - echo "Un-recognized \$AUTO_DEVOPS_POSTGRES_CHANNEL variable '${AUTO_DEVOPS_POSTGRES_CHANNEL}'. Accepted values are '1' and '2'" - - exit 1 - fi + auto_database_url="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRESQL_RELEASE_NAME}:5432/${POSTGRES_DB}" echo "${DATABASE_URL-$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 POSTGRES_VERSION for AUTO_DEVOPS_POSTGRES_CHANNEL:2 is 9.6.16" @@ -189,10 +170,9 @@ function deploy() { stable_name=$(deploy_name stable) local old_postgres_already_enabled - local old_postgres_enabled - if [[ "$POSTGRES_ENABLED" == "true" && "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "2" ]]; then + if [[ "$POSTGRES_ENABLED" == "true" ]]; then old_postgres_already_enabled=$( (helm get values --namespace "$KUBE_NAMESPACE" --output json "$stable_name" || echo '{}') | jq '.postgresql.enabled') - if [[ -z "$AUTO_DEVOPS_POSTGRES_DELETE_V1" ]] && [[ "$old_postgres_already_enabled" == "true" ]]; then + if [[ "$old_postgres_already_enabled" == "true" ]]; then 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. @@ -214,6 +194,12 @@ release, which is controlled by the POSTGRES_ENABLED CI variable. If you are not using the in-cluster PostgreSQL database at all, you can also set the CI variable POSTGRES_ENABLED to false. +NOTE: This database migration is only supported in v1 auto-deploy-image. +If you are seeing this error message in v2 auto-deploy-image, please switch to +the v1 auto-deploy-image before proceed the above steps. +For more information, +please see https://docs.gitlab.com/ee/topics/autodevops/upgrading_auto_deploy_dependencies.html + WARNING: Setting POSTGRES_ENABLED to false will permanently delete any existing channel 1 database.' @@ -222,10 +208,6 @@ channel 1 database.' install_postgresql - # Do not install the older 0.7.1 postgresql sub-chart - old_postgres_enabled="false" - else - old_postgres_enabled="$POSTGRES_ENABLED" fi validate-chart-version "$(helm list --namespace "$KUBE_NAMESPACE" --output json)" "chart" "$name" @@ -244,16 +226,9 @@ channel 1 database.' image_tag=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG} fi - local old_postgres_enabled_for_track="$old_postgres_enabled" local postgres_managed="$AUTO_DEVOPS_POSTGRES_MANAGED" local postgres_managed_selector="$AUTO_DEVOPS_POSTGRES_MANAGED_CLASS_SELECTOR" - # if track is different than stable, - # re-use all attached resources - if [[ "$track" != "stable" ]]; then - old_postgres_enabled_for_track="false" - fi - local replicas replicas=$(get_replicas "$track") @@ -320,14 +295,8 @@ channel 1 database.' --set service.additionalHosts="$additional_hosts" \ --set replicaCount="$replicas" \ --set ingress.canary.weight="${percentage}" \ - --set postgresql.enabled="$old_postgres_enabled" \ --set postgresql.managed="$postgres_managed" \ --set postgresql.managedClassSelector="$postgres_managed_selector" \ - --set postgresql.nameOverride="postgres" \ - --set postgresql.postgresUser="$POSTGRES_USER" \ - --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ - --set postgresql.postgresDatabase="$POSTGRES_DB" \ - --set postgresql.imageTag="$POSTGRES_VERSION" \ --set application.initializeCommand="$DB_INITIALIZE" \ "${modsecurity_set_args[@]}" \ --values "$AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE" \ @@ -360,14 +329,8 @@ channel 1 database.' --set service.additionalHosts="$additional_hosts" \ --set replicaCount="$replicas" \ --set ingress.canary.weight="${percentage}" \ - --set postgresql.enabled="$old_postgres_enabled_for_track" \ --set postgresql.managed="$postgres_managed" \ --set postgresql.managedClassSelector="$postgres_managed_selector" \ - --set postgresql.nameOverride="postgres" \ - --set postgresql.postgresUser="$POSTGRES_USER" \ - --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ - --set postgresql.postgresDatabase="$POSTGRES_DB" \ - --set postgresql.imageTag="$POSTGRES_VERSION" \ --set application.initializeCommand="" \ --set application.migrateCommand="$DB_MIGRATE" \ "${modsecurity_set_args[@]}" \