Skip to content

Commit 0cbb6d7

Browse files
Refactor pgstacbootstrap job and ConfigMaps to use Helm hooks for execution order (#207)
* Refactor pgstacbootstrap job and ConfigMaps to use Helm hooks for execution order * Update PGO_VERSION to 5.7.4 in helm-tests workflow * Enhance debugging output for failed service boot and test failures in CI workflow * Remove unnecessary Helm hook annotations for deployment order management * ensure non empty annotations
1 parent f568a54 commit 0cbb6d7

File tree

4 files changed

+108
-29
lines changed

4 files changed

+108
-29
lines changed

.github/workflows/helm-tests.yml

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,40 @@ jobs:
118118
- name: cleanup if services fail to boot
119119
if: steps.watchservices.outcome == 'failure'
120120
run: |
121-
echo "The previous step failed or timed out."
121+
echo "The watchservices step failed or timed out. Extracting pod logs for debugging..."
122+
123+
# Get and display all pods status
124+
echo "===== Pod Status ====="
125+
kubectl get pods
126+
127+
# Extract logs from database pod
128+
echo "===== Database Pod Logs ====="
129+
kubectl get pod | grep "^db-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get database logs"
130+
131+
# Extract logs from pgstacbootstrap pod
132+
echo "===== PGSTACBootstrap Pod Logs ====="
133+
kubectl get pod | grep "^pgstacbootstrap-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get pgstacbootstrap logs"
134+
135+
# Extract logs from raster pod init container (wait-for-pgstacbootstrap)
136+
echo "===== Raster Pod Init Container Logs (wait-for-pgstacbootstrap) ====="
137+
kubectl get pod | grep "^raster-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} -c wait-for-pgstacbootstrap --tail=100 || echo "Could not get raster init container logs"
138+
139+
# Extract logs from raster pod main container
140+
echo "===== Raster Pod Main Container Logs ====="
141+
kubectl get pod | grep "^raster-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get raster main container logs"
142+
143+
# Extract logs from vector pod
144+
echo "===== Vector Pod Logs ====="
145+
kubectl get pod | grep "^vector-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get vector logs"
146+
147+
# Extract logs from stac pod
148+
echo "===== STAC Pod Logs ====="
149+
kubectl get pod | grep "^stac-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get STAC logs"
150+
151+
# Check if pods are in pending state or have issues
152+
echo "===== Pod Descriptions for Troubleshooting ====="
153+
kubectl get pod | grep "$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl describe pod/{} || echo "Could not describe pods"
154+
122155
# force GH action to show failed result
123156
exit 128
124157
@@ -145,18 +178,51 @@ jobs:
145178
echo $RASTER_ENDPOINT
146179
echo '#################################'
147180
148-
pytest .github/workflows/tests/test_vector.py || kubectl logs svc/vector-$RELEASE_NAME
149-
pytest .github/workflows/tests/test_stac.py
181+
pytest .github/workflows/tests/test_vector.py || kubectl logs svc/vector
182+
pytest .github/workflows/tests/test_stac.py || kubectl logs svc/stac
150183
# TODO: fix raster tests
151-
#pytest .github/workflows/tests/test_raster.py
184+
#pytest .github/workflows/tests/test_raster.py || kubectl logs svc/raster
152185
153186
- name: error if tests failed
154187
if: steps.testrunner.outcome == 'failure'
155188
run: |
156-
echo "The previous step failed or timed out."
189+
echo "The tests failed. Extracting pod logs for debugging..."
190+
191+
# Get and display all pods status
192+
echo "===== Pod Status ====="
193+
kubectl get pods
194+
195+
# Extract logs from database pod
196+
echo "===== Database Pod Logs ====="
197+
kubectl get pod | grep "^db-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get database logs"
198+
199+
# Extract logs from pgstacbootstrap pod
200+
echo "===== PGSTACBootstrap Pod Logs ====="
201+
kubectl get pod | grep "^pgstacbootstrap-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get pgstacbootstrap logs"
202+
203+
# Extract logs from raster pod init container (wait-for-pgstacbootstrap)
204+
echo "===== Raster Pod Init Container Logs (wait-for-pgstacbootstrap) ====="
205+
kubectl get pod | grep "^raster-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} -c wait-for-pgstacbootstrap --tail=100 || echo "Could not get raster init container logs"
206+
207+
# Extract logs from raster pod main container
208+
echo "===== Raster Pod Main Container Logs ====="
209+
kubectl get pod | grep "^raster-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get raster main container logs"
210+
211+
# Extract logs from vector pod
212+
echo "===== Vector Pod Logs ====="
213+
kubectl get pod | grep "^vector-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get vector logs"
214+
215+
# Extract logs from stac pod
216+
echo "===== STAC Pod Logs ====="
217+
kubectl get pod | grep "^stac-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get STAC logs"
218+
219+
# Check if pods are in pending state or have issues
220+
echo "===== Pod Descriptions for Troubleshooting ====="
221+
kubectl get pod | grep "$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl describe pod/{} || echo "Could not describe pods"
222+
157223
# force GH action to show failed result
158224
exit 128
159225
160226
- name: helm uninstall eoapi templates
161227
run: |
162-
helm uninstall $RELEASE_NAME
228+
helm uninstall $RELEASE_NAME

helm-chart/eoapi/templates/pgstacboostrap/configmap.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{{- if .Values.pgstacBootstrap.enabled }}
22
---
3+
# These ConfigMaps provide the necessary data and scripts for the pgstacbootstrap job.
4+
# They use Helm hooks with a weight of "-6" (lower than the job's "-5") to ensure
5+
# they are created before the job that depends on them.
36
apiVersion: v1
47
kind: ConfigMap
58
metadata:
69
name: initdb-sql-config-{{ $.Release.Name }}
10+
annotations:
11+
helm.sh/hook: "post-install,post-upgrade"
12+
helm.sh/hook-weight: "-6"
13+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
714
data:
815
initdb.sql: |
916
{{- range $path, $bytes := $.Files.Glob "initdb-data/*.sql" -}}
@@ -14,6 +21,10 @@ apiVersion: v1
1421
kind: ConfigMap
1522
metadata:
1623
name: initdb-json-config-{{ $.Release.Name }}
24+
annotations:
25+
helm.sh/hook: "post-install,post-upgrade"
26+
helm.sh/hook-weight: "-6"
27+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
1728
data:
1829
{{- range $path, $bytes := $.Files.Glob "initdb-data/*.json" -}}
1930
{{- base $path | nindent 2 -}}: | {{- $.Files.Get $path | nindent 4 -}}
@@ -23,6 +34,10 @@ apiVersion: v1
2334
kind: ConfigMap
2435
metadata:
2536
name: pgstac-setup-config-{{ $.Release.Name }}
37+
annotations:
38+
helm.sh/hook: "post-install,post-upgrade"
39+
helm.sh/hook-weight: "-6"
40+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
2641
data:
2742
pgstac-migrate.py: |
2843
{{- range $path, $bytes := $.Files.Glob "initdb-data/*.py" -}}
@@ -33,6 +48,10 @@ apiVersion: v1
3348
kind: ConfigMap
3449
metadata:
3550
name: initdb-sh-config-{{ $.Release.Name }}
51+
annotations:
52+
helm.sh/hook: "post-install,post-upgrade"
53+
helm.sh/hook-weight: "-6"
54+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
3655
data:
3756
run-forever.sh: |
3857
#!/bin/bash

helm-chart/eoapi/templates/pgstacboostrap/job.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
{{- if .Values.pgstacBootstrap.enabled }}
22
---
3+
# This job initializes the PostgreSQL database with the necessary schema and data.
4+
# Instead of using an initContainer in the deployment to wait for this job to complete,
5+
# we use Helm hooks to control the execution order:
6+
#
7+
# 1. The "post-install,post-upgrade" hook ensures this job runs after the postgres
8+
# dependency is installed but before other resources (like deployments)
9+
# 2. The "-5" hook-weight ensures this job runs after its ConfigMaps (weight -6)
10+
# 3. The "before-hook-creation,hook-succeeded" delete policy ensures the job is recreated
11+
# on each helm install/upgrade and is cleaned up after successful completion
12+
#
313
apiVersion: batch/v1
414
kind: Job
515
metadata:
616
name: pgstacbootstrap
717
labels:
818
app: pgstacbootstrap
19+
annotations:
20+
helm.sh/hook: "post-install,post-upgrade"
21+
helm.sh/hook-weight: "-5"
22+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
923
spec:
1024
template:
1125
metadata:
1226
labels:
1327
app: pgstacbootstrap
1428
spec:
1529
restartPolicy: Never
16-
initContainers:
17-
- name: wait-for-db
18-
image: busybox
19-
command:
20-
{{ if .Values.testing }}
21-
['sh', '-c', 'until nc -z {{ $.Release.Name }}-pgbouncer 5432; do echo waiting for db; sleep 10; done;']
22-
{{ else }}
23-
['sh', '-c', 'until nc -z eoapi-pgbouncer 5432; do echo waiting for db; sleep 10; done;']
24-
{{ end }}
2530
containers:
2631
- name: pgstacbootstrap
2732
image: {{ .Values.pgstacBootstrap.image.name }}:{{ .Values.pgstacBootstrap.image.tag }}

helm-chart/eoapi/templates/services/deployment.yaml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ metadata:
99
app: {{ $serviceName }}-{{ $.Release.Name }}
1010
gitsha: {{ $.Values.gitSha }}
1111
name: {{ $serviceName }}-{{ $.Release.Name }}
12-
{{- with index $v "annotations" }}
12+
{{- if index $v "annotations" }}
1313
annotations:
14+
{{- with index $v "annotations" }}
1415
{{- toYaml . | nindent 4 }}
16+
{{- end }}
1517
{{- end }}
1618
spec:
1719
progressDeadlineSeconds: 600
@@ -30,19 +32,6 @@ spec:
3032
app: {{ $serviceName }}-{{ $.Release.Name }}
3133
spec:
3234
serviceAccountName: eoapi-sa-{{ $.Release.Name }}
33-
initContainers:
34-
- name: wait-for-pgstacbootstrap
35-
image: bitnami/kubectl:latest
36-
command:
37-
- /bin/sh
38-
- -c
39-
- |
40-
echo "Waiting for pgstacbootstrap job to complete..."
41-
while ! kubectl -n {{ $.Release.Namespace }} wait --for=condition=complete job/pgstacbootstrap --timeout=5s; do
42-
echo "pgstacbootstrap job not completed yet. Checking again in 10 seconds..."
43-
sleep 10
44-
done
45-
echo "pgstacbootstrap job completed successfully"
4635
containers:
4736
- image: {{ index $v "image" "name" }}:{{ index $v "image" "tag" }}
4837
name: {{ $serviceName }}

0 commit comments

Comments
 (0)