Skip to content
Closed
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
77 changes: 14 additions & 63 deletions .github/actions/install-k3s/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,24 @@ description: 'GitHub Action composite to install k3s'

inputs:
version:
description: 'k3s version. (e.g, v1.21.2-k3s1)'
description: 'k3s version. (e.g, v1.29.0+k3s1)'
required: true
default: 'v1.21.2-k3s1'
default: 'v1.29.0+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);
}
run: |
set -x
curl -sfL https://get.k3s.io | sh -s - server --docker --disable-network-policy --disable traefik --disable metrics-server --flannel-backend=none --write-kubeconfig-mode 666 || journalctl -xeu k3s.service --no-pager
sudo k3s kubectl get node

kubeConfig=${RUNNER_TEMP}/.kube/config
mkdir -p "${RUNNER_TEMP}/.kube"
echo "KUBECONFIG=${kubeConfig}" >> $GITHUB_ENV
sudo cat /etc/rancher/k3s/k3s.yaml > "${kubeConfig}"
chmod 600 "${kubeConfig}"
env:
TEMPDIR: /tmp/install-k3s-action
RETRIES: '10'
INSTALL_K3S_VERSION: ${{ inputs.version }}
shell: bash
11 changes: 8 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,21 @@ jobs:
jq . buildx-releases-pin.json

install-k3s:
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Install k3s
uses: ./.github/actions/install-k3s
with:
version: v1.21.2-k3s1

list-commits:
uses: ./.github/workflows/list-commits.yml
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ 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
Expand All @@ -128,7 +126,7 @@ jobs:
name: Install k3s
uses: crazy-max/.github/.github/actions/install-k3s@main
with:
version: v1.21.2-k3s1
version: v1.24.4+k3s1
```

## Reusable workflows
Expand Down
Loading