Skip to content

Commit 187473b

Browse files
committed
WIP: k3d composite action
1 parent 455bc3f commit 187473b

File tree

2 files changed

+83
-35
lines changed

2 files changed

+83
-35
lines changed

.github/actions/k3d/action.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
- name: Prefetch container images
51+
shell: bash
52+
env:
53+
INPUT_IMAGES: ${{ inputs.prefetch-images }}
54+
INPUT_TIMEOUT: ${{ inputs.prefetch-timeout }}
55+
run: |
56+
test "${INPUT_IMAGES//[[:space:]]}" || exit 0
57+
jq <<< "$INPUT_IMAGES" --raw-input 'select(. != "")' |
58+
jq --slurp --arg name 'image-prefetch' --argjson labels '{"name":"image-prefetch"}' '{
59+
apiVersion: "apps/v1", kind: "DaemonSet",
60+
metadata: { name: $name, labels: $labels },
61+
spec: {
62+
selector: { matchLabels: $labels },
63+
template: {
64+
metadata: { labels: $labels },
65+
spec: {
66+
initContainers: to_entries | map({
67+
name: "c\(.key)", image: .value, command: ["true"],
68+
}),
69+
containers: [{ name: "pause", image: "k8s.gcr.io/pause:3.5" }]
70+
}
71+
}
72+
}
73+
}' |
74+
kubectl create --filename=-
75+
kubectl rollout status daemonset.apps/image-prefetch --timeout "$INPUT_TIMEOUT" ||
76+
kubectl describe daemonset.apps/image-prefetch

.github/workflows/test.yaml

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,14 @@ jobs:
4646
- uses: actions/setup-go@v2
4747
with: { go-version: 1.x }
4848

49-
- name: Install k3d
50-
# Git tag from https://github.com/rancher/k3d/releases or "latest"
51-
env: { K3D_TAG: latest }
52-
run: |
53-
curl --fail --silent https://raw.githubusercontent.com/rancher/k3d/main/install.sh |
54-
TAG="${K3D_TAG#latest}" bash && k3d version | head -n1
55-
5649
- name: Start k3s
57-
# https://rancher.com/docs/k3s/latest/en/upgrades/basic/#release-channels
58-
env: { K3S_CHANNEL: "${{ matrix.kubernetes }}" }
59-
run: k3d cluster create --image="+${K3S_CHANNEL}" --no-lb --timeout=2m --wait
50+
uses: ./.github/actions/k3d
51+
with:
52+
k3s-channel: "${{ matrix.kubernetes }}"
53+
prefetch-images: |
54+
registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-13.5-0
55+
registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:centos8-2.36-0
56+
registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:centos8-1.16-0
6057
61-
- name: Prefetch container images
62-
run: |
63-
{
64-
echo '"registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-13.5-0"'
65-
echo '"registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:centos8-2.36-0"'
66-
echo '"registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:centos8-1.16-0"'
67-
} |
68-
jq --slurp --arg name 'image-prefetch' --argjson labels '{"name":"image-prefetch"}' '{
69-
apiVersion: "apps/v1", kind: "DaemonSet",
70-
metadata: { name: $name, labels: $labels },
71-
spec: {
72-
selector: { matchLabels: $labels },
73-
template: {
74-
metadata: { labels: $labels },
75-
spec: {
76-
initContainers: to_entries | map({ name: "c\(.key)", command: ["true"], image: .value }),
77-
containers: [{ name: "pause", image: "k8s.gcr.io/pause:3.5" }]
78-
}
79-
}
80-
}
81-
}' |
82-
kubectl create --filename=- && {
83-
kubectl rollout status daemonset.apps/image-prefetch --timeout=90s ||
84-
kubectl describe daemonset.apps/image-prefetch
85-
}
8658
- env: { PGO_TEST_TIMEOUT_SCALE: 1.2 }
8759
run: make createnamespaces check-envtest-existing

0 commit comments

Comments
 (0)