From cb265aad459aff74ed417df4d31aeb7c59b0f6e8 Mon Sep 17 00:00:00 2001
From: Jerry Chen <jerry153fish@gmail.com>
Date: Mon, 27 Feb 2023 11:48:24 +1100
Subject: [PATCH] #54 ignore the occasional post delete cluster

Signed-off-by: Jerry Chen <jerry153fish@gmail.com>
---
 .github/workflows/test.yaml | 17 +++++++++++++++++
 README.md                   |  1 +
 action.yml                  |  4 ++++
 cleanup.sh                  |  2 +-
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 9781e91..b30e59c 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -100,3 +100,20 @@ jobs:
         run: |
           kubectl cluster-info
           kubectl get nodes
+
+  test-with-ignore-failed-clean:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
+
+      - name: Create kind cluster with custom name
+        uses: ./
+        with:
+          kubectl_version: "v1.24.6"
+          ignore_failed_clean: true
+
+      - name: Test
+        run: |
+          kubectl cluster-info
+          kubectl get nodes
diff --git a/README.md b/README.md
index d50bf9b..87b01f5 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi
 - `verbosity`: info log verbosity, higher value produces more output
 - `kubectl_version`: The kubectl version to use (default: v1.23.12)
 - `install_only`: Skips cluster creation, only install kind (default: false)
+- `ignore_failed_clean`: Whether to ignore the post delete cluster action failing (default: false)
 
 ### Example Workflow
 
diff --git a/action.yml b/action.yml
index a8afa9a..9e6f264 100644
--- a/action.yml
+++ b/action.yml
@@ -34,6 +34,10 @@ inputs:
   install_only:
     description: "Skips cluster creation, only install kind (default: false)"
     required: false
+  ignore_failed_clean:
+    description: "Whether to ignore the post-delete the cluster (default: false)"
+    default: false
+    required: false
 runs:
   using: "node16"
   main: "main.js"
diff --git a/cleanup.sh b/cleanup.sh
index 94bdc1f..bfc800e 100755
--- a/cleanup.sh
+++ b/cleanup.sh
@@ -29,7 +29,7 @@ main() {
         args+=(--name "${DEFAULT_CLUSTER_NAME}")
     fi
 
-    kind delete cluster "${args[@]}"
+    kind delete cluster "${args[@]}" || "${INPUT_IGNORE_FAILED_CLEAN}"
 }
 
 main