From 3da52c646e256a7661d8e150683d6f63089208f6 Mon Sep 17 00:00:00 2001 From: Cezary Tarnowski Date: Sat, 27 Nov 2021 18:49:42 +0100 Subject: [PATCH] allow to omit cluster creation 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 553609c..e76e505 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,3 +37,18 @@ jobs: run: | 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 ]] diff --git a/README.md b/README.md index 5760288..720785e 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.20.8) +- `install_only`: Skips cluster creation, only install kind (default: false) ### Example Workflow diff --git a/action.yml b/action.yml index 1efedf5..d747311 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,8 @@ inputs: description: "The log level for kind" kubectl_version: description: "The kubectl version to use (default: v1.20.8)" + 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 d525fc2..ad90c83 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 1b4453c..e9ed588 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[@]}" } main -