-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nolar/initial
Implement the action initially
- Loading branch information
Showing
7 changed files
with
463 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- release/** | ||
pull_request: | ||
branches: | ||
- master | ||
- release/** | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
|
||
test-latest: | ||
name: Install latest | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ # normally: nolar/setup-k3d-k3s@v1 | ||
- run: kubectl version | ||
|
||
test-specific: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
k3s: [v1.17.14+k3s2, v1.17.14, v1.17, v1] | ||
name: Install ${{ matrix.k3s }} | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ # normally: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: ${{ matrix.k3s }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
- run: kubectl version | ||
|
||
test-outputs: | ||
name: Check outputs | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ # normally: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: latest | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
id: install | ||
- run: echo K3S=${K3S} K8S=${K8S} | ||
env: | ||
K3S: ${{ steps.install.outputs.k3s-version }} | ||
K8S: ${{ steps.install.outputs.k8s-version }} | ||
|
||
test-skip-readiness: | ||
name: Skip readiness | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ # normally: nolar/setup-k3d-k3s@v1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
skip-readiness: true | ||
- run: kubectl version | ||
|
||
test-multi-cluster: | ||
name: Multi-cluster | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ # normally: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.16 | ||
k3d-name: 1-16 | ||
- uses: ./ # normally: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.18 | ||
k3d-name: 1-18 | ||
- run: kubectl version --context k3d-1-16 | ||
- run: kubectl version --context k3d-1-18 | ||
|
||
test-custom-args: | ||
name: Custom args | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ # normally: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.16 | ||
k3d-args: --servers 2 --no-lb | ||
- run: kubectl get nodes # there must be two of them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github: nolar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Sergey Vasilyev <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Sergey Vasilyev <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
# Setup K3d/K3s for GitHub Actions | ||
|
||
Install K3d/K3s and start a local Kubernetes cluster of a specific version. | ||
|
||
**K8s** is Kubernetes. | ||
**K3s** is a lightweight K8s distribution. | ||
**K3d** is a wrapper to run K3s in Docker. | ||
|
||
K3d/K3s are especially good for development and CI purposes, as it takes | ||
only 20-30 seconds of time till the cluster is ready. For comparison, | ||
Kind takes 1.5 minutes, Minikube takes 2 minutes till ready (as of Sep'2020). | ||
|
||
|
||
## Quick start | ||
|
||
Start with the simplest way: | ||
|
||
```yaml | ||
jobs: | ||
some-job: | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
``` | ||
Change versions with the verbose way: | ||
```yaml | ||
jobs: | ||
some-job: | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.19 # E.g.: v1.19, v1.19.4, v1.19.4+k3s1 | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
## Inputs | ||
### `version` | ||
|
||
**Required** version of Kubernetes and/or K3s -- either full or partial. | ||
|
||
The following notations are supported: | ||
|
||
* `v1.19.4+k3s1` | ||
* `v1.19.4` | ||
* `v1.19` | ||
* `v1` | ||
* `latest` | ||
|
||
Defaults to `latest`. | ||
|
||
Keep in mind that K3d dates back only to v1.16. | ||
There are no 1.15 and older versions of K8s. | ||
|
||
When the version is partial, the latest detected one will be used, | ||
as found in [K3s releases](https://github.com/rancher/k3s/releases), | ||
according to the basic semantical sorting (i.e. not by time of releasing). | ||
|
||
|
||
### `k3d-name` | ||
|
||
A name of the cluster to be created. | ||
|
||
By default (i.e. if no value is provided), K3d/K3s define their own name. | ||
Usually it is `k3d-k3s-default`. | ||
|
||
Note: the name should not include the `k3d-` prefix, but must be used with it. | ||
The `k3d-` prefix is enforced by K3d and cannot be disabled. | ||
|
||
|
||
### `k3d-args` | ||
|
||
Additional args to pass to K3d. | ||
See `k3d cluster create --help` for available flags. | ||
|
||
|
||
### `github-token` | ||
|
||
A token for GitHub API, which is used to avoid rate limiting. | ||
|
||
The API is used to fetch the releases from the K3s repository. | ||
|
||
By default, or if it is empty, then the API is accessed anonymously, | ||
which implies the limit of approximately 60 requests / 1 hour / 1 worker. | ||
|
||
Usage: | ||
|
||
```yaml | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
|
||
|
||
### `skip-readiness` | ||
|
||
Whether to return from the action as soon as possible, | ||
possibly providing a cluster that is only partially ready. | ||
|
||
By default (`false`), the readiness is awaited by checking for some preselected | ||
resources to appear (e.g., for a service account named "default"). | ||
|
||
|
||
## Outputs | ||
|
||
### `k3s-version` | ||
|
||
The specific K3s version that was detected and used. E.g. `v1.19.4+k3s1`. | ||
|
||
|
||
### `k8s-version` | ||
|
||
The specific K8s version that was detected and used. E.g. `v1.19.4`. | ||
|
||
|
||
## Examples | ||
|
||
With the latest version of K3s/K8s: | ||
|
||
```yaml | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
``` | ||
|
||
With the specific minor version of K8s, which implies the latest micro version | ||
of K8s and the latest possible version of K3s: | ||
|
||
```yaml | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.19 | ||
``` | ||
|
||
With the very specific version of K3s: | ||
|
||
```yaml | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.19.4+k3s1 | ||
``` | ||
|
||
The partial versions enable the build matrices with only the essential | ||
information in them, which in turn, makes it easier to configure GitHub | ||
branch protection checks while the actual versions of tools are upgraded: | ||
|
||
```yaml | ||
jobs: | ||
some-job: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
k8s: [ v1.19, v1.18, v1.17, v1.16 ] | ||
name: K8s ${{ matrix.k8s }} | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: ${{ matrix.k8s }} | ||
``` | ||
|
||
Multiple clusters in one job are possible, as long as there is enough memory | ||
(note: `k3d-` prefix is enforced by K3d): | ||
|
||
```yaml | ||
jobs: | ||
some-job: | ||
name: Multi-cluster | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.16 | ||
k3d-name: 1-16 | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.18 | ||
k3d-name: 1-18 | ||
- run: kubectl version --context k3d-1-16 | ||
- run: kubectl version --context k3d-1-18 | ||
``` | ||
|
||
Custom args can be passed to K3d (and through it, to K3s & K8s): | ||
|
||
```yaml | ||
jobs: | ||
some-job: | ||
name: Custom args | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
k3d-args: --servers 2 --no-lb | ||
- run: kubectl get nodes # there must be two of them | ||
``` | ||
|
||
For real-life examples, see: | ||
|
||
* https://github.com/nolar/kopf/actions (all "K3s…" jobs). |
Oops, something went wrong.