Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 21 additions & 61 deletions .github/actions/install-k3s/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,33 @@ description: 'GitHub Action composite to install k3s'

inputs:
version:
description: 'k3s version. (e.g, v1.21.2-k3s1)'
description: 'k3s version. (e.g, v1.32.2+k3s1)'
required: true
default: 'v1.21.2-k3s1'
default: 'v1.32.2+k3s1'

runs:
using: "composite"
steps:
-
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');

let wait = function(milliseconds) {
return new Promise((resolve, reject) => {
if (typeof(milliseconds) !== 'number') {
throw new Error('milleseconds not a number');
}
setTimeout(() => resolve("done!"), milliseconds)
});
}

try {
const kubeconfig="${{ env.TEMPDIR }}/kubeconfig.yaml";
core.info(`storing kubeconfig in ${kubeconfig}`);

await exec.exec('docker', ["run", "-d",
"--privileged",
"--name=install-k3s-action",
"-e", "K3S_KUBECONFIG_OUTPUT="+kubeconfig,
"-e", "K3S_KUBECONFIG_MODE=666",
"-v", "${{ env.TEMPDIR }}:${{ env.TEMPDIR }}",
"-p", "6443:6443",
"-p", "80:80",
"-p", "443:443",
"-p", "8080:8080",
"rancher/k3s:${{ inputs.version }}",
"server"
]);
await wait(10000);

core.exportVariable('KUBECONFIG', kubeconfig);

let nodeName;
for (let count = 1; count <= ${{ env.RETRIES }}; count++) {
try {
const nodeNameOutput = await exec.getExecOutput("kubectl get nodes --no-headers -oname");
nodeName = nodeNameOutput.stdout
} catch (error) {
core.info(`Unable to resolve node name (${error.message}). Attempt ${count} of ${{ env.RETRIES }}.`)
} finally {
if (nodeName) {
break;
}
await wait(5000);
}
}
if (!nodeName) {
await exec.exec(`yq ${kubeconfig}`);
throw new Error(`Unable to resolve node name after ${{ env.RETRIES }} attempts.`);
}

await exec.exec(`kubectl wait --for=condition=Ready ${nodeName}`);
await exec.exec(`yq ${kubeconfig}`);
} catch (error) {
core.setFailed(error.message);
}
env:
TEMPDIR: /tmp/install-k3s-action
RETRIES: '10'
with:
script: |
const fs = require('fs');
const os = require('os');
const path = require('path');

const tmpDir = fs.mkdtempSync(path.join(`${{ runner.temp }}` || os.tmpdir(), 'install-k3s-'));
const kubeconfig = `${tmpDir}/kubeconfig.yaml`;
core.info(`Storing kubeconfig in ${kubeconfig}`);

await exec.exec('sh', ['-c', 'curl -sfL https://get.k3s.io | sh -'], {
env: Object.assign({}, process.env, {
INSTALL_K3S_VERSION: '${{ inputs.version }}',
INSTALL_K3S_EXEC: `--disable traefik --disable metrics-server --write-kubeconfig-mode 666 --write-kubeconfig ${kubeconfig}`,
})
});

core.exportVariable('KUBECONFIG', kubeconfig);
await exec.exec(`yq ${kubeconfig}`);
15 changes: 13 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,27 @@ jobs:
jq . buildx-releases-pin.json

install-k3s:
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- ubuntu-24.04
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Install k3s
uses: ./.github/actions/install-k3s
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v1.21.2-k3s1
driver: kubernetes
driver-opts: qemu.install=true
buildkitd-flags: --debug

list-commits:
uses: ./.github/workflows/list-commits.yml
Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Test
run: |
Expand All @@ -117,18 +117,13 @@ on:

jobs:
install-k3s:
# does not work with ubuntu-22.04 atm:
# E0310 17:16:57.210215 2047 memcache.go:238] couldn't get current server API group list: Get "https://127.0.0.1:6443/api?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Install k3s
uses: crazy-max/.github/.github/actions/install-k3s@main
with:
version: v1.21.2-k3s1
version: v1.32.2+k3s1
```

## Reusable workflows
Expand Down Expand Up @@ -163,7 +158,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ matrix.commit }}
```
Expand Down
Loading