-
Notifications
You must be signed in to change notification settings - Fork 7
205 lines (180 loc) · 6.64 KB
/
test_k3s.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Runs tests referencing the local GitHub Action to verify it works as intended.
---
name: Test
on:
pull_request:
push:
branches-ignore:
- "dependabot/**"
- "pre-commit-ci-update-config"
tags: ["**"]
workflow_dispatch:
jobs:
test_install_k3s:
runs-on: ubuntu-22.04
name: Test K3s and Helm
strategy:
fail-fast: false
matrix:
include:
- k3s-version: ""
k3s-channel: latest
helm-version: ""
metrics-enabled: "true"
traefik-enabled: "true"
docker-enabled: "false"
- k3s-version: ""
k3s-channel: latest
helm-version: ""
metrics-enabled: "false"
traefik-enabled: "false"
docker-enabled: "true"
- k3s-version: ""
k3s-channel: latest
helm-version: ""
metrics-enabled: "true"
traefik-enabled: "true"
docker-enabled: "true"
- k3s-version: ""
k3s-channel: latest
helm-version: ""
metrics-enabled: "false"
traefik-enabled: "false"
docker-enabled: "false"
- k3s-version: v1.24.7+k3s1
k3s-channel: ""
helm-version: v3.5.0
metrics-enabled: "true"
traefik-enabled: "true"
docker-enabled: "false"
- k3s-version: v1.24.7+k3s1
k3s-channel: ""
helm-version: v3.5.0
metrics-enabled: "false"
traefik-enabled: "false"
docker-enabled: "true"
steps:
- uses: actions/checkout@v4
- name: Local action
id: k3s
uses: ./
with:
k3s-version: ${{ matrix.k3s-version }}
k3s-channel: ${{ matrix.k3s-channel }}
helm-version: ${{ matrix.helm-version }}
metrics-enabled: ${{ matrix.metrics-enabled }}
traefik-enabled: ${{ matrix.traefik-enabled }}
docker-enabled: ${{ matrix.docker-enabled }}
- name: Verify action's outputs and env
run: |
echo "KUBECONFIG=${KUBECONFIG}"
echo "kubeconfig=${{ steps.k3s.outputs.kubeconfig }}"
echo "k3s-version=${{ steps.k3s.outputs.k3s-version }}"
echo "k8s-version=${{ steps.k3s.outputs.k8s-version }}"
echo "calico-version=${{ steps.k3s.outputs.calico-version }}"
echo "helm-version=${{ steps.k3s.outputs.helm-version }}"
echo "---"
EXIT=0
if [[ -z "${KUBECONFIG}" ]]; then
echo "KUBECONFIG not set as an environment variable"
EXIT=1
fi
if [[ -z "${{ steps.k3s.outputs.kubeconfig }}" ]]; then
echo "kubeconfig not set as an action output"
EXIT=1
fi
if [[ "${{ steps.k3s.outputs.k3s-version }}" != v* ]]; then
echo "k3s-version not set correctly as an action output"
EXIT=1
fi
if [[ "${{ steps.k3s.outputs.k8s-version }}" != v* ]]; then
echo "k8s-version not set correctly as an action output"
EXIT=1
fi
if [[ "${{ steps.k3s.outputs.calico-version }}" != v* ]]; then
echo "calico-version not set correctly as an action output"
EXIT=1
fi
if [[ "${{ steps.k3s.outputs.helm-version }}" != v* ]]; then
echo "helm-version not set correctly as an action output"
EXIT=1
fi
exit $EXIT
- name: Information from kubectl
run: |
kubectl version
kubectl get storageclass
kubectl get deploy,daemonset,pods --all-namespaces
- name: Information from docker
run: |
docker info
docker ps
- name: Information from helm
run: |
helm version
helm list
if helm version 2>&1 | grep WARNING > /dev/null; then
echo "helm is expected to run without a WARNING!"
exit 1
fi
- name: Verify deploy/metrics-server based on metrics-enabled input
run: |
kubectl get --namespace=kube-system deploy/metrics-server && enabled=true || enabled=false
if [[ "$enabled" != "${{ matrix.metrics-enabled }}" ]]; then
echo "ERROR: deploy/metrics-server detected or not, which broke an assumption"
exit 1
fi
- name: Verify deploy/traefik based on traefik-enabled input
run: |
kubectl get --namespace=kube-system deploy/traefik && enabled=true || enabled=false
if [[ "$enabled" != "${{ matrix.traefik-enabled }}" ]]; then
echo "ERROR: deploy/traefik detected or not, which broke an assumption"
exit 1
fi
# When using `docker-enabled: true` locally built images with docker
# should be available without loading them for use by the k3s CRI.
#
- name: Verify local image is available for the k8s cluster
if: matrix.docker-enabled == 'true'
run: |
docker pull busybox:latest
docker tag busybox:latest jupyterhub/action-k3s-helm:available-locally
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: image-available-locally
spec:
containers:
- name: image-available-locally
image: jupyterhub/action-k3s-helm:available-locally
args: ["sleep", "30"]
EOF
kubectl wait pod image-available-locally --for condition=Ready --timeout=30s
- name: Install netpol enforcement test chart
run: helm install test-netpol-enforcement ./test-netpol-enforcement --wait
- name: Run netpol enforcement test chart's tests
run: helm test test-netpol-enforcement --logs
# ref: https://github.com/jupyterhub/action-k8s-namespace-report
- name: Kubernetes namespace report (kube-system)
uses: jupyterhub/action-k8s-namespace-report@v1
if: always()
with:
namespace: kube-system
important-workloads: >
ds/calico-node
deploy/calico-kube-controllers
deploy/metrics-server
deploy/traefik
# Provides a single status_all check that can be used in GitHub branch
# protection rules instead of having to list each matrix job
# https://github.community/t/status-check-for-a-matrix-jobs/127354/7
status_all:
name: Status matrix Test
if: always()
runs-on: ubuntu-latest
needs: [test_install_k3s]
steps:
- name: Check build matrix status
if: needs.test_install_k3s.result != 'success'
run: exit 1