From 6c06f828b9b0022e72665d8f32143d2662455288 Mon Sep 17 00:00:00 2001 From: Pinaki Sarkar Date: Fri, 22 May 2026 11:46:41 -0700 Subject: [PATCH] CBP-47071: make the 'create-namespace' helm install input configurable, defaults to 'true' --- .cloudbees/testing/action.yml | 11 ++++++- .cloudbees/workflows/workflow.yaml | 51 +++++++++++++++++++++++++++++- action.yml | 11 ++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/.cloudbees/testing/action.yml b/.cloudbees/testing/action.yml index 572a3bf..8b7a044 100644 --- a/.cloudbees/testing/action.yml +++ b/.cloudbees/testing/action.yml @@ -9,6 +9,9 @@ inputs: namespace: description: 'Kubernetes namespace to install the chart in, created if missing' default: default + create-namespace: + description: 'Whether to create the namespace if it does not exist' + default: 'true' version: description: 'Version of the chart to be installed' # DEPRECATED: values-file is deprecated, use values-files instead @@ -52,6 +55,10 @@ inputs: CloudBees registry configuration file containing the registries to use for loading images. By default it uses the file containing the registries configured under 'Integrations' in the CloudBees platform. default: ${{ cloudbees.registries }} +outputs: + release-revision: + description: 'The helm release revision number after install/upgrade' + value: ${{ steps.helm-install.outputs.release-revision }} runs: using: composite steps: @@ -126,7 +133,7 @@ runs: releases: - valuesFiles: - /tmp/values.yaml - createNamespace: true + ${{ inputs.create-namespace == 'true' && 'createNamespace: true' || 'createNamespace: false' }} skipBuildDependencies: true upgradeOnChange: true flags: @@ -207,11 +214,13 @@ runs: --create-namespace \ --timeout "$TIMEOUT" \ --dry-run + printf '' > $CLOUDBEES_OUTPUTS/release-revision else # Let skaffold deploy the chart to log details on failure cd /tmp/skaffold skaffold config set collect-metrics false skaffold deploy + printf %s "$(helm status "$RELEASE_NAME" -n "$HELM_NAMESPACE" -o yaml | yq '.version')" > $CLOUDBEES_OUTPUTS/release-revision fi env: CHART_LOCATION: ${{ inputs.chart-location }} diff --git a/.cloudbees/workflows/workflow.yaml b/.cloudbees/workflows/workflow.yaml index c2b30fb..c476e93 100644 --- a/.cloudbees/workflows/workflow.yaml +++ b/.cloudbees/workflows/workflow.yaml @@ -255,7 +255,56 @@ jobs: namespace: ${{ steps.createns.outputs.name }} timeout: 1m wait: 'false' - - name: test startup probe failure scenario + - id: create-namespace-false-existing-ns + name: install a helm chart with create-namespace set to false into existing namespace + uses: ./.cloudbees/testing + with: + release-name: example-no-create-ns + chart-location: charts/example + namespace: ${{ steps.createns.outputs.name }} + create-namespace: 'false' + timeout: 2m + - name: verify create-namespace false into existing namespace produced a release revision + uses: docker://alpine/k8s:1.31.2 + run: | + set -ux + [ -n "${REVISION}" ] + env: + REVISION: ${{ steps.create-namespace-false-existing-ns.outputs.release-revision }} + - id: create-namespace-true-new-ns + name: install a helm chart with create-namespace set to true into new namespace + uses: ./.cloudbees/testing + with: + release-name: example-create-ns + chart-location: charts/example + namespace: ${{ format('cn-{0}', cloudbees.scm.sha) }} + create-namespace: 'true' + timeout: 2m + - name: verify create-namespace true into new namespace produced a release revision + uses: docker://alpine/k8s:1.31.2 + run: | + set -ux + [ -n "${REVISION}" ] + env: + REVISION: ${{ steps.create-namespace-true-new-ns.outputs.release-revision }} + - id: create-namespace-false-missing-ns + name: install a helm chart with create-namespace false into non-existent namespace + continue-on-error: true + uses: ./.cloudbees/testing + with: + release-name: example-no-ns + chart-location: charts/example + namespace: ${{ format('missing-{0}', cloudbees.scm.sha) }} + create-namespace: 'false' + timeout: 2m + - name: verify create-namespace false into missing namespace produced no release revision + uses: docker://alpine/k8s:1.31.2 + run: | + set -ux + [ -z "${REVISION}" ] + env: + REVISION: ${{ steps.create-namespace-false-missing-ns.outputs.release-revision }} + - name: test startup probe failure scenario continue-on-error: true uses: ./.cloudbees/testing with: diff --git a/action.yml b/action.yml index ce131b8..1d1fcab 100644 --- a/action.yml +++ b/action.yml @@ -9,6 +9,9 @@ inputs: namespace: description: 'Kubernetes namespace to install the chart in, created if missing' default: default + create-namespace: + description: 'Whether to create the namespace if it does not exist' + default: 'true' version: description: 'Version of the chart to be installed' # DEPRECATED: values-file is deprecated, use values-files instead @@ -52,6 +55,10 @@ inputs: CloudBees registry configuration file containing the registries to use for loading images. By default it uses the file containing the registries configured under 'Integrations' in the CloudBees platform. default: ${{ cloudbees.registries }} +outputs: + release-revision: + description: 'The helm release revision number after install/upgrade' + value: ${{ steps.helm-install.outputs.release-revision }} runs: using: composite steps: @@ -126,7 +133,7 @@ runs: releases: - valuesFiles: - /tmp/values.yaml - createNamespace: true + ${{ inputs.create-namespace == 'true' && 'createNamespace: true' || 'createNamespace: false' }} skipBuildDependencies: true upgradeOnChange: true flags: @@ -207,11 +214,13 @@ runs: --create-namespace \ --timeout "$TIMEOUT" \ --dry-run + printf '' > $CLOUDBEES_OUTPUTS/release-revision else # Let skaffold deploy the chart to log details on failure cd /tmp/skaffold skaffold config set collect-metrics false skaffold deploy + printf %s "$(helm status "$RELEASE_NAME" -n "$HELM_NAMESPACE" -o yaml | yq '.version')" > $CLOUDBEES_OUTPUTS/release-revision fi env: CHART_LOCATION: ${{ inputs.chart-location }}