Skip to content

Commit 2b27f7a

Browse files
authored
Merge pull request #1 from nolar/initial
Implement the action initially
2 parents d0b3a0d + 1b7e89e commit 2b27f7a

File tree

7 files changed

+463
-0
lines changed

7 files changed

+463
-0
lines changed

.github/workflows/ci.yaml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release/**
7+
pull_request:
8+
branches:
9+
- master
10+
- release/**
11+
workflow_dispatch: {}
12+
13+
jobs:
14+
15+
test-latest:
16+
name: Install latest
17+
runs-on: ubuntu-20.04
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
21+
- run: kubectl version
22+
23+
test-specific:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
k3s: [v1.17.14+k3s2, v1.17.14, v1.17, v1]
28+
name: Install ${{ matrix.k3s }}
29+
runs-on: ubuntu-20.04
30+
steps:
31+
- uses: actions/checkout@v2
32+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
33+
with:
34+
version: ${{ matrix.k3s }}
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
- run: kubectl version
37+
38+
test-outputs:
39+
name: Check outputs
40+
runs-on: ubuntu-20.04
41+
steps:
42+
- uses: actions/checkout@v2
43+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
44+
with:
45+
version: latest
46+
github-token: ${{ secrets.GITHUB_TOKEN }}
47+
id: install
48+
- run: echo K3S=${K3S} K8S=${K8S}
49+
env:
50+
K3S: ${{ steps.install.outputs.k3s-version }}
51+
K8S: ${{ steps.install.outputs.k8s-version }}
52+
53+
test-skip-readiness:
54+
name: Skip readiness
55+
runs-on: ubuntu-20.04
56+
steps:
57+
- uses: actions/checkout@v2
58+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
59+
with:
60+
github-token: ${{ secrets.GITHUB_TOKEN }}
61+
skip-readiness: true
62+
- run: kubectl version
63+
64+
test-multi-cluster:
65+
name: Multi-cluster
66+
runs-on: ubuntu-20.04
67+
steps:
68+
- uses: actions/checkout@v2
69+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
70+
with:
71+
version: v1.16
72+
k3d-name: 1-16
73+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
74+
with:
75+
version: v1.18
76+
k3d-name: 1-18
77+
- run: kubectl version --context k3d-1-16
78+
- run: kubectl version --context k3d-1-18
79+
80+
test-custom-args:
81+
name: Custom args
82+
runs-on: ubuntu-20.04
83+
steps:
84+
- uses: actions/checkout@v2
85+
- uses: ./ # normally: nolar/setup-k3d-k3s@v1
86+
with:
87+
version: v1.16
88+
k3d-args: --servers 2 --no-lb
89+
- run: kubectl get nodes # there must be two of them

FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: nolar

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Sergey Vasilyev <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MAINTAINERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sergey Vasilyev <[email protected]>

README.md

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Setup K3d/K3s for GitHub Actions
2+
3+
Install K3d/K3s and start a local Kubernetes cluster of a specific version.
4+
5+
**K8s** is Kubernetes.
6+
**K3s** is a lightweight K8s distribution.
7+
**K3d** is a wrapper to run K3s in Docker.
8+
9+
K3d/K3s are especially good for development and CI purposes, as it takes
10+
only 20-30 seconds of time till the cluster is ready. For comparison,
11+
Kind takes 1.5 minutes, Minikube takes 2 minutes till ready (as of Sep'2020).
12+
13+
14+
## Quick start
15+
16+
Start with the simplest way:
17+
18+
```yaml
19+
jobs:
20+
some-job:
21+
steps:
22+
- uses: nolar/setup-k3d-k3s@v1
23+
```
24+
25+
Change versions with the verbose way:
26+
27+
```yaml
28+
jobs:
29+
some-job:
30+
steps:
31+
- uses: nolar/setup-k3d-k3s@v1
32+
with:
33+
version: v1.19 # E.g.: v1.19, v1.19.4, v1.19.4+k3s1
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
35+
```
36+
37+
38+
## Inputs
39+
40+
### `version`
41+
42+
**Required** version of Kubernetes and/or K3s -- either full or partial.
43+
44+
The following notations are supported:
45+
46+
* `v1.19.4+k3s1`
47+
* `v1.19.4`
48+
* `v1.19`
49+
* `v1`
50+
* `latest`
51+
52+
Defaults to `latest`.
53+
54+
Keep in mind that K3d dates back only to v1.16.
55+
There are no 1.15 and older versions of K8s.
56+
57+
When the version is partial, the latest detected one will be used,
58+
as found in [K3s releases](https://github.com/rancher/k3s/releases),
59+
according to the basic semantical sorting (i.e. not by time of releasing).
60+
61+
62+
### `k3d-name`
63+
64+
A name of the cluster to be created.
65+
66+
By default (i.e. if no value is provided), K3d/K3s define their own name.
67+
Usually it is `k3d-k3s-default`.
68+
69+
Note: the name should not include the `k3d-` prefix, but must be used with it.
70+
The `k3d-` prefix is enforced by K3d and cannot be disabled.
71+
72+
73+
### `k3d-args`
74+
75+
Additional args to pass to K3d.
76+
See `k3d cluster create --help` for available flags.
77+
78+
79+
### `github-token`
80+
81+
A token for GitHub API, which is used to avoid rate limiting.
82+
83+
The API is used to fetch the releases from the K3s repository.
84+
85+
By default, or if it is empty, then the API is accessed anonymously,
86+
which implies the limit of approximately 60 requests / 1 hour / 1 worker.
87+
88+
Usage:
89+
90+
```yaml
91+
with:
92+
github-token: ${{ secrets.GITHUB_TOKEN }}
93+
```
94+
95+
96+
### `skip-readiness`
97+
98+
Whether to return from the action as soon as possible,
99+
possibly providing a cluster that is only partially ready.
100+
101+
By default (`false`), the readiness is awaited by checking for some preselected
102+
resources to appear (e.g., for a service account named "default").
103+
104+
105+
## Outputs
106+
107+
### `k3s-version`
108+
109+
The specific K3s version that was detected and used. E.g. `v1.19.4+k3s1`.
110+
111+
112+
### `k8s-version`
113+
114+
The specific K8s version that was detected and used. E.g. `v1.19.4`.
115+
116+
117+
## Examples
118+
119+
With the latest version of K3s/K8s:
120+
121+
```yaml
122+
steps:
123+
- uses: nolar/setup-k3d-k3s@v1
124+
```
125+
126+
With the specific minor version of K8s, which implies the latest micro version
127+
of K8s and the latest possible version of K3s:
128+
129+
```yaml
130+
steps:
131+
- uses: nolar/setup-k3d-k3s@v1
132+
with:
133+
version: v1.19
134+
```
135+
136+
With the very specific version of K3s:
137+
138+
```yaml
139+
steps:
140+
- uses: nolar/setup-k3d-k3s@v1
141+
with:
142+
version: v1.19.4+k3s1
143+
```
144+
145+
The partial versions enable the build matrices with only the essential
146+
information in them, which in turn, makes it easier to configure GitHub
147+
branch protection checks while the actual versions of tools are upgraded:
148+
149+
```yaml
150+
jobs:
151+
some-job:
152+
strategy:
153+
fail-fast: false
154+
matrix:
155+
k8s: [ v1.19, v1.18, v1.17, v1.16 ]
156+
name: K8s ${{ matrix.k8s }}
157+
runs-on: ubuntu-20.04
158+
steps:
159+
- uses: nolar/setup-k3d-k3s@v1
160+
with:
161+
version: ${{ matrix.k8s }}
162+
```
163+
164+
Multiple clusters in one job are possible, as long as there is enough memory
165+
(note: `k3d-` prefix is enforced by K3d):
166+
167+
```yaml
168+
jobs:
169+
some-job:
170+
name: Multi-cluster
171+
runs-on: ubuntu-20.04
172+
steps:
173+
- uses: nolar/setup-k3d-k3s@v1
174+
with:
175+
version: v1.16
176+
k3d-name: 1-16
177+
- uses: nolar/setup-k3d-k3s@v1
178+
with:
179+
version: v1.18
180+
k3d-name: 1-18
181+
- run: kubectl version --context k3d-1-16
182+
- run: kubectl version --context k3d-1-18
183+
```
184+
185+
Custom args can be passed to K3d (and through it, to K3s & K8s):
186+
187+
```yaml
188+
jobs:
189+
some-job:
190+
name: Custom args
191+
runs-on: ubuntu-20.04
192+
steps:
193+
- uses: nolar/setup-k3d-k3s@v1
194+
with:
195+
k3d-args: --servers 2 --no-lb
196+
- run: kubectl get nodes # there must be two of them
197+
```
198+
199+
For real-life examples, see:
200+
201+
* https://github.com/nolar/kopf/actions (all "K3s…" jobs).

0 commit comments

Comments
 (0)