From b6e98a7021e964457a0397ff86e20fe4cb12751d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20OLIVIER?= <cedric3.olivier@orange.com> Date: Mon, 26 Jul 2021 10:32:42 +0000 Subject: [PATCH] fix: add an option to avoid var conflict name --- README.md | 7 +++++-- kicker.json | 12 ++++++++++++ templates/gitlab-ci-helm.yml | 6 +++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eddea67..859e090 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,9 @@ The Helm template uses some global configuration used throughout all jobs. | --------------------- | -------------------------------------- | ----------------- | | `HELM_CLI_IMAGE` | The Docker image used to run Helm | `alpine/helm:latest` - **it is highly recommended to set the CLI version compatible with your Kubernetes server** | | `HELM_CHART_DIR` | The folder in which is stored the Helm chart | `.` | +| `HELM_ENV_VALUE_NAME` | The environment type variable set to helm | `env` | +| `HELM_HOSTNAME_VALUE_NAME` | The hostname variable set to helm | `hostname` | + ### Secrets management @@ -194,8 +197,8 @@ In order to be able to implement some **genericity** in your scripts and templat 1. you should use generic [values](https://helm.sh/docs/chart_best_practices/values/) dynamically set and passed by the template: -* `env`: the environment type (`review`, `integration`, `staging` or `production`) -* `hostname`: the environment hostname, extracted from `${CI_ENVIRONMENT_URL}` (got from [`environment:url`](https://docs.gitlab.com/ee/ci/yaml/#environmenturl) - see `OS_REVIEW_ENVIRONMENT_SCHEME`, `OS_REVIEW_ENVIRONMENT_DOMAIN`, `OS_STAGING_ENVIRONMENT_URL` and `OS_PROD_ENVIRONMENT_URL`) +* `$HELM_ENV_VALUE_NAME` (set by default to `env`): the environment type (`review`, `integration`, `staging` or `production`) +* `$HELM_HOSTNAME_VALUE_NAME` (set by default to `hostname`): the environment hostname, extracted from `${CI_ENVIRONMENT_URL}` (got from [`environment:url`](https://docs.gitlab.com/ee/ci/yaml/#environmenturl) - see `OS_REVIEW_ENVIRONMENT_SCHEME`, `OS_REVIEW_ENVIRONMENT_DOMAIN`, `OS_STAGING_ENVIRONMENT_URL` and `OS_PROD_ENVIRONMENT_URL`) 2. you should use available environment variables: diff --git a/kicker.json b/kicker.json index 6f171dd..c11e8c6 100644 --- a/kicker.json +++ b/kicker.json @@ -56,6 +56,18 @@ "description": "The Helm [command with options](https://helm.sh/docs/helm/helm_dependency_update/) to update on-disk the chart dependencies (_without dynamic arguments such as the chart path_)", "default": "dependency update", "advanced": true + }, + { + "name": "HELM_ENV_VALUE_NAME", + "description": "The environment type variable set to helm", + "default": "env", + "advanced": true + }, + { + "name": "HELM_HOSTNAME_VALUE_NAME", + "description": "The hostname variable set to helm", + "default": "hostname", + "advanced": true } ], "features": [ diff --git a/templates/gitlab-ci-helm.yml b/templates/gitlab-ci-helm.yml index 5c4a2fe..de011e5 100644 --- a/templates/gitlab-ci-helm.yml +++ b/templates/gitlab-ci-helm.yml @@ -33,6 +33,9 @@ variables: HELM_REPOS: "stable@https://charts.helm.sh/stable bitnami@https://charts.bitnami.com/bitnami" + HELM_ENV_VALUE_NAME: env + HELM_HOSTNAME_VALUE_NAME: hostname + # Will work with gitlab Kubernetes integration (per env variables) # KUBE_NAMESPACE: "default" # KUBECONFIG: "" @@ -373,8 +376,9 @@ stages: fi log_info "--- using \\e[32mpackage\\e[0m: \\e[33;1m${package}\\e[0m" + # shellcheck disable=SC2086 - helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $helm_values_opt --set "env=$env,hostname=$hostname" $HELM_DEPLOY_ARGS $appname $package + helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $helm_values_opt --set "${HELM_ENV_VALUE_NAME}=$env,${HELM_HOSTNAME_VALUE_NAME}=$hostname" $HELM_DEPLOY_ARGS $appname $package # finally persist environment url echo "$CI_ENVIRONMENT_URL" > environment_url.txt -- GitLab