From deab45fc8df9de5090a604e8ec11778eea7170bd Mon Sep 17 00:00:00 2001 From: Cezary Tarnowski <73339102+CezaryTarnowski-TomTom@users.noreply.github.com> Date: Thu, 21 Apr 2022 10:07:48 +0200 Subject: [PATCH] allow to omit cluster creation (#50) Signed-off-by: Cezary Tarnowski --- .github/workflows/test.yaml | 15 +++++++++++++++ README.md | 1 + action.yml | 2 ++ kind.sh | 26 +++++++++++++++++++------- main.sh | 5 ++++- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8a3f291..94f096d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -38,6 +38,21 @@ jobs: kubectl cluster-info kubectl get storageclass standard + test-with-install-only: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Only install kind without starting a cluster + uses: ./ + with: + install_only: true + + - name: Test kind works and there is no cluster started + run: | + [[ $(kind get clusters | wc -l) -eq 0 ]] + test-with-custom-k8s-version: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index c02aeeb..1d2a782 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi - `wait`: The duration to wait for the control plane to become ready (default: `60s`) - `log_level`: The log level for kind - `kubectl_version`: The kubectl version to use (default: v1.21.10) +- `install_only`: Skips cluster creation, only install kind (default: false) ### Example Workflow diff --git a/action.yml b/action.yml index 6c6d30a..67f5f97 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,8 @@ inputs: description: "The kubectl version to use (default: v1.21.10)" required: false default: "v1.21.10" + install_only: + description: "Skips cluster creation, only install kind (default: false)" runs: using: "node12" main: "main.js" diff --git a/kind.sh b/kind.sh index 5a392c3..4fc5d2c 100755 --- a/kind.sh +++ b/kind.sh @@ -27,13 +27,14 @@ cat << EOF Usage: $(basename "$0") -h, --help Display help - -v, --version The kind version to use (default: $DEFAULT_KIND_VERSION)" - -c, --config The path to the kind config file" - -i, --node-image The Docker image for the cluster nodes" - -n, --cluster-name The name of the cluster to create (default: chart-testing)" - -w, --wait The duration to wait for the control plane to become ready (default: 60s)" + -v, --version The kind version to use (default: $DEFAULT_KIND_VERSION) + -c, --config The path to the kind config file + -i, --node-image The Docker image for the cluster nodes + -n, --cluster-name The name of the cluster to create (default: chart-testing) + -w, --wait The duration to wait for the control plane to become ready (default: 60s) -l, --log-level The log level for kind [panic, fatal, error, warning, info, debug, trace] (default: warning) - -k, --kubectl-version The kubectl version to use (default: $DEFAULT_KUBECTL_VERSION)" + -k, --kubectl-version The kubectl version to use (default: $DEFAULT_KUBECTL_VERSION) + -o, --install-only Skips cluster creation, only install kind (default: false) EOF } @@ -46,6 +47,7 @@ main() { local wait=60s local log_level= local kubectl_version="$DEFAULT_KUBECTL_VERSION" + local install_only=false parse_command_line "$@" @@ -77,7 +79,9 @@ main() { "$kind_dir/kind" version "$kubectl_dir/kubectl" version --client=true - create_kind_cluster + if [[ "$install_only" == false ]]; then + create_kind_cluster + fi } parse_command_line() { @@ -157,6 +161,14 @@ parse_command_line() { exit 1 fi ;; + -o|--install-only) + if [[ -n "${2:-}" ]]; then + install_only="$2" + shift + else + install_only=true + fi + ;; *) break ;; diff --git a/main.sh b/main.sh index 688195f..b41b9d2 100755 --- a/main.sh +++ b/main.sh @@ -51,8 +51,11 @@ main() { args+=(--kubectl-version "${INPUT_KUBECTL_VERSION}") fi + if [[ -n "${INPUT_INSTALL_ONLY:-}" ]]; then + args+=(--install-only) + fi + "$SCRIPT_DIR/kind.sh" ${args[@]+"${args[@]}"} } main -