Skip to content

Commit 070e126

Browse files
authored
add CREATE_NAMESPACE flag option
1 parent 016d790 commit 070e126

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Following inputs can be used as `step.with` keys
4949
| `action` | String | Determines if we `install`/`uninstall` the chart, or `list`. (Optional, Defaults to `install`) |
5050
| `dry-run` | Boolean | Toggles `dry-run` option for `install`/`uninstall` action. (Defaults to `false`) |
5151
| `config-files` | String | Comma separated list of helm values files. |
52-
| `namespace` | String | Kubernetes namespace to use. Will create if it does not exist |
52+
| `namespace` | String | Kubernetes namespace to use. To create the namespace if it doesn't exist, also set `create-namespace` to `true`. |
53+
| `create-namespace` | Boolean | Adds `--create-namespace` when set to `true`. Requires cluster API permissions. (Default: `true`) |
5354
| `values` | String | Comma separated list of value set for helms. e.x:`key1=value1,key2=value2` |
5455
| `name` | String | The name of the helm release |
5556
| `chart-path` | String | The path to the chart. (defaults to `helm/`) |
@@ -100,6 +101,7 @@ Following inputs can be used as `step.with` keys
100101
config-files: fluent-bit/prod/values.yaml
101102
chart-path: fluent/fluent-bit
102103
namespace: logging
104+
create-namespace: true
103105
name: fluent-bit
104106
chart-repository: https://fluent.github.io/helm-charts
105107
version: 0.20.6

action.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ inputs:
2525
description: 'Comma separated list of helm values files.'
2626
required: false
2727
namespace:
28-
description: 'Kubernetes namespace to use.'
28+
description: 'Kubernetes namespace to target. (default: "default")'
2929
required: false
30+
create-namespace:
31+
description: 'Enable creating the namespace if it does not exist. Requires cluster API permissions.'
32+
required: false
33+
default: "true"
3034
values:
3135
description: 'Comma separated list of value sets for helms. e.x: key1=value1,key2=value2'
3236
required: false
@@ -106,6 +110,7 @@ runs:
106110
CLUSTER_ROLE_ARN: ${{ inputs.cluster-role-arn }}
107111
DEPLOY_CONFIG_FILES: ${{ inputs.config-files }}
108112
DEPLOY_NAMESPACE: ${{ inputs.namespace }}
113+
CREATE_NAMESPACE: ${{ inputs.create-namespace }}
109114
DEPLOY_VALUES: ${{ inputs.values }}
110115
DEPLOY_NAME: ${{ inputs.name }}
111116
DEPLOY_CHART_PATH: ${{ inputs.chart-path }}

deploy.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ fi
126126
if [ "${HELM_ACTION}" == "install" ]; then
127127

128128
if [ -n "${USE_SECRETS_VALS}" ]; then
129-
HELM_COMMAND="helm secrets --backend vals --evaluate-templates true upgrade --install --create-namespace --timeout ${TIMEOUT} ${HELM_AUTH}"
129+
HELM_COMMAND="helm secrets --backend vals --evaluate-templates true upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}"
130130
else
131131
# Upgrade or install the chart. This does it all.
132-
HELM_COMMAND="helm upgrade --install --create-namespace --timeout ${TIMEOUT} ${HELM_AUTH}"
132+
HELM_COMMAND="helm upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}"
133133
fi
134134

135135
# If we should wait, then do so
@@ -181,6 +181,12 @@ if [ -n "$DEPLOY_NAMESPACE" ]; then
181181
HELM_COMMAND="${HELM_COMMAND} -n ${DEPLOY_NAMESPACE}"
182182
fi
183183

184+
# Create namespace if it doesn't exist. Requires cluster API permissions.
185+
# Will conflict with `list`, so don't set if in list mode
186+
if [ "${CREATE_NAMESPACE}" == "true" ] && [ "${HELM_ACTION}" != "list" ]; then
187+
HELM_COMMAND="${HELM_COMMAND} --create-namespace"
188+
fi
189+
184190
if [ "${HELM_ACTION}" == "list" ]; then
185191
if [ -n "$DEPLOY_NAME" ]; then
186192
HELM_COMMAND="${HELM_COMMAND} --filter"

0 commit comments

Comments
 (0)