From 568a2a81f9c2382903d0282ac84a6f4c717abd03 Mon Sep 17 00:00:00 2001 From: Max Mathieu Date: Thu, 12 Jun 2025 18:51:41 -0400 Subject: [PATCH 1/2] Log diff option --- README.md | 7 ++++--- action.yaml | 10 ++++++++-- deploy.sh | 30 ++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7c0f823..84f7155 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ The following inputs are available as `step.with` keys: | `action` | String | Determines if we `install`/`uninstall` the chart, or `list`. (Optional, Defaults to `install`) | | `dry-run` | Boolean | Toggles `dry-run` option for `install`/`uninstall` action. (Defaults to `false`) | | `config-files` | String | Comma separated list of helm values files. | -| `namespace` | String | Kubernetes namespace to use. To create the namespace if it doesn't exist, also set `create-namespace` to `true`. | -| `create-namespace` | Boolean | Adds `--create-namespace` when set to `true`. Requires cluster API permissions. (Default: `true`) | +| `namespace` | String | Kubernetes namespace to use. To create the namespace if it doesn't exist, also set `create-namespace` to `true`. | +| `create-namespace` | Boolean | Adds `--create-namespace` when set to `true`. Requires cluster API permissions. (Default: `true`) | | `values` | String | Comma separated list of value set for helms. e.x: `key1=value1, key2=value2` | | `name` | String | The name of the helm release. | | `chart-path` | String | The path to the chart. (defaults to `helm/`) | @@ -67,7 +67,8 @@ The following inputs are available as `step.with` keys: | `username` | String | Chart repository username where to locate the requested chart. | | `password` | String | Chart repository password where to locate the requested chart. | | `use-secrets-vals` | Boolean | Use secrets plugin using vals to evaluate the secrets | -| `helm-extra-args` | String | Append any string containing any extra option that might escape the ones present in this action. +| `helm-extra-args` | String | Append any string containing any extra option that might escape the ones present in this action. | +| `log-diff` | Boolean | Outputs the diff of changes for `install` action. (Defaults to `false`) | ## Example 1 - local repo chart diff --git a/action.yaml b/action.yaml index 0137589..6053d56 100644 --- a/action.yaml +++ b/action.yaml @@ -44,7 +44,7 @@ inputs: dry-run: description: 'Toggles dry-run flag for install/uninstall actions' required: false - default: false + default: "false" chart-path: description: 'The path of the chart.' required: false @@ -99,6 +99,11 @@ inputs: helm-extra-args: description: 'Append any string containing any extra option that might escape the ones present in this action.' required: false + log-diff: + description: 'Log the diff of the helm chart before applying it, only works with install action.' + required: false + default: "false" + runs: using: 'docker' image: 'Dockerfile' @@ -131,4 +136,5 @@ runs: REPO_PASSWORD: ${{ inputs.password }} VERSION: ${{ inputs.version }} USE_SECRETS_VALS: ${{ inputs.use-secrets-vals }} - HELM_EXTRA_ARGS: ${{ inputs.helm-extra-args }} \ No newline at end of file + HELM_EXTRA_ARGS: ${{ inputs.helm-extra-args }} + LOG_DIFF: ${{ inputs.log-diff }} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index de4ba62..10b9b9f 100644 --- a/deploy.sh +++ b/deploy.sh @@ -126,12 +126,14 @@ fi if [ "${HELM_ACTION}" == "install" ]; then if [ -n "${USE_SECRETS_VALS}" ]; then - HELM_COMMAND="helm secrets --backend vals --evaluate-templates true upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}" + HELM_COMMAND="helm secrets --backend vals --evaluate-templates true upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}" else # Upgrade or install the chart. This does it all. - HELM_COMMAND="helm upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}" + HELM_COMMAND="helm upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}" fi + HELM_TEMPLATE_COMMAND="helm template --is-upgrade --timeout ${TIMEOUT} ${HELM_AUTH}" + # If we should wait, then do so if [ -n "${HELM_WAIT}" ]; then HELM_COMMAND="${HELM_COMMAND} --wait" @@ -145,6 +147,7 @@ if [ "${HELM_ACTION}" == "install" ]; then for config_file in ${DEPLOY_CONFIG_FILES//,/ } do HELM_COMMAND="${HELM_COMMAND} -f ${config_file}" + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} -f ${config_file}" done if [ -n "$DEPLOY_VALUES" ]; then @@ -161,15 +164,18 @@ if [ "${HELM_ACTION}" == "install" ]; then continue fi HELM_COMMAND="${HELM_COMMAND} --set ${value}" + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --set ${value}" done fi if [ -n "$VERSION" ]; then HELM_COMMAND="${HELM_COMMAND} --version ${VERSION}" + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --version ${VERSION}" fi if [ "${UPDATE_DEPS}" == "true" ]; then HELM_COMMAND="${HELM_COMMAND} --dependency-update" + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --dependency-update" fi if [ "${DRY_RUN}" == "true" ]; then @@ -190,8 +196,12 @@ else exit 2 fi +KUBECTL_DIFF_COMMAND="kubectl" + if [ -n "$DEPLOY_NAMESPACE" ]; then HELM_COMMAND="${HELM_COMMAND} -n ${DEPLOY_NAMESPACE}" + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} -n ${DEPLOY_NAMESPACE}" + KUBECTL_DIFF_COMMAND="${KUBECTL_DIFF_COMMAND} -n ${DEPLOY_NAMESPACE}" fi # Create namespace if it doesn't exist. Requires cluster API permissions. @@ -210,6 +220,7 @@ fi # Execute Commands HELM_COMMAND="${HELM_COMMAND} ${DEPLOY_NAME}" +HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} ${DEPLOY_NAME}" if [ "${HELM_ACTION}" == "install" ]; then if [ "${OCI_REGISTRY}" == "true" ]; then @@ -220,7 +231,18 @@ if [ "${HELM_ACTION}" == "install" ]; then fi fi HELM_COMMAND="${HELM_COMMAND} ${DEPLOY_CHART_PATH}" + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} ${DEPLOY_CHART_PATH}" +fi + +HELM_COMMAND="${HELM_COMMAND} ${HELM_EXTRA_ARGS}" +HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} ${HELM_EXTRA_ARGS}" + +if [ "${LOG_DIFF}" == "true" ] && [ "${HELM_ACTION}" == "install" ]; then + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --dry-run --skip-tests" + KUBECTL_DIFF_COMMAND="${KUBECTL_DIFF_COMMAND} diff --server-side=false" + echo "Diffing before applying: ${HELM_TEMPLATE_COMMAND} | ${KUBECTL_DIFF_COMMAND} -f -" + ${HELM_TEMPLATE_COMMAND} | ${KUBECTL_DIFF_COMMAND} -f - || true # Ignore kubectl diff exit code fi -echo "Executing: ${HELM_COMMAND} ${HELM_EXTRA_ARGS}" -${HELM_COMMAND} ${HELM_EXTRA_ARGS} +echo "Executing: ${HELM_COMMAND}" +${HELM_COMMAND} From 208a303b94206d7f3f3ed0be0dbb417529c9bdf0 Mon Sep 17 00:00:00 2001 From: Max Mathieu Date: Tue, 24 Jun 2025 08:13:36 -0400 Subject: [PATCH 2/2] Also add option --- README.md | 1 + action.yaml | 7 ++++++- deploy.sh | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 84f7155..995d197 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ The following inputs are available as `step.with` keys: | `use-secrets-vals` | Boolean | Use secrets plugin using vals to evaluate the secrets | | `helm-extra-args` | String | Append any string containing any extra option that might escape the ones present in this action. | | `log-diff` | Boolean | Outputs the diff of changes for `install` action. (Defaults to `false`) | +| `debug` | Boolean | Turns on debug mode (Defaults to `false`) | ## Example 1 - local repo chart diff --git a/action.yaml b/action.yaml index 6053d56..78130e7 100644 --- a/action.yaml +++ b/action.yaml @@ -103,6 +103,10 @@ inputs: description: 'Log the diff of the helm chart before applying it, only works with install action.' required: false default: "false" + debug: + description: 'Turns on debug mode.' + required: false + default: "false" runs: using: 'docker' @@ -137,4 +141,5 @@ runs: VERSION: ${{ inputs.version }} USE_SECRETS_VALS: ${{ inputs.use-secrets-vals }} HELM_EXTRA_ARGS: ${{ inputs.helm-extra-args }} - LOG_DIFF: ${{ inputs.log-diff }} \ No newline at end of file + LOG_DIFF: ${{ inputs.log-diff }} + DEBUG: ${{ inputs.debug }} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 10b9b9f..b5a6bd4 100644 --- a/deploy.sh +++ b/deploy.sh @@ -182,6 +182,11 @@ if [ "${HELM_ACTION}" == "install" ]; then HELM_COMMAND="${HELM_COMMAND} --dry-run" fi + if [ "${DEBUG}" == "true" ]; then + HELM_COMMAND="${HELM_COMMAND} --debug" + HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --debug" + fi + elif [ "${HELM_ACTION}" == "uninstall" ]; then HELM_COMMAND="helm uninstall --timeout ${TIMEOUT}"