From f82c3d8968b332ea40f05d97539a2a6dcb66af2a Mon Sep 17 00:00:00 2001 From: Aram Karapetyan Date: Mon, 27 Nov 2023 10:09:11 +0400 Subject: [PATCH 1/3] fix(DMVP-3131): Base chart add cronjob --- charts/base/Chart.yaml | 4 +- charts/base/templates/configmap.yml | 2 + charts/base/templates/cronjob/cronjob.yaml | 82 +++++++++++++++++++ .../templates/cronjob/cronjobstorage.yaml | 37 +++++++++ charts/base/templates/deployment.yaml | 2 + charts/base/templates/service.yaml | 2 + charts/base/templates/serviceaccount.yaml | 20 +++++ .../base/templates/tests/test-connection.yaml | 2 + charts/base/values.yaml | 40 +++++++++ 9 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 charts/base/templates/cronjob/cronjob.yaml create mode 100644 charts/base/templates/cronjob/cronjobstorage.yaml diff --git a/charts/base/Chart.yaml b/charts/base/Chart.yaml index e19f50c..a9b7625 100644 --- a/charts/base/Chart.yaml +++ b/charts/base/Chart.yaml @@ -15,10 +15,10 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.52 +version: 0.1.53 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.1.52" +appVersion: "0.1.53" diff --git a/charts/base/templates/configmap.yml b/charts/base/templates/configmap.yml index 6c29ebd..62bc1f4 100644 --- a/charts/base/templates/configmap.yml +++ b/charts/base/templates/configmap.yml @@ -1,9 +1,11 @@ +{{- if eq .Values.type "Deployment" -}} kind: ConfigMap apiVersion: v1 metadata: name: {{ include "base.fullname" . }} data: {{- toYaml .Values.config | nindent 2 }} +{{- end }} --- {{- if .Values.extraContainer.configmap }} diff --git a/charts/base/templates/cronjob/cronjob.yaml b/charts/base/templates/cronjob/cronjob.yaml new file mode 100644 index 0000000..9e08170 --- /dev/null +++ b/charts/base/templates/cronjob/cronjob.yaml @@ -0,0 +1,82 @@ +{{- if eq .Values.type "CronJob" -}} +{{- range $job := .Values.jobs }} +{{- $tag := $job.image.tag }} +{{- $image := print $job.image.repository ":" $tag }} +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ $job.name | quote}} +spec: + schedule: {{ $job.schedule | quote}} + jobTemplate: + spec: + template: + spec: + serviceAccountName: {{ $job.serviceAccount.name }} + restartPolicy: {{ $job.restartPolicy }} + containers: + - name: {{ $job.name | quote }} + image: {{ $image | quote}} + imagePullPolicy: IfNotPresent + {{- if $job.command }} + command: + {{- range $cmd := $job.command }} + - {{ $cmd }} + {{- end }} + {{- end }} + {{- if $job.args }} + args: + {{- range $args := $job.args }} + - {{ $args }} + {{- end }} + {{- end }} + {{ if $job.resources }} + resources: + requests: + cpu: {{ $job.resources.requests.cpu }} + memory: {{ $job.resources.requests.memory }} + limits: + cpu: {{ $job.resources.limits.cpu }} + memory: {{ $job.resources.limits.memory }} + {{ end }} + env: + {{- range $key, $value := $job.env }} + - name: {{ $key | quote}} + value: {{ $value | quote }} + {{- end }} + {{- if $job.volumes }} + volumeMounts: + {{- range $index, $element := $job.volumes }} + - name: {{ coalesce $element.name (add $index 1) }} + mountPath: {{ $element.mountPath }} + readOnly: {{ $element.readOnly | default false }} + {{- end }} + {{- end }} + {{- with $job.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 12 }} + {{- end }} + {{- with $job.affinity }} + affinity: +{{ toYaml . | indent 12 }} + {{- end }} + {{- with $job.tolerations }} + tolerations: +{{ toYaml . | indent 12 }} + {{- end }} + {{- if $job.volumes }} + volumes: + {{- range $index, $element := $job.volumes }} + - name: {{ coalesce $element.name (add $index 1) }} + {{- if $element.persistentVolumeClaim }} + persistentVolumeClaim: + {{- if $element.persistentVolumeClaim.claimName }} + claimName: {{ $element.persistentVolumeClaim.claimName }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +{{- end }} +--- +{{- end }} \ No newline at end of file diff --git a/charts/base/templates/cronjob/cronjobstorage.yaml b/charts/base/templates/cronjob/cronjobstorage.yaml new file mode 100644 index 0000000..b9c45f8 --- /dev/null +++ b/charts/base/templates/cronjob/cronjobstorage.yaml @@ -0,0 +1,37 @@ +{{- if eq .Values.type "CronJob" -}} +{{- range $job := .Values.jobs }} +{{- if $job.storage -}} +{{ range $storage := $job.storages }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ $storage.persistentVolumeClaimName }} + labels: +{{/* {{- include "base.labels" . | nindent 4 }}*/}} + {{- if $storage.keepPvc }} + annotations: + "helm.sh/resource-policy": keep + {{- end }} +spec: + {{- with $storage }} + accessModes: + {{- toYaml .accessModes | nindent 4 }} + volumeMode: {{ .volumeMode | default "Filesystem" }} + resources: + requests: + storage: {{ .requestedSize }} + {{- if .className }} + storageClassName: {{ .className }} + {{- end }} + {{- end }} + {{ if $storage.enableDataSource}} + dataSource: + kind: PersistentVolumeClaim + name: {{ $storage.persistentVolumeClaimName }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} +--- +{{- end }} \ No newline at end of file diff --git a/charts/base/templates/deployment.yaml b/charts/base/templates/deployment.yaml index e921135..833b68b 100644 --- a/charts/base/templates/deployment.yaml +++ b/charts/base/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.type "Deployment" -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -249,3 +250,4 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} +{{- end }} diff --git a/charts/base/templates/service.yaml b/charts/base/templates/service.yaml index a96ffaa..485082b 100644 --- a/charts/base/templates/service.yaml +++ b/charts/base/templates/service.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.type "Deployment" -}} {{- if .Values.service.enabled -}} apiVersion: v1 kind: Service @@ -19,3 +20,4 @@ spec: selector: {{- include "base.selectorLabels" . | nindent 4 }} {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/base/templates/serviceaccount.yaml b/charts/base/templates/serviceaccount.yaml index 7ff33c4..dd03717 100644 --- a/charts/base/templates/serviceaccount.yaml +++ b/charts/base/templates/serviceaccount.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.type "Deployment" -}} {{- if .Values.serviceAccount.create -}} apiVersion: v1 kind: ServiceAccount @@ -10,3 +11,22 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} {{- end }} +{{- end }} + +--- + +{{- if eq .Values.type "CronJob" -}} +{{- range $job := .Values.jobs }} +{{- if $job.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ $job.serviceAccount.name }} + labels: + {{- with $job.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/base/templates/tests/test-connection.yaml b/charts/base/templates/tests/test-connection.yaml index fcaf6ba..e942f83 100644 --- a/charts/base/templates/tests/test-connection.yaml +++ b/charts/base/templates/tests/test-connection.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.type "Deployment" -}} {{- if .Values.service.enabled -}} apiVersion: v1 kind: Pod @@ -15,3 +16,4 @@ spec: args: ['{{ include "base.fullname" . }}:{{ .Values.service.port }}'] restartPolicy: OnFailure {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/base/values.yaml b/charts/base/values.yaml index 280a127..ca19ae4 100644 --- a/charts/base/values.yaml +++ b/charts/base/values.yaml @@ -2,6 +2,8 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. +type: Deployment + replicaCount: 1 image: @@ -154,3 +156,41 @@ pdb: enabled: false minAvailable: 1 pdbName: + +jobs: {} +# - name: cronjob1 +# schedule: "0 * * * *" +# restartPolicy: OnFailure +# serviceAccount: +# create: true +# name: "sa-1" +# image: +# registry: docker.io +# repository: busybox +# pullPolicy: IfNotPresent +# tag: latest +# env: +# - name: key3 +# value: value3 +# - name: key4 +# value: value4 +# volumes: {} +# # - name: persistent-storage +# # mountPath: /path +# # persistentVolumeClaim: +# # claimName: claim +# storage: {} +# # persistentVolumeClaimName: claim +# # accessModes: +# # - ReadWriteMany +# # className: claim +# # requestedSize: 5Gi +# # enableDataSource: false + +# resources: {} +# # request: +# # cpu: 500m +# # memory: 5Gi +# # limits: +# # cpu: 500m +# # memory: 5Gi \ No newline at end of file From 14680b2e3dc096ef19c7494db7f88aaa903c1040 Mon Sep 17 00:00:00 2001 From: Aram Karapetyan Date: Mon, 27 Nov 2023 10:11:35 +0400 Subject: [PATCH 2/3] fix(DMVP-3131): Base chart add cronjob --- charts/base/README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/charts/base/README.md b/charts/base/README.md index 5c94a15..08aed28 100644 --- a/charts/base/README.md +++ b/charts/base/README.md @@ -462,4 +462,20 @@ base: app.kubernetes.io/name: base-fullname maxSkew: 2 topologyKey: kubernetes.io/hostname - whenUnsatisfiable: ScheduleAnyway \ No newline at end of file + whenUnsatisfiable: ScheduleAnyway + +### If you want create cronjob + jobs: + - name: events + schedule: "*/2 * * * *" + restartPolicy: OnFailure + serviceAccount: + create: false + image: + repository: dasmeta/events + tag: 0.1.18 + env: + HOST: "0.0.0.0" + PORT: "1337" + SERVE_ADMIN_PANEL: "true" + NODE_ENV: "production" From 355297ac9d74d30fc2ac022fd19beb7ffac10400 Mon Sep 17 00:00:00 2001 From: Aram Karapetyan Date: Mon, 27 Nov 2023 10:15:11 +0400 Subject: [PATCH 3/3] fix(DMVP-3131): Base chart add cronjob --- charts/base/templates/cronjob/cronjob.yaml | 2 +- charts/base/templates/cronjob/cronjobstorage.yaml | 2 +- charts/base/templates/service.yaml | 2 +- charts/base/templates/tests/test-connection.yaml | 2 +- charts/base/values.yaml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/charts/base/templates/cronjob/cronjob.yaml b/charts/base/templates/cronjob/cronjob.yaml index 9e08170..eeebfcc 100644 --- a/charts/base/templates/cronjob/cronjob.yaml +++ b/charts/base/templates/cronjob/cronjob.yaml @@ -79,4 +79,4 @@ spec: {{- end }} {{- end }} --- -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/base/templates/cronjob/cronjobstorage.yaml b/charts/base/templates/cronjob/cronjobstorage.yaml index b9c45f8..3b47ef1 100644 --- a/charts/base/templates/cronjob/cronjobstorage.yaml +++ b/charts/base/templates/cronjob/cronjobstorage.yaml @@ -34,4 +34,4 @@ spec: {{- end }} {{- end }} --- -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/base/templates/service.yaml b/charts/base/templates/service.yaml index 485082b..579bd1b 100644 --- a/charts/base/templates/service.yaml +++ b/charts/base/templates/service.yaml @@ -20,4 +20,4 @@ spec: selector: {{- include "base.selectorLabels" . | nindent 4 }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/base/templates/tests/test-connection.yaml b/charts/base/templates/tests/test-connection.yaml index e942f83..3c42471 100644 --- a/charts/base/templates/tests/test-connection.yaml +++ b/charts/base/templates/tests/test-connection.yaml @@ -16,4 +16,4 @@ spec: args: ['{{ include "base.fullname" . }}:{{ .Values.service.port }}'] restartPolicy: OnFailure {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/base/values.yaml b/charts/base/values.yaml index ca19ae4..037e705 100644 --- a/charts/base/values.yaml +++ b/charts/base/values.yaml @@ -193,4 +193,4 @@ jobs: {} # # memory: 5Gi # # limits: # # cpu: 500m -# # memory: 5Gi \ No newline at end of file +# # memory: 5Gi