Skip to content

Commit cfc4bb7

Browse files
authored
Merge pull request #15 from nolar/k3d-tag
Accept a custom K3d tag/version as a parameter
2 parents 7e76ae9 + d50e310 commit cfc4bb7

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

.github/workflows/ci.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ jobs:
7575
- run: kubectl version --context k3d-1-20
7676
- run: kubectl version --context k3d-1-21
7777

78+
test-custom-tag:
79+
name: Custom K3d tag
80+
runs-on: ubuntu-20.04
81+
steps:
82+
- uses: actions/checkout@v2
83+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
84+
with:
85+
version: v1.21
86+
k3d-tag: v4.4.8
87+
- run: k3d --version
88+
7889
test-custom-args:
7990
name: Custom args
8091
runs-on: ubuntu-20.04

README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ as found in [K3s releases](https://github.com/k3s-io/k3s/releases),
6161
according to the basic semantical sorting (i.e. not by time of releasing).
6262

6363

64+
### `k3d-tag`
65+
66+
A tag/version of K3d to use. Corresponds to GitHub tags at
67+
https://github.com/rancher/k3d/releases. For example, `v5.0.0`.
68+
`latest` is also accepted, but converted to an empty string
69+
for the installation script.
70+
71+
By default (i.e. if no value is provided), the latest version is used.
72+
73+
6474
### `k3d-name`
6575

6676
A name of the cluster to be created.
@@ -106,6 +116,11 @@ resources to appear (e.g., for a service account named "default").
106116

107117
## Outputs
108118

119+
### `k3d-version`
120+
121+
The specific K3d version that was detected and used. E.g. `v5.0.0`.
122+
123+
109124
### `k3s-version`
110125

111126
The specific K3s version that was detected and used. E.g. `v1.21.2+k3s1`.
@@ -118,7 +133,7 @@ The specific K8s version that was detected and used. E.g. `v1.21.2`.
118133

119134
## Examples
120135

121-
With the latest version of K3s/K8s:
136+
With the latest version of K3d/K3s/K8s:
122137

123138
```yaml
124139
steps:
@@ -184,6 +199,20 @@ jobs:
184199
- run: kubectl version --context k3d-1-21
185200
```
186201

202+
Custom version of K3d can be used, if needed:
203+
204+
```yaml
205+
jobs:
206+
some-job:
207+
name: Custom K3d version
208+
runs-on: ubuntu-20.04
209+
steps:
210+
- uses: nolar/setup-k3d-k3s@v1
211+
with:
212+
k3d-tag: v4.4.8
213+
- run: k3d --version
214+
```
215+
187216
Custom args can be passed to K3d (and through it, to K3s & K8s):
188217

189218
```yaml

action.sh

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
22
set -eu
3-
#set -x # for debugging
43

54
: ${GITHUB_API_URL:=https://api.github.com}
65
: ${VERSION:=latest}
@@ -59,14 +58,25 @@ fi
5958
K3S=$(jq --slurp <<< "$versions_matching" --raw-output '.[0]')
6059
K8S=${K3S%%+*}
6160

61+
# Install K3d and start a K3s cluster. It takes 20 seconds usually.
62+
# Name & args can be empty or multi-value. For this, they are not quoted.
63+
if [[ "${K3D_TAG:-}" == "latest" ]]; then
64+
K3D_TAG=""
65+
fi
66+
curl --silent --fail https://raw.githubusercontent.com/rancher/k3d/main/install.sh \
67+
| TAG=${K3D_TAG:-} bash
68+
k3d --version
69+
K3D=$(k3d --version | grep -Po 'k3d version \K(v[\S]+)' || true )
70+
6271
# Communicate back to GitHub Actions.
72+
echo "Detected k3d-version::${K3D}"
73+
echo "Detected k3s-version::${K3S}"
74+
echo "Detected k8s-version::${K8S}"
75+
echo "::set-output name=k3d-version::${K3D}"
6376
echo "::set-output name=k3s-version::${K3S}"
6477
echo "::set-output name=k8s-version::${K8S}"
6578

66-
# Install K3d and start a K3s cluster. It takes 20 seconds usually.
67-
# Name & args can be empty or multi-value. For this, they are not quoted.
68-
curl --silent --fail https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
69-
k3d --version
79+
# Start a cluster. It takes 20 seconds usually.
7080
k3d cluster create ${K3D_NAME:-} --wait --image=rancher/k3s:"${K3S//+/-}" ${K3D_ARGS:-}
7181

7282
# Sometimes, the service account is not created immediately. Nice trick, but no:

action.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
description: Full or partial version of K3s, or `latest`.
1010
required: true
1111
default: latest
12+
k3d-tag:
13+
description: K3d tag/version to use (by default, the latest one).
14+
required: false
15+
default: latest
1216
k3d-name:
1317
description: Cluster name.
1418
required: false
@@ -22,6 +26,9 @@ inputs:
2226
description: Skip waiting for full cluster readiness?
2327
required: false
2428
outputs:
29+
k3d-version:
30+
description: Actual version of K3d detected and used.
31+
value: ${{ steps.main.outputs.k3d-version }}
2532
k3s-version:
2633
description: Actual version of K3s detected and used.
2734
value: ${{ steps.main.outputs.k3s-version }}
@@ -36,6 +43,7 @@ runs:
3643
run: ${{ github.action_path }}/action.sh
3744
env:
3845
VERSION: ${{ inputs.version }}
46+
K3D_TAG: ${{ inputs.k3d-tag }}
3947
K3D_NAME: ${{ inputs.k3d-name }}
4048
K3D_ARGS: ${{ inputs.k3d-args }}
4149
GITHUB_TOKEN: ${{ inputs.github-token }}

0 commit comments

Comments
 (0)