Skip to content

Commit 19ff8e9

Browse files
committed
InitContainer to delete docker.sock if it's a directory
1 parent fb3c3c0 commit 19ff8e9

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

helm-chart/binderhub/templates/container-builder/daemonset.yaml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{- $builderName := .Values.imageBuilderType -}}
33
{{- $builder := index .Values $builderName -}}
44
{{- $daemonset := $builder.daemonset -}}
5+
{{- $hostSocketPath := printf "%s/%s" $builder.hostSocketDir $builder.hostSocketName }}
56

67
apiVersion: apps/v1
78
kind: DaemonSet
@@ -36,10 +37,33 @@ spec:
3637
value: user
3738
nodeSelector: {{ .Values.config.BinderHub.build_node_selector | toJson }}
3839

39-
{{- with $builder.initContainers }}
40+
{{- if or $builder.cleanupIncorrectSocketDir $builder.initContainers }}
4041
initContainers:
42+
{{- if $builder.cleanupIncorrectSocketDir }}
43+
- name: filesystem
44+
# Reuse the main container image since this is a simple shell command
45+
image: {{ $daemonset.image.name }}:{{ $daemonset.image.tag }}
46+
{{- with $daemonset.image.pullPolicy }}
47+
imagePullPolicy: {{ . }}
48+
{{- end }}
49+
command:
50+
- sh
51+
- -c
52+
- >
53+
if [ -d "{{ $hostSocketPath }}" ]; then
54+
echo "Removing incorrect socket directory {{ $hostSocketPath }}";
55+
rmdir "{{ $hostSocketPath }}"";
56+
fi
57+
securityContext:
58+
privileged: true
59+
volumeMounts:
60+
- name: run-{{ $builderName }}
61+
mountPath: {{ $builder.hostSocketDir }}
62+
{{- end }}
63+
{{- with $builder.initContainers }}
4164
{{- . | toYaml | nindent 8 }}
4265
{{- end }}
66+
{{- end }}
4367

4468
containers:
4569
- name: {{ $builderName }}
@@ -55,7 +79,7 @@ spec:
5579
args:
5680
- dockerd
5781
- --storage-driver={{ $builder.storageDriver }}
58-
- -H unix://{{ $builder.hostSocketDir }}/{{ $builder.hostSocketName }}
82+
- -H unix://{{ $hostSocketPath }}
5983
{{- with $daemonset.extraArgs }}
6084
{{- . | toYaml | nindent 12 }}
6185
{{- end }}
@@ -73,7 +97,7 @@ spec:
7397
- system
7498
- service
7599
- --time=0
76-
- unix://{{ $builder.hostSocketDir }}/{{ $builder.hostSocketName }}
100+
- unix://{{ $hostSocketPath }}
77101
{{- with $daemonset.extraArgs }}
78102
{{- . | toYaml | nindent 12 }}
79103
{{- end }}

helm-chart/binderhub/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ dind:
284284
lifecycle: {}
285285
extraVolumes: []
286286
extraVolumeMounts: []
287+
cleanupIncorrectSocketDir: true
287288
storageDriver: overlay2
288289
resources: {}
289290
hostSocketDir: /var/run/dind
@@ -302,6 +303,7 @@ pink:
302303
lifecycle: {}
303304
extraVolumes: []
304305
extraVolumeMounts: []
306+
cleanupIncorrectSocketDir: true
305307
resources: {}
306308
hostStorageDir: /var/lib/pink/storage
307309
hostSocketDir: /var/run/pink

0 commit comments

Comments
 (0)