Skip to content

Commit b40ab5a

Browse files
committed
WIP: k3d composite action
1 parent f0c2016 commit b40ab5a

File tree

2 files changed

+92
-35
lines changed

2 files changed

+92
-35
lines changed

.github/actions/k3d/action.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

.github/workflows/test.yaml

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,15 @@ jobs:
5656
- uses: actions/setup-go@v3
5757
with: { go-version: 1.x }
5858

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

0 commit comments

Comments
 (0)