Skip to content
Open
7 changes: 7 additions & 0 deletions .helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ Generage image reference based on image repository and tag
{{- printf "%s:%s" .Values.image.repository (default (printf "%s" .Chart.AppVersion) .Values.image.tag) }}
{{- end }}

{{/*
Generate garbage collector image reference based on image repository and tag
*/}}
{{- define "app.garbageCollectorImage" -}}
{{- printf "%s:%s" .Values.garbageCollector.image.repository (default (printf "%s" .Chart.AppVersion) .Values.garbageCollector.image.tag) }}
{{- end }}

{{/*
Generage common labels
*/}}
Expand Down
98 changes: 98 additions & 0 deletions .helm/templates/cron-job-garbage-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{{- if .Values.garbageCollector.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "app.name" . }}-garbage-collector
labels:
{{- include "app.labels" $ | nindent 4 }}
app.kubernetes.io/component: garbage-collector
{{- with .Values.additionalAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
schedule: {{ .Values.garbageCollector.schedule | quote }}
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: {{ .Values.garbageCollector.successfulJobsHistoryLimit | default 3 }}
failedJobsHistoryLimit: {{ .Values.garbageCollector.failedJobsHistoryLimit | default 1 }}
jobTemplate:
metadata:
labels:
{{- include "app.labels" $ | nindent 8 }}
app.kubernetes.io/component: garbage-collector
{{- with .Values.additionalAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
backoffLimit: {{ .Values.garbageCollector.backoffLimit | default 3 }}
template:
metadata:
labels:
{{- include "app.labels" $ | nindent 12 }}
app.kubernetes.io/component: garbage-collector
{{- with .Values.additionalAnnotations }}
annotations:
{{- toYaml . | nindent 12 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
serviceAccountName: {{ include "app.serviceAccountName" . }}
restartPolicy: {{ .Values.garbageCollector.restartPolicy | default "OnFailure" }}
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
containers:
- name: garbage-collector
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 14 }}
{{- end }}
image: "{{ include "app.garbageCollectorImage" . }}"
imagePullPolicy: "{{ .Values.garbageCollector.image.pullPolicy }}"
command:
- /bin/sh
- -c
- |
kubectl get backfillrequests --all-namespaces \
--field-selector spec.completed=true \
--sort-by=metadata.creationTimestamp \
--no-headers \
--output custom-columns="NAMESPACE:.metadata.namespace,NAME:.metadata.name" \
| head -n $HISTORY_LIMIT \
| xargs --no-run-if-empty -n2 kubectl delete backfillrequests --namespace
env:
- name: HISTORY_LIMIT
value: "{{ .Values.garbageCollector.historyLimit }}"
{{- if .Values.extraEnvFrom }}
envFrom:
{{- with .Values.extraEnvFrom }}
{{- toYaml . | nindent 14 }}
{{- end }}
{{- end }}
volumeMounts:
{{- with .Values.extraVolumeMounts }}
{{- toYaml . | nindent 14 }}
{{- end }}
{{- with .Values.garbageCollector.resources }}
resources:
{{- toYaml . | nindent 14 }}
{{- end }}
volumes:
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.garbageCollector.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.garbageCollector.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}

57 changes: 56 additions & 1 deletion .helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,59 @@ datadog:
disable_vendor_telemetry: true

# service environment tag
service_env: development
service_env: development

# Garbage collector configuration
garbageCollector:

# Enable garbage collector CronJob
enabled: false

# Image configuration for garbage collector
image:
# Repository to pull the image from
# Note: This image should contain the kubectl binary to allow the garbage collector to delete old BackfillRequest resources
# By default it is set to snd-cli-go, which is a lightweight image containing the kubectl binary and the SND CLI
# tool, but it can be overridden to use a custom image if needed
repository: "public.ecr.aws/ecco-sneaks-and-data/snd-cli-go"

# Tag to pull
tag: "1.3.4"

# Image pull policy
pullPolicy: "IfNotPresent"

# Cron schedule for the garbage collector (e.g., "0 2 * * *" for daily at 2 AM)
schedule: "0 2 * * *"

# Number of successful finished jobs to retain
successfulJobsHistoryLimit: 3

# Number of failed finished jobs to retain
failedJobsHistoryLimit: 1

# Number of retries before considering a job as failed
backoffLimit: 3

# Restart policy for the job (OnFailure, Never)
restartPolicy: "OnFailure"

# Maximum length of the BackfillRequest deletion history
historyLimit: 300

# Resource constraints for the garbage collector job
resources: {}
# Example:
#
# requests:
# cpu: 100m
# memory: 128Mi
# limits:
# cpu: 500m
# memory: 512Mi

# Node labels for pod assignment
tolerations: { }

# Node labels for pod assignment
affinity: { }
Loading