From 64a0a2f703432485a9269138004db0ee433bdea4 Mon Sep 17 00:00:00 2001
From: Pierre Smeyers <pierre.smeyers@gmail.com>
Date: Tue, 3 Jan 2023 08:36:42 +0100
Subject: [PATCH] feat: environments activation is now opt-in

BREAKING CHANGE: HELM_xxx_DISABLED variables no longer supported to enable/disable environments (see doc)
---
 README.md                    | 16 ++++++-------
 kicker.json                  |  8 +++----
 templates/gitlab-ci-helm.yml | 45 +++++++++++++++++-------------------
 3 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/README.md b/README.md
index 86fc633..0d76c4e 100644
--- a/README.md
+++ b/README.md
@@ -226,13 +226,13 @@ The Helm template uses some global configuration used throughout all jobs.
 
 Review environments are dynamic and ephemeral environments to deploy your _ongoing developments_ (a.k.a. _feature_ or _topic_ branches).
 
-They are **enabled by default** and can be disabled by setting the `HELM_REVIEW_DISABLED` variable (see below).
+They are **disabled by default** and can be enabled by setting the `HELM_REVIEW_ENABLED` variable (see below).
 
 Here are variables supported to configure review environments:
 
 | Name                     | description                            | default value     |
 | ------------------------ | -------------------------------------- | ----------------- |
-| `HELM_REVIEW_DISABLED`   | Set to `true` to disable `review` env            | _none_ (enabled) |
+| `HELM_REVIEW_ENABLED`    | Set to `true` to enable `review` env   | _none_ (enabled) |
 | `HELM_REVIEW_APP_NAME`   | Application name for `review` env      | `"${HELM_BASE_APP_NAME}-${CI_ENVIRONMENT_SLUG}"` (ex: `myproject-review-fix-bug-12`) |
 | `HELM_REVIEW_ENVIRONMENT_URL`| The review environments url _(only define for static environment URLs declaration and if different from default)_ | `$HELM_ENVIRONMENT_URL` |
 | `HELM_REVIEW_NAMESPACE`  | The Kubernetes namespace to use for `review` env _(only define to override default)_ | `$KUBE_NAMESPACE` |
@@ -243,13 +243,13 @@ Here are variables supported to configure review environments:
 
 The integration environment is the environment associated to your integration branch (`develop` by default).
 
-It is **enabled by default** and can be disabled by setting the `HELM_INTEG_DISABLED` variable (see below).
+It is **disabled by default** and can be enabled by setting the `HELM_INTEG_ENABLED` variable (see below).
 
 Here are variables supported to configure the integration environment:
 
 | Name                     | description                            | default value     |
 | ------------------------ | -------------------------------------- | ----------------- |
-| `HELM_INTEG_DISABLED`    | Set to `true` to disable `integration` env       | _none_ (enabled) |
+| `HELM_INTEG_ENABLED`     | Set to `true` to enable `integration` env | _none_ (enabled) |
 | `HELM_INTEG_APP_NAME`    | Application name for `integration` env | `$HELM_BASE_APP_NAME-integration` |
 | `HELM_INTEG_ENVIRONMENT_URL`| The integration environment url _(only define for static environment URLs declaration and if different from default)_ | `$HELM_ENVIRONMENT_URL` |
 | `HELM_INTEG_NAMESPACE`   | The Kubernetes namespace to use for `integration` env _(only define to override default)_ | `$KUBE_NAMESPACE` |
@@ -260,13 +260,13 @@ Here are variables supported to configure the integration environment:
 
 The staging environment is an iso-prod environment meant for testing and validation purpose associated to your production branch (`master` by default).
 
-It is **enabled by default** and can be disabled by setting the `HELM_STAGING_DISABLED` variable (see below).
+It is **disabled by default** and can be enabled by setting the `HELM_STAGING_ENABLED` variable (see below).
 
 Here are variables supported to configure the staging environment:
 
 | Name                     | description                            | default value     |
 | ------------------------ | -------------------------------------- | ----------------- |
-| `HELM_STAGING_DISABLED`  | Set to `true` to disable `staging` env           | _none_ (enabled) |
+| `HELM_STAGING_ENABLED`   | Set to `true` to enable `staging` env  | _none_ (enabled) |
 | `HELM_STAGING_APP_NAME`  | Application name for `staging` env     | `$HELM_BASE_APP_NAME-staging` |
 | `HELM_STAGING_ENVIRONMENT_URL`| The staging environment url _(only define for static environment URLs declaration and if different from default)_ | `$HELM_ENVIRONMENT_URL` |
 | `HELM_STAGING_NAMESPACE` | The Kubernetes namespace to use for `staging` env _(only define to override default)_ | `$KUBE_NAMESPACE` |
@@ -277,13 +277,13 @@ Here are variables supported to configure the staging environment:
 
 The production environment is the final deployment environment associated with your production branch (`master` by default).
 
-It is **enabled by default** and can be disabled by setting the `HELM_PROD_DISABLED` variable (see below).
+It is **disabled by default** and can be enabled by setting the `HELM_PROD_ENABLED` variable (see below).
 
 Here are variables supported to configure the production environment:
 
 | Name                     | description                            | default value     |
 | ------------------------ | -------------------------------------- | ----------------- |
-| `HELM_PROD_DISABLED`     | Set to `true` to disable `production` env        | _none_ (enabled)  |
+| `HELM_PROD_ENABLED`      | Set to `true` to enable `production` env | _none_ (enabled)  |
 | `HELM_PROD_APP_NAME`     | Application name for `production` env  | `$HELM_BASE_APP_NAME` |
 | `HELM_PROD_ENVIRONMENT_URL`| The production environment url _(only define for static environment URLs declaration and if different from default)_ | `$HELM_ENVIRONMENT_URL` |
 | `HELM_PROD_NAMESPACE`    | The Kubernetes namespace to use for `production` env _(only define to override default)_ | `$KUBE_NAMESPACE` |
diff --git a/kicker.json b/kicker.json
index d305bd9..555fced 100644
--- a/kicker.json
+++ b/kicker.json
@@ -216,7 +216,7 @@
       "id": "review",
       "name": "Review",
       "description": "Dynamic review environments for your topic branches (see GitLab [Review Apps](https://docs.gitlab.com/ee/ci/review_apps/))",
-      "disable_with": "HELM_REVIEW_DISABLED",
+      "enable_with": "HELM_REVIEW_ENABLED",
       "variables": [
         {
           "name": "HELM_REVIEW_APP_NAME",
@@ -253,7 +253,7 @@
       "id": "integration",
       "name": "Integration",
       "description": "A continuous-integration environment associated to your integration branch (`develop` by default)",
-      "disable_with": "HELM_INTEG_DISABLED",
+      "enable_with": "HELM_INTEG_ENABLED",
       "variables": [
         {
           "name": "HELM_INTEG_APP_NAME",
@@ -290,7 +290,7 @@
       "id": "staging",
       "name": "Staging",
       "description": "An iso-prod environment meant for testing and validation purpose on your production branch (`master` by default)",
-      "disable_with": "HELM_STAGING_DISABLED",
+      "enable_with": "HELM_STAGING_ENABLED",
       "variables": [
         {
           "name": "HELM_STAGING_APP_NAME",
@@ -327,7 +327,7 @@
       "id": "prod",
       "name": "Production",
       "description": "The production environment",
-      "disable_with": "HELM_PROD_DISABLED",
+      "enable_with": "HELM_PROD_ENABLED",
       "variables": [
         {
           "name": "AUTODEPLOY_TO_PROD",
diff --git a/templates/gitlab-ci-helm.yml b/templates/gitlab-ci-helm.yml
index b3655d4..3613ad9 100644
--- a/templates/gitlab-ci-helm.yml
+++ b/templates/gitlab-ci-helm.yml
@@ -76,17 +76,14 @@ variables:
 
 #  HELM_COMMON_VALUES: "values-common.yml"
 
-#  HELM_REVIEW_DISABLED: "true"
 #  HELM_REVIEW_VALUES: "values-review.yml"
 #  HELM_REVIEW_NAMESPACE: ""
 #  HELM_REVIEW_KUBE_CONFIG: ""
 
-#  HELM_INTEG_DISABLED: "true"
 #  HELM_INTEG_VALUES: "values-review.yml"
 #  HELM_INTEG_NAMESPACE: ""
 #  HELM_INTEG_KUBE_CONFIG: ""
 
-#  HELM_STAGING_DISABLED: "true"
 #  HELM_STAGING_VALUES: "values-staging.yml"
 #  HELM_STAGING_NAMESPACE: ""
 #  HELM_STAGING_KUBE_CONFIG: ""
@@ -987,7 +984,7 @@ helm-publish:
 # Stage: review
 # ==================================================
 # deploy to review env (only for feature branches)
-# enabled by default, disable this job by setting $HELM_REVIEW_DISABLED
+# disabled by default, enable this job by setting $HELM_REVIEW_ENABLED
 helm-review:
   extends: .helm-deploy
   variables:
@@ -1003,8 +1000,8 @@ helm-review:
     on_stop: helm-cleanup-review
   resource_group: review/$CI_COMMIT_REF_NAME
   rules:
-    # exclude tags and on $HELM_REVIEW_DISABLED set
-    - if: '$HELM_REVIEW_DISABLED == "true" || $CI_COMMIT_TAG'
+    # exclude tags and on $HELM_REVIEW_ENABLED not set
+    - if: '$HELM_REVIEW_ENABLED != "true" || $CI_COMMIT_TAG'
       when: never
     # only on non-production, non-integration branches
     - if: '$CI_COMMIT_REF_NAME !~ $PROD_REF && $CI_COMMIT_REF_NAME !~ $INTEG_REF'
@@ -1022,8 +1019,8 @@ helm-cleanup-review:
     action: stop
   resource_group: review/$CI_COMMIT_REF_NAME
   rules:
-    # exclude tags and on $HELM_REVIEW_DISABLED set
-    - if: '$HELM_REVIEW_DISABLED == "true" || $CI_COMMIT_TAG'
+    # exclude tags and on $HELM_REVIEW_ENABLED not set
+    - if: '$HELM_REVIEW_ENABLED != "true" || $CI_COMMIT_TAG'
       when: never
     # only on non-production, non-integration branches
     - if: '$CI_COMMIT_REF_NAME !~ $PROD_REF && $CI_COMMIT_REF_NAME !~ $INTEG_REF'
@@ -1031,7 +1028,7 @@ helm-cleanup-review:
       allow_failure: true
 
 # test to review env (only for feature branches)
-# enabled by default, disable this job by setting $HELM_REVIEW_DISABLED
+# disabled by default, enable this job by setting $HELM_REVIEW_ENABLED
 helm-test-review:
   extends: .helm-test
   variables:
@@ -1043,7 +1040,7 @@ helm-test-review:
       when: never
     - if: '$HELM_TEST_ENABLED != "true"'
       when: never
-    - if: '$HELM_REVIEW_DISABLED == "true"'
+    - if: '$HELM_REVIEW_ENABLED != "true"'
       when: never
     # exclude on production or integration branch(es)
     - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF || $CI_COMMIT_REF_NAME =~ $INTEG_REF'
@@ -1055,7 +1052,7 @@ helm-test-review:
 # Stage: integration
 # ==================================================
 # deploy to integration env (only for integration branches)
-# enabled by default, disable this job by setting $HELM_INTEG_DISABLED
+# disabled by default, enable this job by setting $HELM_INTEG_ENABLED
 helm-integration:
   extends: .helm-deploy
   variables:
@@ -1070,8 +1067,8 @@ helm-integration:
     on_stop: helm-cleanup-integration
   resource_group: integration
   rules:
-    # exclude merge requests and on $HELM_INTEG_DISABLED set
-    - if: '$HELM_INTEG_DISABLED == "true"'
+    # exclude on $HELM_INTEG_ENABLED not set
+    - if: '$HELM_INTEG_ENABLED != "true"'
       when: never
     # only on integration branch(es)
     - if: '$CI_COMMIT_REF_NAME =~ $INTEG_REF'
@@ -1089,8 +1086,8 @@ helm-cleanup-integration:
     action: stop
   resource_group: integration
   rules:
-    # exclude merge requests and on $HELM_INTEG_DISABLED set
-    - if: '$HELM_INTEG_DISABLED == "true"'
+    # exclude on $HELM_INTEG_ENABLED not set
+    - if: '$HELM_INTEG_ENABLED != "true"'
       when: never
     # only on integration branch(es)
     - if: '$CI_COMMIT_REF_NAME =~ $INTEG_REF'
@@ -1098,7 +1095,7 @@ helm-cleanup-integration:
       allow_failure: true
 
 # test to integration env (only for integration branches)
-# enabled by default, disable this job by setting $HELM_INTEG_DISABLED
+# disabled by default, enable this job by setting $HELM_INTEG_ENABLED
 helm-test-integration:
   extends: .helm-test
   variables:
@@ -1111,7 +1108,7 @@ helm-test-integration:
       when: never
     - if: '$HELM_TEST_ENABLED != "true"'
       when: never
-    - if: '$HELM_INTEG_DISABLED == "true"'
+    - if: '$HELM_INTEG_ENABLED != "true"'
       when: never
     # exclude on non-integration branch
     - if: '$CI_COMMIT_REF_NAME !~ $INTEG_REF'
@@ -1136,8 +1133,8 @@ helm-staging:
     on_stop: helm-cleanup-staging
   resource_group: staging
   rules:
-    # exclude merge requests and on $HELM_STAGING_DISABLED set
-    - if: '$HELM_STAGING_DISABLED == "true"'
+    # exclude on $HELM_STAGING_ENABLED not set
+    - if: '$HELM_STAGING_ENABLED != "true"'
       when: never
     # only on production branch(es)
     - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF'
@@ -1155,8 +1152,8 @@ helm-cleanup-staging:
     action: stop
   resource_group: staging
   rules:
-    # exclude merge requests and on $HELM_STAGING_DISABLED set
-    - if: '$HELM_STAGING_DISABLED == "true"'
+    # exclude on $HELM_STAGING_ENABLED not set
+    - if: '$HELM_STAGING_ENABLED != "true"'
       when: never
     # only on production branch(es)
     - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF'
@@ -1175,7 +1172,7 @@ helm-test-staging:
       when: never
     - if: '$HELM_TEST_ENABLED != "true"'
       when: never
-    - if: '$HELM_STAGING_DISABLED == "true"'
+    - if: '$HELM_STAGING_ENABLED != "true"'
       when: never
     # exclude on non-production branch
     - if: '$CI_COMMIT_REF_NAME !~ $PROD_REF'
@@ -1204,8 +1201,8 @@ helm-production:
     # exclude non-production branches
     - if: '$CI_COMMIT_REF_NAME !~ $PROD_REF'
       when: never
-    # exclude if $HELM_PROD_DISABLED set
-    - if: '$HELM_PROD_DISABLED == "true"'
+    # exclude if $HELM_PROD_ENABLED not set
+    - if: '$HELM_PROD_ENABLED != "true"'
       when: never
     # if $AUTODEPLOY_TO_PROD: auto
     - if: '$AUTODEPLOY_TO_PROD == "true"'
-- 
GitLab