|
| 1 | +name: k3d |
| 2 | +description: Start k3s using k3d |
| 3 | +inputs: |
| 4 | + k3d-tag: |
| 5 | + default: latest |
| 6 | + required: true |
| 7 | + description: > |
| 8 | + Git tag from https://github.com/rancher/k3d/releases or "latest" |
| 9 | + k3s-channel: |
| 10 | + default: latest |
| 11 | + required: true |
| 12 | + description: > |
| 13 | + https://rancher.com/docs/k3s/latest/en/upgrades/basic/#release-channels |
| 14 | + prefetch-images: |
| 15 | + required: true |
| 16 | + description: > |
| 17 | + Each line is the name of an image to fetch onto all Kubernetes nodes |
| 18 | + prefetch-timeout: |
| 19 | + default: 90s |
| 20 | + required: true |
| 21 | + description: > |
| 22 | + Amount of time to wait for images to be fetched |
| 23 | +
|
| 24 | +outputs: |
| 25 | + kubernetes-version: |
| 26 | + value: ${{ steps.k3s.outputs.server }} |
| 27 | + description: > |
| 28 | + Kubernetes server version, as reported by the Kubernetes API |
| 29 | +
|
| 30 | +runs: |
| 31 | + using: composite |
| 32 | + steps: |
| 33 | + - id: k3d |
| 34 | + name: Install k3d |
| 35 | + shell: bash |
| 36 | + env: |
| 37 | + K3D_TAG: ${{ inputs.k3d-tag }} |
| 38 | + run: | |
| 39 | + curl --fail --silent https://raw.githubusercontent.com/rancher/k3d/main/install.sh | |
| 40 | + TAG="${K3D_TAG#latest}" bash |
| 41 | + k3d version | awk '{ print "::set-output name=" tolower($1) "::" $3 }' |
| 42 | +
|
| 43 | + - id: k3s |
| 44 | + name: Start k3s |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + k3d cluster create --image '+${{ inputs.k3s-channel }}' --no-lb --timeout=2m --wait |
| 48 | + kubectl version --short | awk '{ print "::set-output name=" tolower($1) "::" $3 }' |
| 49 | +
|
| 50 | + docker exec $(k3d node list --output json | jq --raw-output 'first.name') \ |
| 51 | + k3s agent --help | awk '$1 == "--pause-image" { |
| 52 | + match($0, /default: "[^"]*"/) |
| 53 | + print "::set-output name=pause-image::" substr($0, RSTART+10, RLENGTH-11) |
| 54 | + }' |
| 55 | +
|
| 56 | + - name: Prefetch container images |
| 57 | + shell: bash |
| 58 | + env: |
| 59 | + INPUT_IMAGES: ${{ inputs.prefetch-images }} |
| 60 | + INPUT_TIMEOUT: ${{ inputs.prefetch-timeout }} |
| 61 | + run: | |
| 62 | + jq <<< "$INPUT_IMAGES" --raw-input 'select(. != "")' | |
| 63 | + jq --slurp \ |
| 64 | + --arg pause '${{ steps.k3s.outputs.pause-image }}' \ |
| 65 | + --argjson labels '{"name":"image-prefetch"}' \ |
| 66 | + --argjson name '"image-prefetch"' \ |
| 67 | + '{ |
| 68 | + apiVersion: "apps/v1", kind: "DaemonSet", |
| 69 | + metadata: { name: $name, labels: $labels }, |
| 70 | + spec: { |
| 71 | + selector: { matchLabels: $labels }, |
| 72 | + template: { |
| 73 | + metadata: { labels: $labels }, |
| 74 | + spec: { |
| 75 | + initContainers: to_entries | map({ |
| 76 | + name: "c\(.key)", image: .value, command: ["true"], |
| 77 | + }), |
| 78 | + containers: [{ name: "pause", image: $pause }] |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + }' | |
| 83 | + kubectl create --filename=- |
| 84 | + kubectl rollout status daemonset.apps/image-prefetch --timeout "$INPUT_TIMEOUT" || |
| 85 | + kubectl describe daemonset.apps/image-prefetch |
0 commit comments