diff --git a/.github/actions/install-k3s/action.yml b/.github/actions/install-k3s/action.yml index bff3ae5..b408ef5 100644 --- a/.github/actions/install-k3s/action.yml +++ b/.github/actions/install-k3s/action.yml @@ -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}`); diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61a1aa0..1926b38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -86,7 +86,13 @@ 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 @@ -94,8 +100,13 @@ jobs: - 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 diff --git a/README.md b/README.md index c615741..79cde42 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test run: | @@ -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 @@ -163,7 +158,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ matrix.commit }} ```