Skip to content

Commit 8a09385

Browse files
committed
refactor(helm-chart): Simplify image-cleaner handling
This is a follow up of #1531. This patch refactors the creation and handling of the image cleaner daemonset. The current behaviour makes it so that if one doesn't disable the host cleaner explicitly when using dind (or pink), they would end up with two cleaners instead of one. The new behaviour avoids this issue by ensuring that only the container matching the selected imageBuilderType is created. Same goes for the volumes handling. In order to have consistent naming, the "local" imageBuilderType enumeration value is replaced with "host". It also deprecates the use of the imageCleaner.host.enabled parameter as you either want image cleanup or not.
1 parent 3de27f2 commit 8a09385

File tree

6 files changed

+36
-31
lines changed

6 files changed

+36
-31
lines changed

helm-chart/binderhub/schema.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ properties:
353353
354354
imageBuilderType:
355355
type: string
356-
enum: ["local", "dind", "pink"]
357-
default: "local"
356+
enum: ["host", "dind", "pink"]
357+
default: "host"
358358
description: |
359359
Selected image builder type
360360
@@ -470,12 +470,12 @@ properties:
470470
host:
471471
type: object
472472
additionalProperties: false
473-
required: [enabled, dockerSocket, dockerLibDir]
473+
required: [dockerSocket, dockerLibDir]
474474
properties:
475475
enabled:
476476
type: boolean
477477
description: |
478-
TODO
478+
DEPRECATED: use imageCleaner.enabled if the cleaner shall not used.
479479
dockerSocket:
480480
type: string
481481
description: |

helm-chart/binderhub/templates/NOTES.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ config:
190190
{{- $breaking = print $breaking "\n\nimageBuilderType: dind" }}
191191
{{- end }}
192192

193+
{{- if hasKey .Values.imageCleaner.host "enabled" }}
194+
{{- $breaking = print $breaking "\n\nCHANGED:" }}
195+
{{- $breaking = print $breaking "\n\nimageCleaner:" }}
196+
{{- $breaking = print $breaking "\n host:" }}
197+
{{- $breaking = print $breaking "\n enabled: true" }}
198+
{{- $breaking = print $breaking "\n\nas of version 0.3.0 is not used anymore." }}
199+
{{- $breaking = print $breaking "\n\nThe image cleaner is either disabled or adapted to the value of imageBuilderType." }}
200+
{{- end }}
201+
193202
{{- if $breaking }}
194203
{{- fail (print $breaking_title $breaking) }}
195204
{{- end }}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
{{- if ne .Values.imageBuilderType "local" -}}
1+
{{- if ne .Values.imageBuilderType "host" -}}
22
{{- $builderName := .Values.imageBuilderType -}}
3-
{{- $builder := index .Values $builderName -}}
3+
{{- $builder := (index .Values $builderName) -}}
44
{{- $daemonset := $builder.daemonset -}}
5+
56
apiVersion: apps/v1
67
kind: DaemonSet
78
metadata:

helm-chart/binderhub/templates/image-cleaner.yaml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{{- if .Values.imageCleaner.enabled -}}
22
{{- $Values := .Values -}}
3+
{{- $imageBuilderType := $Values.imageBuilderType -}}
4+
{{- $imageCleaner := $Values.imageCleaner -}}
35
apiVersion: apps/v1
46
kind: DaemonSet
57
metadata:
@@ -36,47 +38,43 @@ spec:
3638
serviceAccountName: {{ .Release.Name }}-image-cleaner
3739
{{- end }}
3840
containers:
39-
{{- range $i, $kind := tuple "host" "dind" "pink" }}
40-
{{- if or (and (eq $kind "dind") (eq $Values.imageBuilderType "dind")) (and (eq $kind "pink") (eq $Values.imageBuilderType "pink")) (and (eq $kind "host") $Values.imageCleaner.host.enabled) }}
41-
- name: image-cleaner-{{ $kind }}
42-
image: {{ $Values.imageCleaner.image.name }}:{{ $Values.imageCleaner.image.tag }}
43-
{{- with $Values.imageCleaner.image.pullPolicy }}
41+
- name: image-cleaner-{{ $imageBuilderType }}
42+
image: {{ $imageCleaner.image.name }}:{{ $imageCleaner.image.tag }}
43+
{{- with $imageCleaner.image.pullPolicy }}
4444
imagePullPolicy: {{ . }}
4545
{{- end }}
4646
volumeMounts:
47-
- name: storage-{{ $kind }}
48-
mountPath: /var/lib/{{ $kind }}
49-
- name: socket-{{ $kind }}
47+
- name: storage-{{ $imageBuilderType }}
48+
mountPath: /var/lib/{{ $imageBuilderType }}
49+
- name: socket-{{ $imageBuilderType }}
5050
mountPath: /var/run/docker.sock
5151
env:
5252
- name: DOCKER_IMAGE_CLEANER_NODE_NAME
5353
valueFrom:
5454
fieldRef:
5555
fieldPath: spec.nodeName
5656
- name: DOCKER_IMAGE_CLEANER_PATH_TO_CHECK
57-
value: /var/lib/{{ $kind }}
57+
value: /var/lib/{{ $imageBuilderType }}
5858
- name: DOCKER_IMAGE_CLEANER_DELAY_SECONDS
59-
value: {{ $Values.imageCleaner.delay | quote }}
59+
value: {{ $imageCleaner.delay | quote }}
6060
- name: DOCKER_IMAGE_CLEANER_THRESHOLD_TYPE
61-
value: {{ $Values.imageCleaner.imageGCThresholdType | quote }}
61+
value: {{ $imageCleaner.imageGCThresholdType | quote }}
6262
- name: DOCKER_IMAGE_CLEANER_THRESHOLD_HIGH
63-
value: {{ $Values.imageCleaner.imageGCThresholdHigh | quote }}
63+
value: {{ $imageCleaner.imageGCThresholdHigh | quote }}
6464
- name: DOCKER_IMAGE_CLEANER_THRESHOLD_LOW
65-
value: {{ $Values.imageCleaner.imageGCThresholdLow | quote }}
66-
{{- end }}
67-
{{- end }}
65+
value: {{ $imageCleaner.imageGCThresholdLow | quote }}
6866
terminationGracePeriodSeconds: 0
6967
volumes:
70-
{{- if .Values.imageCleaner.host.enabled }}
68+
{{- if eq $imageBuilderType "host" }}
7169
- name: storage-host
7270
hostPath:
73-
path: {{ .Values.imageCleaner.host.dockerLibDir }}
71+
path: {{ $imageCleaner.host.dockerLibDir }}
7472
- name: socket-host
7573
hostPath:
76-
path: {{ .Values.imageCleaner.host.dockerSocket }}
74+
path: {{ $imageCleaner.host.dockerSocket }}
7775
type: Socket
7876
{{- end }}
79-
{{- if eq $Values.imageBuilderType "dind" }}
77+
{{- if eq $imageBuilderType "dind" }}
8078
- name: storage-dind
8179
hostPath:
8280
path: {{ .Values.dind.hostLibDir }}
@@ -86,7 +84,7 @@ spec:
8684
path: {{ .Values.dind.hostSocketDir }}/docker.sock
8785
type: Socket
8886
{{- end }}
89-
{{- if eq $Values.imageBuilderType "pink" }}
87+
{{- if eq $imageBuilderType "pink" }}
9088
- name: storage-pink
9189
hostPath:
9290
path: {{ .Values.pink.hostStorageDir }}
@@ -96,5 +94,4 @@ spec:
9694
path: {{ .Values.pink.hostSocketDir }}/podman.sock
9795
type: Socket
9896
{{- end }}
99-
10097
{{- end }}

helm-chart/binderhub/values.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ deployment:
247247
timeoutSeconds: 10
248248
labels: {}
249249

250-
imageBuilderType: "local"
250+
imageBuilderType: "host"
251251

252252
dind:
253253
initContainers: []
@@ -300,7 +300,6 @@ imageCleaner:
300300
imageGCThresholdLow: 60
301301
# cull images on the host docker as well as dind
302302
host:
303-
enabled: true
304303
dockerSocket: /var/run/docker.sock
305304
dockerLibDir: /var/lib/docker
306305

tools/templates/lint-and-validate-values.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ deployment:
8686
livenessProbe: *probe
8787
labels: *labels
8888

89-
imageBuilderType: local
89+
imageBuilderType: host
9090

9191
dind:
9292
initContainers: &initContainers
@@ -128,7 +128,6 @@ imageCleaner:
128128
imageGCThresholdHigh: 2
129129
imageGCThresholdLow: 1
130130
host:
131-
enabled: true
132131
dockerSocket: /var/run/docker.sock
133132
dockerLibDir: /var/lib/docker
134133

0 commit comments

Comments
 (0)