From 7ede1b347e950e8efc48712ced3ece3ac494b674 Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Mon, 4 Nov 2024 20:02:32 +0100 Subject: [PATCH] feat(helm): standalone garbage collection cronjob --- .../templates/garbage-collection-cron-job.yaml | 2 ++ .../templates/garbage-collection-role-binding.yaml | 2 ++ helm/kube-image-keeper/templates/garbage-collection-role.yaml | 2 ++ .../templates/garbage-collection-service-account.yaml | 2 ++ helm/kube-image-keeper/templates/registry-statefulset.yaml | 2 ++ helm/kube-image-keeper/values.yaml | 1 + 6 files changed, 11 insertions(+) diff --git a/helm/kube-image-keeper/templates/garbage-collection-cron-job.yaml b/helm/kube-image-keeper/templates/garbage-collection-cron-job.yaml index 9fa57d74..e1983262 100644 --- a/helm/kube-image-keeper/templates/garbage-collection-cron-job.yaml +++ b/helm/kube-image-keeper/templates/garbage-collection-cron-job.yaml @@ -1,3 +1,4 @@ +{{- if .Values.registry.garbageCollection.enabled }} {{- if and .Values.registry.garbageCollection.schedule (or .Values.registry.persistence.enabled (eq (include "kube-image-keeper.registry-stateless-mode" .) "true")) }} {{- if semverCompare ">=1.21-0" (default .Capabilities.KubeVersion.Version .Values.kubeVersion) -}} apiVersion: batch/v1 @@ -61,3 +62,4 @@ spec: kubectl rollout status sts {{ include "kube-image-keeper.fullname" . }}-registry {{- end }} {{- end }} +{{- end }} diff --git a/helm/kube-image-keeper/templates/garbage-collection-role-binding.yaml b/helm/kube-image-keeper/templates/garbage-collection-role-binding.yaml index ccad6ec1..99104f0d 100644 --- a/helm/kube-image-keeper/templates/garbage-collection-role-binding.yaml +++ b/helm/kube-image-keeper/templates/garbage-collection-role-binding.yaml @@ -1,3 +1,4 @@ +{{- if .Values.registry.garbageCollection.enabled }} {{- if .Values.registry.garbageCollection.schedule }} apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding @@ -13,3 +14,4 @@ subjects: name: {{ include "kube-image-keeper.fullname" . }}-registry-restart namespace: {{ .Release.Namespace }} {{- end }} +{{- end }} diff --git a/helm/kube-image-keeper/templates/garbage-collection-role.yaml b/helm/kube-image-keeper/templates/garbage-collection-role.yaml index 82fa720c..917f1243 100644 --- a/helm/kube-image-keeper/templates/garbage-collection-role.yaml +++ b/helm/kube-image-keeper/templates/garbage-collection-role.yaml @@ -1,3 +1,4 @@ +{{- if .Values.registry.garbageCollection.enabled }} {{- if .Values.registry.garbageCollection.schedule }} apiVersion: rbac.authorization.k8s.io/v1 kind: Role @@ -15,3 +16,4 @@ rules: resources: ["pods/exec"] verbs: ["create"] {{- end }} +{{- end }} diff --git a/helm/kube-image-keeper/templates/garbage-collection-service-account.yaml b/helm/kube-image-keeper/templates/garbage-collection-service-account.yaml index e2df42e9..83f04464 100644 --- a/helm/kube-image-keeper/templates/garbage-collection-service-account.yaml +++ b/helm/kube-image-keeper/templates/garbage-collection-service-account.yaml @@ -1,6 +1,8 @@ +{{- if .Values.registry.garbageCollection.enabled }} {{- if .Values.registry.garbageCollection.schedule }} kind: ServiceAccount apiVersion: v1 metadata: name: {{ include "kube-image-keeper.fullname" . }}-registry-restart {{- end }} +{{- end }} diff --git a/helm/kube-image-keeper/templates/registry-statefulset.yaml b/helm/kube-image-keeper/templates/registry-statefulset.yaml index 6077b5f6..31d33d12 100644 --- a/helm/kube-image-keeper/templates/registry-statefulset.yaml +++ b/helm/kube-image-keeper/templates/registry-statefulset.yaml @@ -50,6 +50,7 @@ spec: volumeMounts: - mountPath: /var/lib/registry name: data + {{- if .Values.registry.garbageCollection.enabled }} - name: garbage-collector image: "{{ .Values.registry.image.repository }}:{{ .Values.registry.image.tag }}" imagePullPolicy: {{ .Values.registry.image.pullPolicy }} @@ -63,6 +64,7 @@ spec: volumeMounts: - mountPath: /var/lib/registry name: data + {{- end }} {{- end }} containers: - name: registry diff --git a/helm/kube-image-keeper/values.yaml b/helm/kube-image-keeper/values.yaml index 15bdc7f2..5e648c4a 100644 --- a/helm/kube-image-keeper/values.yaml +++ b/helm/kube-image-keeper/values.yaml @@ -235,6 +235,7 @@ registry: azure: {} azureExistingSecret: "" garbageCollection: + enabled: true # -- Garbage collector cron schedule. Use standard crontab format. schedule: "0 0 * * 0" # -- If true, delete untagged manifests. Default to false since there is a known bug in **docker distribution** garbage collect job.