diff --git a/changelogs/unreleased/64081-override-helm-release-name.yml b/changelogs/unreleased/64081-override-helm-release-name.yml new file mode 100644 index 00000000000..2bf39b17c03 --- /dev/null +++ b/changelogs/unreleased/64081-override-helm-release-name.yml @@ -0,0 +1,5 @@ +--- +title: Allow multiple Auto DevOps projects to deploy to a single namespace within a k8s cluster +merge_request: 30360 +author: James Keogh +type: added diff --git a/doc/topics/autodevops/index.md b/doc/topics/autodevops/index.md index 7a92a672801..30b9e88ade8 100644 --- a/doc/topics/autodevops/index.md +++ b/doc/topics/autodevops/index.md @@ -764,6 +764,7 @@ also be customized, and you can easily use a [custom buildpack](#custom-buildpac | `ROLLOUT_RESOURCE_TYPE` | From GitLab 11.9, this variable allows specification of the resource type being deployed when using a custom helm chart. Default value is `deployment`. | | `ROLLOUT_STATUS_DISABLED` | From GitLab 12.0, this variable allows to disable rollout status check because it doesn't support all resource types, for example, `cronjob`. | | `HELM_UPGRADE_EXTRA_ARGS` | From GitLab 11.11, this variable allows extra arguments in `helm` commands when deploying the application. Note that using quotes will not prevent word splitting. **Tip:** you can use this variable to [customize the Auto Deploy helm chart](https://docs.gitlab.com/ee/topics/autodevops/index.html#custom-helm-chart) by applying custom override values with `--values my-values.yaml`. | +| `HELM_RELEASE_NAME` | From GitLab 12.1, this variable allows the `helm` release name to be overridden, this can be used to assign unique release names when deploying multiple projects to a single namespace | TIP: **Tip:** Set up the replica variables using a diff --git a/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml index 108f0119ae1..6ead127e7b6 100644 --- a/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml @@ -243,7 +243,8 @@ rollout 100%: .deploy_helpers: &deploy_helpers | [[ "$TRACE" ]] && set -x - auto_database_url=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${CI_ENVIRONMENT_SLUG}-postgres:5432/${POSTGRES_DB} + export RELEASE_NAME=${HELM_RELEASE_NAME:-$CI_ENVIRONMENT_SLUG} + auto_database_url=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${RELEASE_NAME}-postgres:5432/${POSTGRES_DB} export DATABASE_URL=${DATABASE_URL-$auto_database_url} export TILLER_NAMESPACE=$KUBE_NAMESPACE @@ -307,7 +308,7 @@ rollout 100%: } function deploy_name() { - name="$CI_ENVIRONMENT_SLUG" + name="$RELEASE_NAME" track="${1-stable}" if [[ "$track" != "stable" ]]; then @@ -372,7 +373,7 @@ rollout 100%: --set service.enabled="$service_enabled" \ --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ - --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ + --set releaseOverride="$RELEASE_NAME" \ --set image.repository="$image_repository" \ --set image.tag="$image_tag" \ --set image.pullPolicy=IfNotPresent \ @@ -413,7 +414,7 @@ rollout 100%: --set service.enabled="$service_enabled" \ --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ - --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ + --set releaseOverride="$RELEASE_NAME" \ --set image.repository="$image_repository" \ --set image.tag="$image_tag" \ --set image.pullPolicy=IfNotPresent \