diff --git a/helm-undeploy/action.yml b/helm-undeploy/action.yml new file mode 100644 index 0000000..89af1be --- /dev/null +++ b/helm-undeploy/action.yml @@ -0,0 +1,39 @@ +name: "Helm Undeploy" +description: "Undeploy a Helm deployment from a Kubernetes cluster" + +inputs: + namespace: + description: "The namespace of the Helm release" + required: true + release-name: + description: "The name of the Helm release" + required: true + +runs: + using: "composite" + steps: + - name: Delete Helm deployment + env: + HELM_DRIVER: configmaps + run: | + RELEASE_NAME="${{ inputs.release-name }}" + NAMESPACE="${{ inputs.namespace }}" + + echo "Checking Helm release: $RELEASE_NAME in namespace: $NAMESPACE" + + STATUS_OUTPUT=$(helm status "$RELEASE_NAME" --namespace "$NAMESPACE" 2>&1) && STATUS_EXIT=0 || STATUS_EXIT=$? + + if [ $STATUS_EXIT -eq 0 ]; then + echo "Release found. Uninstalling..." + helm uninstall "$RELEASE_NAME" --namespace "$NAMESPACE" + else + if echo "$STATUS_OUTPUT" | grep -qi "forbidden\|cannot list\|unauthorized\|permission"; then + echo "::error::Permission denied when querying release '$RELEASE_NAME'. Check kubeconfig and RBAC permissions." + echo "$STATUS_OUTPUT" + exit 1 + else + echo "Release '$RELEASE_NAME' not found, skipping uninstall." + echo "$STATUS_OUTPUT" + fi + fi + shell: bash diff --git a/readme.md b/readme.md index f0a5c2a..dacc18e 100644 --- a/readme.md +++ b/readme.md @@ -90,6 +90,28 @@ The following inputs can be used as `step.with` keys: | `timeout` | `5m` | The timeout for the Helm command | | `working-directory` | `.` | The working directory where the action commands will operate | +### Helm Undeploy + +Undeploy a Helm deployment from a Kubernetes cluster. Checks if the release exists before attempting uninstall and detects permission errors. Requires Kubernetes to be configured first. + +#### Example + +```yaml + - uses: aboutbits/github-actions-kubernetes/helm-undeploy@v4 + with: + release-name: my-app + namespace: my-namespace +``` + +#### Inputs + +The following inputs can be used as `step.with` keys: + +| Name | Required/Default | Description | +|----------------|------------------|--------------------------------| +| `namespace` | required | The namespace of the Helm release | +| `release-name` | required | The name of the Helm release | + ### Setup S3 Preview Creates an S3 preview prefix by copying from the main prefix.