Skip to content

Commit

Permalink
Merge pull request #20 from nolar/skip-cluster-creation
Browse files Browse the repository at this point in the history
Add an option to skip the cluster creation
  • Loading branch information
nolar authored Nov 1, 2022
2 parents 181c711 + e947bd7 commit 293b8e5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ jobs:
K3S: ${{ steps.install.outputs.k3s-version }}
K8S: ${{ steps.install.outputs.k8s-version }}

test-skip-creation:
name: Skip creation
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
skip-creation: true

test-skip-readiness:
name: Skip readiness
runs-on: ubuntu-22.04
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ with:
```


### `skip-creation`

Whether to return from the action as soon as possible
without the cluster creation (the cluster readiness is also skipped).
This can be useful to only install the tools for manual cluster creation,
or to parse the available versions and return them as the action's outputs.

By default (`false`), the cluster is created.


### `skip-readiness`

Whether to return from the action as soon as possible,
Expand Down
8 changes: 6 additions & 2 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ echo "k3s-version=${K3S}" >> $GITHUB_OUTPUT
echo "k8s-version=${K8S}" >> $GITHUB_OUTPUT

# Start a cluster. It takes 20 seconds usually.
k3d cluster create ${K3D_NAME:-} --wait --image=rancher/k3s:"${K3S//+/-}" ${K3D_ARGS:-}
if [[ -z "${SKIP_CREATION}" ]]; then
k3d cluster create ${K3D_NAME:-} --wait --image=rancher/k3s:"${K3S//+/-}" ${K3D_ARGS:-}
else
echo "Skipping the cluster creation. The cluster can be not fully ready yet."
fi

# Sometimes, the service account is not created immediately. Nice trick, but no:
# we need to wait until the cluster is fully ready before starting the tests.
if [[ -z "${SKIP_READINESS}" ]]; then
if [[ -z "${SKIP_CREATION}" && -z "${SKIP_READINESS}" ]]; then
echo "::group::Waiting for cluster readiness"
while ! kubectl get serviceaccount default >/dev/null; do sleep 1; done
echo "::endgroup::"
Expand Down
5 changes: 5 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ inputs:
github-token:
description: Optional GitHub token to overcome API rate limiting.
required: false
skip-creation:
description: Skip creating the cluster and waiting for its readiness?
required: false
skip-readiness:
description: Skip waiting for full cluster readiness?
required: false
Expand All @@ -47,8 +50,10 @@ runs:
K3D_NAME: ${{ inputs.k3d-name }}
K3D_ARGS: ${{ inputs.k3d-args }}
GITHUB_TOKEN: ${{ inputs.github-token }}
SKIP_CREATION: ${{ inputs.skip-creation && 'yes' || '' }}
SKIP_READINESS: ${{ inputs.skip-readiness && 'yes' || '' }}

# Validate that everything is installed, is on PATH, and generally works.
- shell: bash
run: kubectl version
if: ${{ !inputs.skip-creation }}

0 comments on commit 293b8e5

Please sign in to comment.