-
Notifications
You must be signed in to change notification settings - Fork 5
326 lines (276 loc) · 11.6 KB
/
helm-tests.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [ opened, reopened, synchronize, labeled ]
env:
HELM_VERSION: v3.15.2
PGO_VERSION: 5.5.2
jobs:
helm-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: d3adb5/helm-unittest-action@v2
with:
helm-version: ${{ env.HELM_VERSION }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: |
cd helm-chart
helm unittest eoapi -f 'tests/*.yaml' -v eoapi/test-helm-values.yaml
k3s-integration-tests:
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: 'read'
id-token: 'write'
needs: helm-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Start a local k3s cluster
uses: jupyterhub/action-k3s-helm@v4
with:
# See available:
# - k3s release channels at https://github.com/k3s-io/k3s/blob/HEAD/channel.yaml
# - k3s versions at https://github.com/k3s-io/k3s/tags
# - helm versions at https://github.com/helm/helm/tags
k3s-channel: latest
helm-version: ${{ env.HELM_VERSION }}
metrics-enabled: false
docker-enabled: true
- name: last commit sha if PR
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> ${GITHUB_ENV}
- name: last commit sha if push
if: ${{ github.event_name == 'push' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=${GITHUB_SHA}" >> ${GITHUB_ENV}
- name: set k8s .release.name suffix
run: |
# salt for randomness per test run
COMMITSHA=$(echo $LAST_COMMIT_SHA | cut -c 1-6)
SALT=$(echo "${RANDOM}${RANDOM}${RANDOM}" | cut -c1-3)
echo "RELEASE_NAME=eoapi$COMMITSHA$SALT" >> $GITHUB_ENV
- name: helm install crunchydata postgres operator
run: |
helm upgrade --install \
--set disable_check_for_upgrades=true \
pgo \
oci://registry.developers.crunchydata.com/crunchydata/pgo \
--version ${{ env.PGO_VERSION }}
- name: helm render/install eoapi templates
run: |
export GITSHA='${{github.sha}}'
cd helm-chart
helm dependency build eoapi
helm install $RELEASE_NAME \
--namespace default \
-f ./eoapi/values.yaml \
-f ./eoapi/test-k3s-unittest-values.yaml \
./eoapi
- name: sleep for 10s seconds while services boot
shell: bash
run: sleep 10s
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
- id: watchservices
name: watch services boot
timeout-minutes: 10
continue-on-error: true
run: |
kubectl config set-context --current --namespace=default
while [[ -z "$(kubectl get pod | grep "^raster-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "GET /.*/healthz" | head -n 1)" ]]; do
echo "still waiting for raster service to start..."
sleep 1
done
echo "raster service has started, moving on..."
while [[ -z "$(kubectl get pod | grep "^vector-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "GET /healthz" | head -n 1)" ]]; do
echo "still waiting for vector service to start..."
sleep 1
done
echo "vector service has started, moving on..."
while [[ -z "$(kubectl get pod | grep "^stac-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "GET /_mgmt/ping" | head -n 1)" ]]; do
echo "still waiting for stac service to start..."
sleep 1
done
echo "all services have started, moving on..."
- name: cleanup if services fail to boot
if: steps.watchservices.outcome == 'failure'
run: |
echo "The previous step failed or timed out."
# force GH action to show failed result
exit 128
- name: install python unit-test dependencies
run: |
python -m pip install pytest httpx
- name: run the tests
id: testrunner
continue-on-error: true
run: |
kubectl get svc --all-namespaces
kubectl get ingress --all-namespaces -o jsonpath='{range .items[0]}kubectl describe ingress {.metadata.name} -n {.metadata.namespace}{end}' | sh
kubectl get middleware.traefik.io --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' --no-headers | while read -r namespace name; do kubectl describe middleware.traefik.io "$name" -n "$namespace"; done
kubectl config set-context --current --namespace=default
PUBLICIP='http://'$(kubectl -n kube-system get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export VECTOR_ENDPOINT=$PUBLICIP/vector$RELEASE_NAME
export STAC_ENDPOINT=$PUBLICIP/stac$RELEASE_NAME
export RASTER_ENDPOINT=$PUBLICIP/raster$RELEASE_NAME
echo '#################################'
echo $VECTOR_ENDPOINT
echo $STAC_ENDPOINT
echo $RASTER_ENDPOINT
echo '#################################'
pytest .github/workflows/tests/test_vector.py || kubectl logs svc/vector-$RELEASE_NAME
pytest .github/workflows/tests/test_stac.py
# TODO: fix raster tests
#pytest .github/workflows/tests/test_raster.py
- name: error if tests failed
if: steps.testrunner.outcome == 'failure'
run: |
echo "The previous step failed or timed out."
# force GH action to show failed result
exit 128
- name: helm uninstall eoapi templates
run: |
helm uninstall $RELEASE_NAME
gcp-integration-tests:
# run on:
# - a PR was just labeled 'test-integration-gcp'
# - a PR was just labeled 'test-integration'
# - a PR with 'test-integration' label was opened, reopened, or synchronized
if: |
github.event.label.name == 'test-integration-gcp' ||
contains( github.event.pull_request.labels.*.name, 'test-integration-gcp')
permissions:
contents: 'read'
id-token: 'write'
needs: helm-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}
#token: ${{ secrets.GITHUB_TOKEN }}
- name: last commit sha if PR
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> ${GITHUB_ENV}
- name: last commit sha if push
if: ${{ github.event_name == 'push' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=${GITHUB_SHA}" >> ${GITHUB_ENV}
- name: set k8s .release.name suffix
run: |
# salt for randomness per test run
COMMITSHA=$(echo $LAST_COMMIT_SHA | cut -c 1-6)
SALT=$(echo "${RANDOM}${RANDOM}${RANDOM}" | cut -c1-3)
echo "RELEASE_NAME=eoapi$COMMITSHA$SALT" >> $GITHUB_ENV
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
service_account: 'k8seed-deploy@devseed-labs.iam.gserviceaccount.com'
credentials_json: ${{ secrets.GH_ACTIONS_SA_JSON }}
- name: setup gcloud sdk
uses: google-github-actions/setup-gcloud@v2
with:
version: '>= 363.0.0'
project_id: 'devseed-labs'
- name: configure kubectl context
run: |
gcloud components install gke-gcloud-auth-plugin
gcloud container clusters get-credentials k8seed-labs-cluster --zone us-central1-f
- name: helm install crunchydata postgres operator
run: |
helm upgrade --install \
--set disable_check_for_upgrades=true \
pgo \
oci://registry.developers.crunchydata.com/crunchydata/pgo \
--version ${{ env.PGO_VERSION }}
- name: helm render/install eoapi templates
run: |
HOST='${{ env.RELEASE_NAME }}.k8s.labs.ds.io'
echo $HOST
cd helm-chart
helm dependency build eoapi
helm install $RELEASE_NAME \
--namespace $RELEASE_NAME \
--create-namespace \
--set ingress.host=$HOST \
-f ./eoapi/values.yaml \
-f ./eoapi/test-gcp-unittest-values.yaml \
./eoapi
- name: sleep for 10s seconds while services boot
shell: bash
run: sleep 10s
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
- id: watchservices
name: watch services boot
timeout-minutes: 10
continue-on-error: true
run: |
kubectl config set-context --current --namespace=$RELEASE_NAME
while [[ -z "$(kubectl get pod | grep "^raster-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "GET /.*/healthz" | head -n 1)" ]]; do
echo "still waiting for raster service to start..."
sleep 1
done
echo "raster service has started, moving on..."
while [[ -z "$(kubectl get pod | grep "^vector-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "GET /healthz" | head -n 1)" ]]; do
echo "still waiting for vector service to start..."
sleep 1
done
echo "vector service has started, moving on..."
while [[ -z "$(kubectl get pod | grep "^stac-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "GET /_mgmt/ping" | head -n 1)" ]]; do
echo "still waiting for stac service to start..."
sleep 1
done
echo "all services have started, moving on..."
- name: cleanup if services fail to boot
if: steps.watchservices.outcome == 'failure'
run: |
echo "The previous step failed or timed out. Running cleanup logic..."
helm uninstall $RELEASE_NAME
kubectl delete ns/$RELEASE_NAME
# force GH action to show failed result
exit 128
- name: install python unit-test dependencies
run: |
python -m pip install pytest httpx
- name: run the tests
id: testrunner
continue-on-error: true
run: |
kubectl config set-context --current --namespace=$RELEASE_NAME
PUBLICIP='https://${{ env.RELEASE_NAME }}.k8s.labs.ds.io'
export VECTOR_ENDPOINT=$PUBLICIP/vector$RELEASE_NAME
export STAC_ENDPOINT=$PUBLICIP/stac$RELEASE_NAME
export RASTER_ENDPOINT=$PUBLICIP/raster$RELEASE_NAME
echo '#################################'
echo $VECTOR_ENDPOINT
echo $STAC_ENDPOINT
echo $RASTER_ENDPOINT
echo '#################################'
pytest .github/workflows/tests/test_vector.py
pytest .github/workflows/tests/test_stac.py
# TODO: fix raster tests
#pytest .github/workflows/tests/test_raster.py
- name: cleanup if tests fail
if: steps.testrunner.outcome == 'failure'
run: |
echo "The previous step failed or timed out. Running cleanup logic..."
helm uninstall $RELEASE_NAME
kubectl delete ns/$RELEASE_NAME
# force GH action to show failed result
exit 128
- name: helm uninstall eoapi templates
run: |
helm uninstall $RELEASE_NAME
kubectl delete ns/$RELEASE_NAME