From 31c7a5595eaafd5681c12aff332ea2b023b77e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Guillot?= Date: Mon, 22 Apr 2024 16:04:44 +0200 Subject: [PATCH] feat(helm-chart): add server cleanup `CronJob` --- .../templates/server/cleanup.cron-job.yaml | 104 ++++++++++++++++++ apps/helm-chart/src/values.yaml | 25 +++++ 2 files changed, 129 insertions(+) create mode 100644 apps/helm-chart/src/templates/server/cleanup.cron-job.yaml diff --git a/apps/helm-chart/src/templates/server/cleanup.cron-job.yaml b/apps/helm-chart/src/templates/server/cleanup.cron-job.yaml new file mode 100644 index 00000000..85fcad79 --- /dev/null +++ b/apps/helm-chart/src/templates/server/cleanup.cron-job.yaml @@ -0,0 +1,104 @@ +{{- if .Values.server.cleanup.enabled }} +apiVersion: batch/v1 +kind: CronJob + +metadata: + {{- with (mergeOverwrite (deepCopy .Values.global.cronJobAnnotations) .Values.server.cronJobAnnotations) }} + annotations: + {{- range $key, $value := . }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} + name: {{ template "nx-cloud-ce.server.fullname" . }}-cleanup + namespace: {{ .Release.Namespace | quote }} + labels: + {{- include "nx-cloud-ce.labels" (dict "context" . "component" .Values.server.name "name" .Values.server.name) | nindent 4 }} + +spec: + schedule: {{ .Values.server.cleanup.schedule }} + successfulJobsHistoryLimit: {{ .Values.server.cleanup.successfulJobsHistoryLimit }} + failedJobsHistoryLimit: {{ .Values.server.cleanup.failedJobsHistoryLimit }} + concurrencyPolicy: "{{ .Values.server.cleanup.concurrencyPolicy }}" + jobTemplate: + spec: + {{- if .Values.server.cleanup.activeDeadlineSeconds }} + activeDeadlineSeconds: {{ .Values.server.cleanup.activeDeadlineSeconds }} + {{- end}} + template: + metadata: + annotations: + {{- with (mergeOverwrite (deepCopy .Values.global.podAnnotations) .Values.server.podAnnotations) }} + {{- range $key, $value := . }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} + labels: + {{- include "nx-cloud-ce.labels" (dict "context" . "component" .Values.server.name "name" .Values.server.name) | nindent 8 }} + {{- with (mergeOverwrite (deepCopy .Values.global.podLabels) .Values.server.podLabels) }} + {{- toYaml . | nindent 14 }} + {{- end }} + spec: + {{- with .Values.server.imagePullSecrets | default .Values.global.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.global.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + restartPolicy: Never + {{- if .Values.server.terminationGracePeriodSeconds }} + terminationGracePeriodSeconds: {{ .Values.server.terminationGracePeriodSeconds }} + {{- end }} + containers: + - name: {{ .Values.server.name }}-cleanup + image: {{ .Values.server.image.repository }}:{{ default (include "nx-cloud-ce.defaultTag" .) .Values.server.image.tag }} + imagePullPolicy: {{ default .Values.global.image.imagePullPolicy .Values.server.image.imagePullPolicy }} + args: + - "cleanup" + - "--days" + - {{ .Values.server.cleanup.days | quote }} + env: + {{- with (concat .Values.global.env .Values.server.env) }} + {{- toYaml . | nindent 16 }} + {{- end }} + - name: NX_SERVER_APPLICATION_URL + value: {{ .Values.global.domain }} + - name: QUARKUS_MONGODB_CONNECTION_STRING + {{- include "nx-cloud-ce.server.database.connection-string" . | nindent 18 }} + - name: QUARKUS_MONGODB_DATABASE + value: {{ .Values.server.name }} + {{- with .Values.server.envFrom }} + envFrom: + {{- toYaml . | nindent 16 }} + {{- end }} + volumeMounts: + - mountPath: /tmp + name: tmp + resources: + {{- toYaml .Values.server.resources | nindent 16 }} + {{- with .Values.server.containerSecurityContext }} + securityContext: + {{- toYaml . | nindent 16 }} + {{- end }} + {{- with include "nx-cloud-ce.affinity" (dict "context" . "component" .Values.server) }} + affinity: + {{- trim . | nindent 12 }} + {{- end }} + {{- with .Values.server.nodeSelector | default .Values.global.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.server.tolerations | default .Values.global.tolerations }} + tolerations: + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: tmp + {{- if .Values.server.emptyDir.sizeLimit }} + emptyDir: + sizeLimit: {{ .Values.server.emptyDir.sizeLimit }} + {{- else }} + emptyDir: { } + {{- end }} +{{- end }} diff --git a/apps/helm-chart/src/values.yaml b/apps/helm-chart/src/values.yaml index 333a09f4..400d673b 100644 --- a/apps/helm-chart/src/values.yaml +++ b/apps/helm-chart/src/values.yaml @@ -32,6 +32,9 @@ global: # -- Annotations for the all deployed Deployments deploymentAnnotations: {} + # -- Annotations for the all deployed Cron Jobs + cronJobAnnotations: {} + # -- Annotations for the all deployed pods podAnnotations: {} @@ -124,6 +127,9 @@ server: # -- Annotations to be added to server Deployment deploymentAnnotations: {} + # -- Annotations to be added to server Cron Jobs + cronJobAnnotations: {} + # -- Annotations to be added to server pods podAnnotations: {} @@ -197,6 +203,25 @@ server: sizeLimit: "" # sizeLimit: "1Gi" + ## Server clean-up cron job configuration + cleanup: + # -- Server clean-up enabled + enabled: true + # -- Server clean-up cron schedule expression + schedule: 0 0 * * * + # -- Server clean-up successful jobs history limit + successfulJobsHistoryLimit: 5 + # -- Server clean-up failed jobs history limit + failedJobsHistoryLimit: 5 + # -- Server clean-up active deadline seconds + activeDeadlineSeconds: 300 + # -- Server clean-up concurrent policy + concurrencyPolicy: Forbid + #-- Server clean-up concurrency + concurrency: 1 + # -- Server clean-up numbers of days to truncate on + days: 30 + ## Embedded MongoDB configuration (Bitnami Helm Chart) mongodb: # If `enabled`, Bitnami's chart is installed.