Skip to content

Commit bde2bb7

Browse files
Detach loop devices post shutdown
Add sidecar container teardown Monitor Concourse processes post shutdown and detach main container loop devices left alone. Disk space is released on the node from the dead pod. Signed-off-by: David Rozé <droze@baylibre.com>
1 parent 50a9472 commit bde2bb7

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

templates/worker-configmap.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,30 @@ data:
2424
fi
2525
done
2626
done
27+
teardown-entrypoint.sh: |
28+
#!/usr/bin/sh
29+
apk add --no-cache losetup
30+
while true; do
31+
pid=$(pgrep -o -f "entrypoint.sh worker")
32+
# Get loop devices from the main container and store them
33+
nsenter --mount=/proc/${pid}/ns/mnt mount | grep loop | cut -d\ -f1 > /tmp/loopdev.txt
34+
sleep 60
35+
done
36+
teardown-pre-stop-hook.sh: |
37+
#!/usr/bin/sh
38+
while true; do
39+
if ! pgrep concourse >/dev/null 2>&1; then
40+
41+
# Wait until filesystem is no longer busy
42+
while (lsof | grep "${CONCOURSE_WORK_DIR}/volumes") >/dev/null 2>&1; do
43+
sleep 1
44+
done
45+
46+
# Detach main container loop devices
47+
cat /tmp/loopdev.txt | xargs -r -n1 losetup -d
48+
49+
exit 0
50+
fi
51+
52+
sleep 1
53+
done

templates/worker-deployment.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ spec:
108108
{{- end }}
109109
securityContext:
110110
privileged: true
111+
shareProcessNamespace: true
111112
volumeMounts:
112113
- name: concourse-keys
113114
mountPath: {{ .Values.worker.keySecretsPath | quote }}
@@ -128,6 +129,34 @@ spec:
128129
- name: concourse-work-dir
129130
mountPath: {{ .Values.concourse.worker.workDir | quote }}
130131
{{- end }}
132+
- name: teardown
133+
image: cgr.dev/chainguard/wolfi-base
134+
command: ["/usr/bin/sh", "-c", "sh /entrypoint.sh"]
135+
lifecycle:
136+
preStop:
137+
exec:
138+
command:
139+
- "/usr/bin/sh"
140+
- "-c"
141+
- "sh /pre-stop-hook.sh 2>&1"
142+
env:
143+
{{- if .Values.concourse.worker.workDir }}
144+
- name: CONCOURSE_WORK_DIR
145+
value: {{ .Values.concourse.worker.workDir | quote }}
146+
{{- end }}
147+
securityContext:
148+
privileged: true
149+
volumeMounts:
150+
- name: concourse-worker
151+
mountPath: /entrypoint.sh
152+
subPath: teardown-entrypoint.sh
153+
- name: concourse-worker
154+
mountPath: /pre-stop-hook.sh
155+
subPath: teardown-pre-stop-hook.sh
156+
{{- if include "concourse.are-there-additional-volumes.with-the-name.concourse-work-dir" . | not }}
157+
- name: concourse-work-dir
158+
mountPath: {{ .Values.concourse.worker.workDir | quote }}
159+
{{- end }}
131160

132161
{{- if .Values.worker.additionalVolumeMounts }}
133162
{{ toYaml .Values.worker.additionalVolumeMounts | indent 12 }}

0 commit comments

Comments
 (0)