From a95a3480c6c12c8a21d34001b2bcebbe402ee16f Mon Sep 17 00:00:00 2001 From: Vladimir Kuznichenkov Date: Sat, 18 Sep 2021 12:37:50 +0300 Subject: [PATCH] Garbage collector job to keep registry tiny We don't have unlimited storage, and we would like to run built-in garbage collector to keep storage usage low. --- Chart.yaml | 2 +- README.md | 3 +++ templates/cronjob.yaml | 47 ++++++++++++++++++++++++++++++++++++++++++ values.yaml | 5 +++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 templates/cronjob.yaml diff --git a/Chart.yaml b/Chart.yaml index df95853..b875fc6 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 description: A Helm chart for Docker Registry name: docker-registry -version: 1.13.0 +version: 1.14.0 appVersion: 2.7.1 home: https://hub.docker.com/_/registry/ icon: https://helm.twun.io/docker-registry.png diff --git a/README.md b/README.md index 440667d..889916a 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ their default values. | `ingress.tls` | Ingress TLS configuration (YAML) | `[]` | | `extraVolumeMounts` | Additional volumeMounts to the registry container | `[]` | | `extraVolumes` | Additional volumes to the pod | `[]` | +| `garbageCollect.enabled` | If true, will deploy garbage-collector cronjob | `false` | +| `garbageCollect.deleteUntagged` | If true, garbage-collector will delete manifests that are not currently referenced via tag | `true` | | +| `garbageCollect.schedule` | CronTab schedule, please use standard crontab format | `0 1 * * *` | | Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. diff --git a/templates/cronjob.yaml b/templates/cronjob.yaml new file mode 100644 index 0000000..6cf1253 --- /dev/null +++ b/templates/cronjob.yaml @@ -0,0 +1,47 @@ +{{- if .Values.garbageCollect.enabled }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ template "docker-registry.fullname" . }}-garbage-collector + labels: + app: {{ template "docker-registry.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + schedule: {{ .Values.garbageCollect.schedule | quote }} + jobTemplate: + spec: + template: + spec: + {{- if .Values.imagePullSecrets }} + imagePullSecrets: {{ toYaml .Values.imagePullSecrets | nindent 12 }} + {{- end }} + {{- if .Values.securityContext.enabled }} + securityContext: + fsGroup: {{ .Values.securityContext.fsGroup }} + runAsUser: {{ .Values.securityContext.runAsUser }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - /bin/registry + - garbage-collect + - --delete-untagged={{ .Values.garbageCollect.deleteUntagged }} + - /etc/docker/registry/config.yml + env: {{ include "docker-registry.envs" . | nindent 16 }} + volumeMounts: {{ include "docker-registry.volumeMounts" . | nindent 16 }} + restartPolicy: OnFailure + {{- if .Values.nodeSelector }} + nodeSelector: {{ toYaml .Values.nodeSelector | nindent 12 }} + {{- end }} + {{- if .Values.affinity }} + affinity: {{ toYaml .Values.affinity | nindent 12 }} + {{- end }} + {{- if .Values.tolerations }} + tolerations: {{ toYaml .Values.tolerations | nindent 12 }} + {{- end }} + volumes: {{ include "docker-registry.volumes" . | nindent 12 }} +{{- end }} diff --git a/values.yaml b/values.yaml index e239d58..92116aa 100644 --- a/values.yaml +++ b/values.yaml @@ -166,3 +166,8 @@ extraVolumes: [] # - key: cloudfront.pem # path: cloudfront.pem # mode: 511 + +garbageCollect: + enabled: false + deleteUntagged: true + schedule: "0 1 * * *"