From 197af27e26376c6d544d01c583ca6f9b60ba49cd Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Mon, 17 Jan 2022 15:45:46 +0200 Subject: [PATCH 01/10] Add pvc for static files --- .../smartbirds-server/templates/_helpers.tpl | 24 +++++++++++++++++++ .../templates/deployment.yaml | 15 +++++++++--- .../templates/pvc-static.yaml | 21 ++++++++++++++++ .../templates/pvc-uploads.yaml | 21 ++++++++++++++++ charts/smartbirds-server/templates/pvc.yaml | 21 ---------------- charts/smartbirds-server/values.yaml | 20 ++++++++++++---- 6 files changed, 93 insertions(+), 29 deletions(-) create mode 100644 charts/smartbirds-server/templates/pvc-static.yaml create mode 100644 charts/smartbirds-server/templates/pvc-uploads.yaml delete mode 100644 charts/smartbirds-server/templates/pvc.yaml diff --git a/charts/smartbirds-server/templates/_helpers.tpl b/charts/smartbirds-server/templates/_helpers.tpl index 7c27e9d..8fdf634 100644 --- a/charts/smartbirds-server/templates/_helpers.tpl +++ b/charts/smartbirds-server/templates/_helpers.tpl @@ -23,6 +23,30 @@ If release name contains chart name it will be used as a full name. {{- end }} {{- end }} +{{/* +Create a default fully qualified static name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "smartbirds-server.static.fullname" -}} +{{- if .Values.static.fullnameOverride -}} +{{- .Values.static.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" (include "smartbirds-server.fullname" .) .Values.static.name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} + +{{/* +Create a default fully qualified uploads name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "smartbirds-server.uploads.fullname" -}} +{{- if .Values.uploads.fullnameOverride -}} +{{- .Values.uploads.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" (include "smartbirds-server.fullname" .) .Values.uploads.name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} + {{/* Create chart name and version as used by the chart label. */}} diff --git a/charts/smartbirds-server/templates/deployment.yaml b/charts/smartbirds-server/templates/deployment.yaml index 6c53309..a70ae4c 100644 --- a/charts/smartbirds-server/templates/deployment.yaml +++ b/charts/smartbirds-server/templates/deployment.yaml @@ -102,16 +102,25 @@ spec: volumeMounts: - mountPath: /app/uploads/files name: uploads + - mountPath: /app/public + name: static resources: {{- toYaml .Values.resources | nindent 12 }} volumes: - name: uploads - {{- if .Values.persistence.enabled }} + {{- if .Values.uploads.persistence.enabled }} persistentVolumeClaim: - claimName: {{ .Values.persistence.existingClaim | default (include "smartbirds-server.fullname" .) }} + claimName: {{ .Values.uploads.persistence.existingClaim | default (include "smartbirds-server.uploads.fullname" .) }} {{- else }} emptyDir: {} - {{- end -}} + {{- end }} + - name: static + {{- if .Values.static.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ .Values.static.persistence.existingClaim | default (include "smartbirds-server.static.fullname" .) }} + {{- else }} + emptyDir: {} + {{- end }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/charts/smartbirds-server/templates/pvc-static.yaml b/charts/smartbirds-server/templates/pvc-static.yaml new file mode 100644 index 0000000..cc9a803 --- /dev/null +++ b/charts/smartbirds-server/templates/pvc-static.yaml @@ -0,0 +1,21 @@ +{{- if and .Values.static.persistence.enabled (not .Values.static.persistence.existingClaim) }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "smartbirds-server.static.fullname" . }} + labels: + {{- include "smartbirds-server.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.static.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.static.persistence.size | quote }} +{{- if .Values.static.persistence.storageClass }} +{{- if (eq "-" .Values.static.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.static.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/smartbirds-server/templates/pvc-uploads.yaml b/charts/smartbirds-server/templates/pvc-uploads.yaml new file mode 100644 index 0000000..a3bd7dd --- /dev/null +++ b/charts/smartbirds-server/templates/pvc-uploads.yaml @@ -0,0 +1,21 @@ +{{- if and .Values.uploads.persistence.enabled (not .Values.uploads.persistence.existingClaim) }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "smartbirds-server.uploads.fullname" . }} + labels: + {{- include "smartbirds-server.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.uploads.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.uploads.persistence.size | quote }} +{{- if .Values.uploads.persistence.storageClass }} +{{- if (eq "-" .Values.uploads.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.uploads.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/smartbirds-server/templates/pvc.yaml b/charts/smartbirds-server/templates/pvc.yaml deleted file mode 100644 index 09c2fd2..0000000 --- a/charts/smartbirds-server/templates/pvc.yaml +++ /dev/null @@ -1,21 +0,0 @@ -{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "smartbirds-server.fullname" . }} - labels: - {{- include "smartbirds-server.labels" . | nindent 4 }} -spec: - accessModes: - - {{ .Values.persistence.accessMode | quote }} - resources: - requests: - storage: {{ .Values.persistence.size | quote }} -{{- if .Values.persistence.storageClass }} -{{- if (eq "-" .Values.persistence.storageClass) }} - storageClassName: "" -{{- else }} - storageClassName: "{{ .Values.persistence.storageClass }}" -{{- end }} -{{- end }} -{{- end }} diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 3376d99..0e52b73 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -14,11 +14,21 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" -persistence: - enabled: true - accessMode: ReadWriteMany - existingClaim: "" - size: 8Gi +uploads: + name: "uploads" + persistence: + enabled: true + accessMode: ReadWriteMany + existingClaim: "" + size: 8Gi + +static: + name: "static" + persistence: + enabled: true + accessMode: ReadWriteMany + existingClaim: "" + size: 1Gi serviceAccount: # Specifies whether a service account should be created From 954d390cc7534d445578be901f2cae9ef8d7b8c8 Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Mon, 17 Jan 2022 17:51:19 +0200 Subject: [PATCH 02/10] Create cronjob to export organizations --- .../templates/cronjobs/organizations.tpl | 66 +++++++++++++++++++ charts/smartbirds-server/values.yaml | 32 +++++++++ 2 files changed, 98 insertions(+) create mode 100644 charts/smartbirds-server/templates/cronjobs/organizations.tpl diff --git a/charts/smartbirds-server/templates/cronjobs/organizations.tpl b/charts/smartbirds-server/templates/cronjobs/organizations.tpl new file mode 100644 index 0000000..5fc43b8 --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/organizations.tpl @@ -0,0 +1,66 @@ +{{- if and .Values.cron.enabled .Values.cron.organizations.enabled -}} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "smartbirds-server.fullname" . }}-organizations-exporter + labels: + {{- include "smartbirds-server.labels" . | nindent 4 }} +spec: + concurrencyPolicy: {{ .Values.cron.organizations.concurency }} + schedule: {{ .Values.cron.organizations.schedule | quote }} + successfulJobsHistoryLimit: {{ .Values.cron.organizations.historyLimit }} + jobTemplate: + spec: + template: + metadata: + labels: + {{- include "smartbirds-server.labels" . | nindent 12 }} + app.kubernetes.io/component: organizations-exporter + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 12 }} + {{- end }} + restartPolicy: OnFailure + serviceAccountName: {{ include "smartbirds-server.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 12 }} + containers: + - name: {{ .Chart.Name }}-organizations-exporter + securityContext: + {{- toYaml .Values.securityContext | nindent 16 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - /usr/local/bin/npm + - run + - ah + - -- + - task + - enqueue + - --name=organizations:export + env: + - name: NODE_ENV + value: production + - name: DATABASE_URL + value: "postgres://{{ .Values.postgresql.postgresqlUsername }}:{{ .Values.postgresql.postgresqlPassword }}@{{ .Release.Name }}-postgresql:{{ .Values.postgresql.containerPorts.postgresql }}/{{ .Values.postgresql.postgresqlDatabase }}" + - name: REDIS_HOST + value: "{{ .Release.Name }}-redis-master" + - name: REDIS_PASS + valueFrom: + secretKeyRef: + name: "{{ .Release.Name }}-redis" + key: "redis-password" + {{- if .Values.smartbirds.serverToken }} + - name: SERVER_TOKEN + value: {{ .Values.smartbirds.serverToken | quote }} + {{- end }} + {{- if .Values.smartbirds.sentry.enabled }} + - name: SENTRY_DSN + value: {{ .Values.smartbirds.sentry.dsn | quote }} + {{- end }} + + {{- if .Values.cron.organizations.resources }} + resources: {{- toYaml .Values.cron.organizations.resources | nindent 16 }} + {{- end }} +{{- end }} diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 0e52b73..0db43b4 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -30,6 +30,38 @@ static: existingClaim: "" size: 1Gi +cron: + enabled: true + organizations: + enabled: true + concurency: Forbid + ## @param cron.organizations.schedule Schedule in Cron format to generate organizations export + ## See https://en.wikipedia.org/wiki/Cron + ## + schedule: "* * * * *" + ## @param cron.organizations.historyLimit Number of successful finished jobs to retain + ## + historyLimit: 1 + ## @param cron.organizations.snapshotHistoryLimit Number of etcd snapshots to retain, tagged by date + ## + snapshotHistoryLimit: 1 + ## Configure resource requests and limits for organization-exporter containers + ## ref: https://kubernetes.io/docs/user-guide/compute-resources/ + ## We usually recommend not to specify default resources and to leave this as a conscious + ## choice for the user. This also increases chances charts run on environments with little + ## resources, such as Minikube. If you do want to specify resources, uncomment the following + ## lines, adjust them as necessary, and remove the curly braces after 'resources:'. + ## @param cron.organizations.resources.limits [object] Cronjob container resource limits + ## @param cron.organizations.resources.requests [object] Cronjob container resource requests + ## + resources: + ## Example: + ## limits: + ## cpu: 500m + ## memory: 1Gi + limits: { } + requests: { } + serviceAccount: # Specifies whether a service account should be created create: true From c88e2b13a637377742c8d4cf21da4ca61052fe17 Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Mon, 17 Jan 2022 20:58:42 +0200 Subject: [PATCH 03/10] Refactor cronjobs and add test --- charts/smartbirds-server/ci/ct-values.yaml | 4 ++ .../templates/_containers.tpl | 37 ++++++++++ .../smartbirds-server/templates/_cronjobs.tpl | 55 +++++++++++++++ .../templates/cronjobs/organizations.tpl | 67 +------------------ .../templates/deployment.yaml | 26 +------ .../templates/tests/test-connection.yaml | 6 +- charts/smartbirds-server/values.yaml | 8 +-- 7 files changed, 106 insertions(+), 97 deletions(-) create mode 100644 charts/smartbirds-server/templates/_containers.tpl create mode 100644 charts/smartbirds-server/templates/_cronjobs.tpl diff --git a/charts/smartbirds-server/ci/ct-values.yaml b/charts/smartbirds-server/ci/ct-values.yaml index 32266bc..9076571 100644 --- a/charts/smartbirds-server/ci/ct-values.yaml +++ b/charts/smartbirds-server/ci/ct-values.yaml @@ -1,2 +1,6 @@ persistence: accessMode: ReadWriteOnce + +cron: + organizations: + schedule: "* * * * *" diff --git a/charts/smartbirds-server/templates/_containers.tpl b/charts/smartbirds-server/templates/_containers.tpl new file mode 100644 index 0000000..9180dac --- /dev/null +++ b/charts/smartbirds-server/templates/_containers.tpl @@ -0,0 +1,37 @@ +{{/* +Define container image and pull policy +Usage: +{{ include "smartbirds-server.container.image" (dict "values" .Values.image "ctx" $) }} +*/}} +{{- define "smartbirds-server.container.image" -}} +{{- $values := default .values .ctx.Values.image -}} +image: "{{ $values.repository }}:{{ $values.tag | default .ctx.Chart.AppVersion }}" +imagePullPolicy: {{ $values.pullPolicy }} +{{- end -}} + +{{/* +Define common container environment +Usage: +{{ include "smartbirds-server.container.common-env" $ }} +*/}} +{{- define "smartbirds-server.container.common-env" -}} +- name: NODE_ENV + value: production +- name: DATABASE_URL + value: "postgres://{{ $.Values.postgresql.postgresqlUsername }}:{{ $.Values.postgresql.postgresqlPassword }}@{{ $.Release.Name }}-postgresql:{{ $.Values.postgresql.containerPorts.postgresql }}/{{ $.Values.postgresql.postgresqlDatabase }}" +- name: REDIS_HOST + value: "{{ $.Release.Name }}-redis-master" +- name: REDIS_PASS + valueFrom: + secretKeyRef: + name: "{{ $.Release.Name }}-redis" + key: "redis-password" +{{- if $.Values.smartbirds.serverToken }} +- name: SERVER_TOKEN + value: {{ $.Values.smartbirds.serverToken | quote }} +{{- end }} +{{- if $.Values.smartbirds.sentry.enabled }} +- name: SENTRY_DSN + value: {{ $.Values.smartbirds.sentry.dsn | quote }} +{{- end }} +{{- end -}} diff --git a/charts/smartbirds-server/templates/_cronjobs.tpl b/charts/smartbirds-server/templates/_cronjobs.tpl new file mode 100644 index 0000000..d19fe59 --- /dev/null +++ b/charts/smartbirds-server/templates/_cronjobs.tpl @@ -0,0 +1,55 @@ +{{/* +Create a complete cronjob definition to enqueue task +Usage: +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "job-name" "taskName" "task-name" "args" (dict "opt1" "val1) "values" .Values.cronjob.task-name "ctx" $) }} +*/}} +{{- define "smartbirds-server.cronjob.enqueue" -}} +{{- if and .ctx.Values.cron.enabled .values.enabled -}} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "smartbirds-server.fullname" .ctx }}-{{ .name }} + labels: + {{- include "smartbirds-server.labels" .ctx | nindent 4 }} +spec: + concurrencyPolicy: {{ .values.concurency }} + schedule: {{ .values.schedule | quote }} + successfulJobsHistoryLimit: {{ .values.historyLimit | default 1 }} + jobTemplate: + spec: + template: + metadata: + labels: + {{- include "smartbirds-server.labels" .ctx | nindent 12 }} + app.kubernetes.io/component: enqueue-{{ .name }} + spec: + {{- with .ctx.Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 12 }} + {{- end }} + restartPolicy: {{ .values.restartPolicy | default "OnFailure" }} + serviceAccountName: {{ include "smartbirds-server.serviceAccountName" .ctx }} + securityContext: + {{- toYaml .ctx.Values.podSecurityContext | nindent 12 }} + containers: + - name: {{ .ctx.Chart.Name }}-enqueue-{{ .name }} + securityContext: {{- toYaml (default .values.securityContext .ctx.Values.securityContext) | nindent 16 }} + {{- include "smartbirds-server.container.image" (dict "ctx" .ctx) | nindent 14 }} + command: + - /usr/local/bin/npm + - run + - ah + - -- + - task + - enqueue + - --name={{ .taskName }} + {{- if .args }} + - --args={{ toJson .args }} + {{- end }} + env: + {{- include "smartbirds-server.container.common-env" .ctx | nindent 16 }} + {{- if .values.resources }} + resources: {{- toYaml .values.resources | nindent 16 }} + {{- end }} +{{- end }} +{{- end -}} diff --git a/charts/smartbirds-server/templates/cronjobs/organizations.tpl b/charts/smartbirds-server/templates/cronjobs/organizations.tpl index 5fc43b8..f044f7e 100644 --- a/charts/smartbirds-server/templates/cronjobs/organizations.tpl +++ b/charts/smartbirds-server/templates/cronjobs/organizations.tpl @@ -1,66 +1 @@ -{{- if and .Values.cron.enabled .Values.cron.organizations.enabled -}} -apiVersion: batch/v1 -kind: CronJob -metadata: - name: {{ include "smartbirds-server.fullname" . }}-organizations-exporter - labels: - {{- include "smartbirds-server.labels" . | nindent 4 }} -spec: - concurrencyPolicy: {{ .Values.cron.organizations.concurency }} - schedule: {{ .Values.cron.organizations.schedule | quote }} - successfulJobsHistoryLimit: {{ .Values.cron.organizations.historyLimit }} - jobTemplate: - spec: - template: - metadata: - labels: - {{- include "smartbirds-server.labels" . | nindent 12 }} - app.kubernetes.io/component: organizations-exporter - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - restartPolicy: OnFailure - serviceAccountName: {{ include "smartbirds-server.serviceAccountName" . }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 12 }} - containers: - - name: {{ .Chart.Name }}-organizations-exporter - securityContext: - {{- toYaml .Values.securityContext | nindent 16 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - command: - - /usr/local/bin/npm - - run - - ah - - -- - - task - - enqueue - - --name=organizations:export - env: - - name: NODE_ENV - value: production - - name: DATABASE_URL - value: "postgres://{{ .Values.postgresql.postgresqlUsername }}:{{ .Values.postgresql.postgresqlPassword }}@{{ .Release.Name }}-postgresql:{{ .Values.postgresql.containerPorts.postgresql }}/{{ .Values.postgresql.postgresqlDatabase }}" - - name: REDIS_HOST - value: "{{ .Release.Name }}-redis-master" - - name: REDIS_PASS - valueFrom: - secretKeyRef: - name: "{{ .Release.Name }}-redis" - key: "redis-password" - {{- if .Values.smartbirds.serverToken }} - - name: SERVER_TOKEN - value: {{ .Values.smartbirds.serverToken | quote }} - {{- end }} - {{- if .Values.smartbirds.sentry.enabled }} - - name: SENTRY_DSN - value: {{ .Values.smartbirds.sentry.dsn | quote }} - {{- end }} - - {{- if .Values.cron.organizations.resources }} - resources: {{- toYaml .Values.cron.organizations.resources | nindent 16 }} - {{- end }} -{{- end }} +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "organizations" "taskName" "organizations:export" "values" .Values.cron.organizations "ctx" $) }} diff --git a/charts/smartbirds-server/templates/deployment.yaml b/charts/smartbirds-server/templates/deployment.yaml index a70ae4c..c4aec35 100644 --- a/charts/smartbirds-server/templates/deployment.yaml +++ b/charts/smartbirds-server/templates/deployment.yaml @@ -29,34 +29,18 @@ spec: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: {{- toYaml .Values.securityContext | nindent 12 }} + {{- include "smartbirds-server.container.image" (dict "ctx" $) | nindent 10 }} ports: - name: http containerPort: 5000 protocol: TCP env: - - name: NODE_ENV - value: production + {{- include "smartbirds-server.container.common-env" $ | nindent 12 }} - name: PORT value: "5000" - - name: DATABASE_URL - value: "postgres://{{ .Values.postgresql.postgresqlUsername }}:{{ .Values.postgresql.postgresqlPassword }}@{{ .Release.Name }}-postgresql:{{ .Values.postgresql.containerPorts.postgresql }}/{{ .Values.postgresql.postgresqlDatabase }}" - - name: REDIS_HOST - value: "{{ .Release.Name }}-redis-master" - - name: REDIS_PASS - valueFrom: - secretKeyRef: - name: "{{ .Release.Name }}-redis" - key: "redis-password" - name: ORPHAN_OWNER value: {{ .Values.smartbirds.orphanOwner | quote }} - {{- if .Values.smartbirds.serverToken }} - - name: SERVER_TOKEN - value: {{ .Values.smartbirds.serverToken | quote }} - {{- end }} {{- if .Values.smartbirds.session.duration }} - name: SESSION_DURATION value: {{ .Values.smartbirds.session.duration | quote }} @@ -87,10 +71,6 @@ spec: - name: MAILCHIMP_LIST_ID value: {{ .Values.smartbirds.mailchimp.listId | quote }} {{- end }} - {{- if .Values.smartbirds.sentry.enabled }} - - name: SENTRY_DSN - value: {{ .Values.smartbirds.sentry.dsn | quote }} - {{- end }} livenessProbe: httpGet: path: /api/status diff --git a/charts/smartbirds-server/templates/tests/test-connection.yaml b/charts/smartbirds-server/templates/tests/test-connection.yaml index ed148de..a99a41b 100644 --- a/charts/smartbirds-server/templates/tests/test-connection.yaml +++ b/charts/smartbirds-server/templates/tests/test-connection.yaml @@ -8,8 +8,12 @@ metadata: "helm.sh/hook": test spec: containers: - - name: wget + - name: api-status image: busybox command: ['wget'] args: ['{{ include "smartbirds-server.fullname" . }}:{{ .Values.service.port }}/api/status'] + - name: organizations + image: busybox + command: ['wget'] + args: ['{{ include "smartbirds-server.fullname" . }}:{{ .Values.service.port }}/organizations.json'] restartPolicy: Never diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 0db43b4..eae7d0d 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -38,13 +38,7 @@ cron: ## @param cron.organizations.schedule Schedule in Cron format to generate organizations export ## See https://en.wikipedia.org/wiki/Cron ## - schedule: "* * * * *" - ## @param cron.organizations.historyLimit Number of successful finished jobs to retain - ## - historyLimit: 1 - ## @param cron.organizations.snapshotHistoryLimit Number of etcd snapshots to retain, tagged by date - ## - snapshotHistoryLimit: 1 + schedule: "*/17 * * * *" ## Configure resource requests and limits for organization-exporter containers ## ref: https://kubernetes.io/docs/user-guide/compute-resources/ ## We usually recommend not to specify default resources and to leave this as a conscious From 193ebebed9df2f381b14ce9e3fce28346447ad5c Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Mon, 17 Jan 2022 21:01:41 +0200 Subject: [PATCH 04/10] Bump version --- charts/smartbirds-server/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/smartbirds-server/Chart.yaml b/charts/smartbirds-server/Chart.yaml index 357ed3e..0b3ff68 100644 --- a/charts/smartbirds-server/Chart.yaml +++ b/charts/smartbirds-server/Chart.yaml @@ -15,7 +15,7 @@ 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.2 +version: 0.1.3 # 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 From f8bff65154be62161778240b8f5519a1bd24a42b Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Mon, 17 Jan 2022 21:06:08 +0200 Subject: [PATCH 05/10] Fix lint issues --- charts/smartbirds-server/values.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index eae7d0d..72b56a8 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -53,8 +53,8 @@ cron: ## limits: ## cpu: 500m ## memory: 1Gi - limits: { } - requests: { } + limits: {} + requests: {} serviceAccount: # Specifies whether a service account should be created From cbeef78e5c73b67dc6cd003008f0f7751a864b7e Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Mon, 17 Jan 2022 22:05:48 +0200 Subject: [PATCH 06/10] Add tests for stats export --- charts/smartbirds-server/Chart.yaml | 2 +- charts/smartbirds-server/ci/ct-values.yaml | 4 +++ .../templates/cronjobs/banner.tpl | 1 + .../templates/cronjobs/mailchimp.tpl | 1 + .../templates/cronjobs/stats.tpl | 1 + .../cronjobs/tests/test-connection.yaml | 34 +++++++++++++++++++ .../templates/tests/test-connection.yaml | 4 --- charts/smartbirds-server/values.yaml | 13 +++++++ 8 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 charts/smartbirds-server/templates/cronjobs/banner.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/mailchimp.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/stats.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml diff --git a/charts/smartbirds-server/Chart.yaml b/charts/smartbirds-server/Chart.yaml index 0b3ff68..9de07d4 100644 --- a/charts/smartbirds-server/Chart.yaml +++ b/charts/smartbirds-server/Chart.yaml @@ -15,7 +15,7 @@ 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.3 +version: 0.2.0 # 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 diff --git a/charts/smartbirds-server/ci/ct-values.yaml b/charts/smartbirds-server/ci/ct-values.yaml index 9076571..5800724 100644 --- a/charts/smartbirds-server/ci/ct-values.yaml +++ b/charts/smartbirds-server/ci/ct-values.yaml @@ -4,3 +4,7 @@ persistence: cron: organizations: schedule: "* * * * *" + stats: + schedule: "* * * * *" + banners: + schedule: "* * * * *" diff --git a/charts/smartbirds-server/templates/cronjobs/banner.tpl b/charts/smartbirds-server/templates/cronjobs/banner.tpl new file mode 100644 index 0000000..77159bb --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/banner.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "banners" "taskName" "banner:generate" "values" .Values.cron.banners "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/mailchimp.tpl b/charts/smartbirds-server/templates/cronjobs/mailchimp.tpl new file mode 100644 index 0000000..86b703e --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/mailchimp.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "mailchimp" "taskName" "stats:mailchimp" "values" .Values.cron.mailchimp "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/stats.tpl b/charts/smartbirds-server/templates/cronjobs/stats.tpl new file mode 100644 index 0000000..87e637a --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/stats.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "stats" "taskName" "stats:generate" "values" .Values.cron.stats "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml b/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml new file mode 100644 index 0000000..c180146 --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml @@ -0,0 +1,34 @@ +{{- $files := list -}} +{{- $files = append $files "organizations" -}} +{{- $files = append $files "birds_stats" -}} +{{- $files = append $files "cbm_stats" -}} +{{- $files = append $files "ciconia_stats" -}} +{{- $files = append $files "mammals_stats" -}} +{{- $files = append $files "invertebrates_stats" -}} +{{- $files = append $files "plants_stats" -}} +{{- $files = append $files "threats_stats" -}} +{{- $files = append $files "user_rank_stats" -}} +{{- $files = append $files "total_user_records_stats" -}} +{{- $files = append $files "birds_top_stats" -}} +{{- $files = append $files "herptiles_top_stats" -}} +{{- $files = append $files "mammals_top_stats" -}} +{{- $files = append $files "plants_top_stats" -}} +{{- $files = append $files "invertebrates_top_stats" -}} +{{- $files = append $files "bgatlas2008_global_stats" -}} +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "smartbirds-server.fullname" . }}-test-cronjobs" + labels: + {{- include "smartbirds-server.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + {{- range $name := $files }} + - name: {{ regexReplaceAll "_" $name "-" }} + image: busybox + command: ['wget'] + args: ['{{ include "smartbirds-server.fullname" $ }}:{{ $.Values.service.port }}/{{ $name }}.json'] + {{- end }} + restartPolicy: Never diff --git a/charts/smartbirds-server/templates/tests/test-connection.yaml b/charts/smartbirds-server/templates/tests/test-connection.yaml index a99a41b..774c011 100644 --- a/charts/smartbirds-server/templates/tests/test-connection.yaml +++ b/charts/smartbirds-server/templates/tests/test-connection.yaml @@ -12,8 +12,4 @@ spec: image: busybox command: ['wget'] args: ['{{ include "smartbirds-server.fullname" . }}:{{ .Values.service.port }}/api/status'] - - name: organizations - image: busybox - command: ['wget'] - args: ['{{ include "smartbirds-server.fullname" . }}:{{ .Values.service.port }}/organizations.json'] restartPolicy: Never diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 72b56a8..9e4e5a1 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -55,6 +55,19 @@ cron: ## memory: 1Gi limits: {} requests: {} + stats: + enabled: true + concurency: Forbid + schedule: "43 * * * *" + banners: + enabled: true + concurency: Forbid + schedule: "25 3 * * *" + mailchimp: + enabled: true + concurency: Forbid + schedule: "35 3 * * *" + serviceAccount: # Specifies whether a service account should be created From 392a752b9d7d66bb922fcb150f3ece370d0f004e Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Thu, 20 Jan 2022 17:57:29 +0200 Subject: [PATCH 07/10] Add remaining cronjobs and checks --- charts/smartbirds-server/ci/ct-values.yaml | 4 +++ .../templates/cronjobs/atlas-bspb-stats.tpl | 1 + .../templates/cronjobs/bgatlas2008.tpl | 1 + .../templates/cronjobs/locations.tpl | 1 + .../templates/cronjobs/modreview.tpl | 1 + .../cronjobs/tests/test-connection.yaml | 22 +++++++++------- .../templates/cronjobs/utmcode.tpl | 1 + .../templates/cronjobs/visits.tpl | 1 + charts/smartbirds-server/values.yaml | 26 ++++++++++++++++++- 9 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/locations.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/modreview.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/utmcode.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs/visits.tpl diff --git a/charts/smartbirds-server/ci/ct-values.yaml b/charts/smartbirds-server/ci/ct-values.yaml index 5800724..5109dd1 100644 --- a/charts/smartbirds-server/ci/ct-values.yaml +++ b/charts/smartbirds-server/ci/ct-values.yaml @@ -6,5 +6,9 @@ cron: schedule: "* * * * *" stats: schedule: "* * * * *" + refreshBgatlas2008: + schedule: "* * * * *" banners: schedule: "* * * * *" + atlasBspbStats: + schedule: "* * * * *" diff --git a/charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl b/charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl new file mode 100644 index 0000000..c1dd296 --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "atlas-bspb-stats" "taskName" "AtlasBspbStats" "values" .Values.cron.atlasBspbStats "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl b/charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl new file mode 100644 index 0000000..189b3c1 --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "bgatlas2008" "taskName" "bgatlas2008_refresh" "values" .Values.cron.refreshBgatlas2008 "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/locations.tpl b/charts/smartbirds-server/templates/cronjobs/locations.tpl new file mode 100644 index 0000000..e961095 --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/locations.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "locations" "taskName" "autoLocation" "values" .Values.cron.locations "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/modreview.tpl b/charts/smartbirds-server/templates/cronjobs/modreview.tpl new file mode 100644 index 0000000..a9188e7 --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/modreview.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "modreview" "taskName" "birdsNewSpeciesModeratorReview" "values" .Values.cron.birdsNewSpeciesModeratorReview "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml b/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml index c180146..3592beb 100644 --- a/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml +++ b/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml @@ -1,20 +1,24 @@ {{- $files := list -}} -{{- $files = append $files "organizations" -}} +{{- $files = append $files "atlas_bspb_summer_species.json" }} +{{- $files = append $files "atlas_bspb_winter_species.json" }} +{{- $files = append $files "bgatlas2008_global_stats" -}} {{- $files = append $files "birds_stats" -}} +{{- $files = append $files "birds_top_stats" -}} +{{- $files = append $files "campaign_stats" -}} {{- $files = append $files "cbm_stats" -}} {{- $files = append $files "ciconia_stats" -}} -{{- $files = append $files "mammals_stats" -}} +{{- $files = append $files "herptiles_stats" -}} +{{- $files = append $files "herptiles_top_stats" -}} {{- $files = append $files "invertebrates_stats" -}} +{{- $files = append $files "invertebrates_top_stats" -}} +{{- $files = append $files "mammals_stats" -}} +{{- $files = append $files "mammals_top_stats" -}} +{{- $files = append $files "organizations" -}} {{- $files = append $files "plants_stats" -}} +{{- $files = append $files "plants_top_stats" -}} {{- $files = append $files "threats_stats" -}} -{{- $files = append $files "user_rank_stats" -}} {{- $files = append $files "total_user_records_stats" -}} -{{- $files = append $files "birds_top_stats" -}} -{{- $files = append $files "herptiles_top_stats" -}} -{{- $files = append $files "mammals_top_stats" -}} -{{- $files = append $files "plants_top_stats" -}} -{{- $files = append $files "invertebrates_top_stats" -}} -{{- $files = append $files "bgatlas2008_global_stats" -}} +{{- $files = append $files "user_rank_stats" -}} apiVersion: v1 kind: Pod metadata: diff --git a/charts/smartbirds-server/templates/cronjobs/utmcode.tpl b/charts/smartbirds-server/templates/cronjobs/utmcode.tpl new file mode 100644 index 0000000..68ecccc --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/utmcode.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "utmcode" "taskName" "forms_fill_bgatlas2008_utmcode" "values" .Values.cron.utmcode "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/visits.tpl b/charts/smartbirds-server/templates/cronjobs/visits.tpl new file mode 100644 index 0000000..289b796 --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs/visits.tpl @@ -0,0 +1 @@ +{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "visits" "taskName" "autoVisit" "values" .Values.cron.visits "ctx" $) }} diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 9e4e5a1..04201ee 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -6,7 +6,7 @@ replicaCount: 1 image: repository: ghcr.io/bspborg/smartbirds-server - pullPolicy: IfNotPresent + pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. tag: "master" @@ -55,10 +55,30 @@ cron: ## memory: 1Gi limits: {} requests: {} + locations: + enabled: true + concurency: Forbid + schedule: "* * * * *" + visits: + enabled: true + concurency: Forbid + schedule: "* * * * *" + utmcode: + enabled: true + concurency: Forbid + schedule: "* * * * *" + birdsNewSpeciesModeratorReview: + enabled: true + concurency: Forbid + schedule: "* * * * *" stats: enabled: true concurency: Forbid schedule: "43 * * * *" + refreshBgatlas2008: + enabled: true + concurency: Forbid + schedule: "30 1 * * *" banners: enabled: true concurency: Forbid @@ -67,6 +87,10 @@ cron: enabled: true concurency: Forbid schedule: "35 3 * * *" + atlasBspbStats: + enabled: true + concurency: Forbid + schedule: "45 3 * * *" serviceAccount: From 6ddc1e102aebe372853d8ff79ef1027153609360 Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Thu, 20 Jan 2022 20:26:32 +0200 Subject: [PATCH 08/10] fixup! Add remaining cronjobs and checks --- charts/smartbirds-server/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 04201ee..956eebd 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -6,7 +6,7 @@ replicaCount: 1 image: repository: ghcr.io/bspborg/smartbirds-server - pullPolicy: Always + pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "master" From ef443ee668f1a25f8a2f7e0d00cca41da4ecbc5b Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Thu, 20 Jan 2022 22:18:46 +0200 Subject: [PATCH 09/10] Refactor cronjobs and add install/upgrade hook to run the jobs --- charts/smartbirds-server/ci/ct-values.yaml | 11 +--- .../smartbirds-server/templates/_cronjobs.tpl | 55 ------------------- charts/smartbirds-server/templates/_jobs.tpl | 37 +++++++++++++ .../smartbirds-server/templates/cronjobs.tpl | 20 +++++++ .../templates/cronjobs/atlas-bspb-stats.tpl | 1 - .../templates/cronjobs/banner.tpl | 1 - .../templates/cronjobs/bgatlas2008.tpl | 1 - .../templates/cronjobs/locations.tpl | 1 - .../templates/cronjobs/mailchimp.tpl | 1 - .../templates/cronjobs/modreview.tpl | 1 - .../templates/cronjobs/organizations.tpl | 1 - .../templates/cronjobs/stats.tpl | 1 - .../templates/cronjobs/utmcode.tpl | 1 - .../templates/cronjobs/visits.tpl | 1 - charts/smartbirds-server/templates/jobs.tpl | 17 ++++++ .../test-statics.yaml} | 6 +- charts/smartbirds-server/values.yaml | 52 ++++++++---------- 17 files changed, 100 insertions(+), 108 deletions(-) delete mode 100644 charts/smartbirds-server/templates/_cronjobs.tpl create mode 100644 charts/smartbirds-server/templates/_jobs.tpl create mode 100644 charts/smartbirds-server/templates/cronjobs.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/banner.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/locations.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/mailchimp.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/modreview.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/organizations.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/stats.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/utmcode.tpl delete mode 100644 charts/smartbirds-server/templates/cronjobs/visits.tpl create mode 100644 charts/smartbirds-server/templates/jobs.tpl rename charts/smartbirds-server/templates/{cronjobs/tests/test-connection.yaml => tests/test-statics.yaml} (87%) diff --git a/charts/smartbirds-server/ci/ct-values.yaml b/charts/smartbirds-server/ci/ct-values.yaml index 5109dd1..1b7e3a9 100644 --- a/charts/smartbirds-server/ci/ct-values.yaml +++ b/charts/smartbirds-server/ci/ct-values.yaml @@ -2,13 +2,4 @@ persistence: accessMode: ReadWriteOnce cron: - organizations: - schedule: "* * * * *" - stats: - schedule: "* * * * *" - refreshBgatlas2008: - schedule: "* * * * *" - banners: - schedule: "* * * * *" - atlasBspbStats: - schedule: "* * * * *" + enabled: false diff --git a/charts/smartbirds-server/templates/_cronjobs.tpl b/charts/smartbirds-server/templates/_cronjobs.tpl deleted file mode 100644 index d19fe59..0000000 --- a/charts/smartbirds-server/templates/_cronjobs.tpl +++ /dev/null @@ -1,55 +0,0 @@ -{{/* -Create a complete cronjob definition to enqueue task -Usage: -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "job-name" "taskName" "task-name" "args" (dict "opt1" "val1) "values" .Values.cronjob.task-name "ctx" $) }} -*/}} -{{- define "smartbirds-server.cronjob.enqueue" -}} -{{- if and .ctx.Values.cron.enabled .values.enabled -}} -apiVersion: batch/v1 -kind: CronJob -metadata: - name: {{ include "smartbirds-server.fullname" .ctx }}-{{ .name }} - labels: - {{- include "smartbirds-server.labels" .ctx | nindent 4 }} -spec: - concurrencyPolicy: {{ .values.concurency }} - schedule: {{ .values.schedule | quote }} - successfulJobsHistoryLimit: {{ .values.historyLimit | default 1 }} - jobTemplate: - spec: - template: - metadata: - labels: - {{- include "smartbirds-server.labels" .ctx | nindent 12 }} - app.kubernetes.io/component: enqueue-{{ .name }} - spec: - {{- with .ctx.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - restartPolicy: {{ .values.restartPolicy | default "OnFailure" }} - serviceAccountName: {{ include "smartbirds-server.serviceAccountName" .ctx }} - securityContext: - {{- toYaml .ctx.Values.podSecurityContext | nindent 12 }} - containers: - - name: {{ .ctx.Chart.Name }}-enqueue-{{ .name }} - securityContext: {{- toYaml (default .values.securityContext .ctx.Values.securityContext) | nindent 16 }} - {{- include "smartbirds-server.container.image" (dict "ctx" .ctx) | nindent 14 }} - command: - - /usr/local/bin/npm - - run - - ah - - -- - - task - - enqueue - - --name={{ .taskName }} - {{- if .args }} - - --args={{ toJson .args }} - {{- end }} - env: - {{- include "smartbirds-server.container.common-env" .ctx | nindent 16 }} - {{- if .values.resources }} - resources: {{- toYaml .values.resources | nindent 16 }} - {{- end }} -{{- end }} -{{- end -}} diff --git a/charts/smartbirds-server/templates/_jobs.tpl b/charts/smartbirds-server/templates/_jobs.tpl new file mode 100644 index 0000000..a8c0ded --- /dev/null +++ b/charts/smartbirds-server/templates/_jobs.tpl @@ -0,0 +1,37 @@ +{{/* +Create a job definition to enqueue task +Usage: +{{ include "smartbirds-server.job.enqueue" ("values" (dict "name" "job-name" "taskName" "task-name" "taskArgs" (dict "opt1" "val1)) "ctx" $) }} +*/}} +{{- define "smartbirds-server.job.enqueue" -}} +metadata: + labels: + {{- include "smartbirds-server.labels" .ctx | nindent 4 }} + app.kubernetes.io/component: enqueue-{{ .values.name }} +spec: + {{- with .ctx.Values.imagePullSecrets }} + imagePullSecrets: {{- toYaml . | nindent 4 }} + {{- end }} + restartPolicy: {{ .values.restartPolicy | default "OnFailure" }} + serviceAccountName: {{ include "smartbirds-server.serviceAccountName" .ctx }} + securityContext: {{- toYaml .ctx.Values.podSecurityContext | nindent 4 }} + containers: + - name: {{ .ctx.Chart.Name }}-enqueue-{{ .values.name }} + securityContext: {{- toYaml (default .values.securityContext .ctx.Values.securityContext) | nindent 8 }} + {{- include "smartbirds-server.container.image" (dict "ctx" .ctx) | nindent 6 }} + command: + - /usr/local/bin/npm + - run + - ah + - -- + - task + - enqueue + - --name={{ .values.taskName }} + {{- if .values.taskArgs }} + - --args={{ toJson .values.taskArgs }} + {{- end }} + env: {{- include "smartbirds-server.container.common-env" .ctx | nindent 8 }} + {{- if .values.resources }} + resources: {{- toYaml .values.resources | nindent 8 }} + {{- end }} +{{- end -}} diff --git a/charts/smartbirds-server/templates/cronjobs.tpl b/charts/smartbirds-server/templates/cronjobs.tpl new file mode 100644 index 0000000..c517eaa --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs.tpl @@ -0,0 +1,20 @@ +{{- if .Values.cron.enabled }} +{{- range .Values.cron.jobs }} +{{- if .enabled }} +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "smartbirds-server.fullname" $ }}-{{ .name }} + labels: + {{- include "smartbirds-server.labels" $ | nindent 4 }} +spec: + concurrencyPolicy: {{ .concurency }} + schedule: {{ .schedule | quote }} + successfulJobsHistoryLimit: {{ .historyLimit | default 1 }} + jobTemplate: + spec: + template: {{- include "smartbirds-server.job.enqueue" (dict "values" . "ctx" $) | nindent 8 }} +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl b/charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl deleted file mode 100644 index c1dd296..0000000 --- a/charts/smartbirds-server/templates/cronjobs/atlas-bspb-stats.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "atlas-bspb-stats" "taskName" "AtlasBspbStats" "values" .Values.cron.atlasBspbStats "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/banner.tpl b/charts/smartbirds-server/templates/cronjobs/banner.tpl deleted file mode 100644 index 77159bb..0000000 --- a/charts/smartbirds-server/templates/cronjobs/banner.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "banners" "taskName" "banner:generate" "values" .Values.cron.banners "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl b/charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl deleted file mode 100644 index 189b3c1..0000000 --- a/charts/smartbirds-server/templates/cronjobs/bgatlas2008.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "bgatlas2008" "taskName" "bgatlas2008_refresh" "values" .Values.cron.refreshBgatlas2008 "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/locations.tpl b/charts/smartbirds-server/templates/cronjobs/locations.tpl deleted file mode 100644 index e961095..0000000 --- a/charts/smartbirds-server/templates/cronjobs/locations.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "locations" "taskName" "autoLocation" "values" .Values.cron.locations "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/mailchimp.tpl b/charts/smartbirds-server/templates/cronjobs/mailchimp.tpl deleted file mode 100644 index 86b703e..0000000 --- a/charts/smartbirds-server/templates/cronjobs/mailchimp.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "mailchimp" "taskName" "stats:mailchimp" "values" .Values.cron.mailchimp "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/modreview.tpl b/charts/smartbirds-server/templates/cronjobs/modreview.tpl deleted file mode 100644 index a9188e7..0000000 --- a/charts/smartbirds-server/templates/cronjobs/modreview.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "modreview" "taskName" "birdsNewSpeciesModeratorReview" "values" .Values.cron.birdsNewSpeciesModeratorReview "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/organizations.tpl b/charts/smartbirds-server/templates/cronjobs/organizations.tpl deleted file mode 100644 index f044f7e..0000000 --- a/charts/smartbirds-server/templates/cronjobs/organizations.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "organizations" "taskName" "organizations:export" "values" .Values.cron.organizations "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/stats.tpl b/charts/smartbirds-server/templates/cronjobs/stats.tpl deleted file mode 100644 index 87e637a..0000000 --- a/charts/smartbirds-server/templates/cronjobs/stats.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "stats" "taskName" "stats:generate" "values" .Values.cron.stats "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/utmcode.tpl b/charts/smartbirds-server/templates/cronjobs/utmcode.tpl deleted file mode 100644 index 68ecccc..0000000 --- a/charts/smartbirds-server/templates/cronjobs/utmcode.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "utmcode" "taskName" "forms_fill_bgatlas2008_utmcode" "values" .Values.cron.utmcode "ctx" $) }} diff --git a/charts/smartbirds-server/templates/cronjobs/visits.tpl b/charts/smartbirds-server/templates/cronjobs/visits.tpl deleted file mode 100644 index 289b796..0000000 --- a/charts/smartbirds-server/templates/cronjobs/visits.tpl +++ /dev/null @@ -1 +0,0 @@ -{{ include "smartbirds-server.cronjob.enqueue" (dict "name" "visits" "taskName" "autoVisit" "values" .Values.cron.visits "ctx" $) }} diff --git a/charts/smartbirds-server/templates/jobs.tpl b/charts/smartbirds-server/templates/jobs.tpl new file mode 100644 index 0000000..5f1be23 --- /dev/null +++ b/charts/smartbirds-server/templates/jobs.tpl @@ -0,0 +1,17 @@ +{{- range .Values.cron.jobs }} +{{- if .enabled }} +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "smartbirds-server.fullname" $ }}-{{ .name }} + labels: + {{- include "smartbirds-server.labels" $ | nindent 4 }} + annotations: + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-weight": "0" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded +spec: + template: {{- include "smartbirds-server.job.enqueue" (dict "values" . "ctx" $) | nindent 4 }} +{{- end }} +{{- end }} diff --git a/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml b/charts/smartbirds-server/templates/tests/test-statics.yaml similarity index 87% rename from charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml rename to charts/smartbirds-server/templates/tests/test-statics.yaml index 3592beb..04c5de4 100644 --- a/charts/smartbirds-server/templates/cronjobs/tests/test-connection.yaml +++ b/charts/smartbirds-server/templates/tests/test-statics.yaml @@ -1,6 +1,6 @@ {{- $files := list -}} -{{- $files = append $files "atlas_bspb_summer_species.json" }} -{{- $files = append $files "atlas_bspb_winter_species.json" }} +{{- $files = append $files "atlas_bspb_summer_species" -}} +{{- $files = append $files "atlas_bspb_winter_species" -}} {{- $files = append $files "bgatlas2008_global_stats" -}} {{- $files = append $files "birds_stats" -}} {{- $files = append $files "birds_top_stats" -}} @@ -22,7 +22,7 @@ apiVersion: v1 kind: Pod metadata: - name: "{{ include "smartbirds-server.fullname" . }}-test-cronjobs" + name: "{{ include "smartbirds-server.fullname" . }}-test-statics" labels: {{- include "smartbirds-server.labels" . | nindent 4 }} annotations: diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 956eebd..74c8ef1 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -32,63 +32,55 @@ static: cron: enabled: true - organizations: + jobs: + - name: "organizations" enabled: true + taskName: "organizations:export" concurency: Forbid - ## @param cron.organizations.schedule Schedule in Cron format to generate organizations export - ## See https://en.wikipedia.org/wiki/Cron - ## schedule: "*/17 * * * *" - ## Configure resource requests and limits for organization-exporter containers - ## ref: https://kubernetes.io/docs/user-guide/compute-resources/ - ## We usually recommend not to specify default resources and to leave this as a conscious - ## choice for the user. This also increases chances charts run on environments with little - ## resources, such as Minikube. If you do want to specify resources, uncomment the following - ## lines, adjust them as necessary, and remove the curly braces after 'resources:'. - ## @param cron.organizations.resources.limits [object] Cronjob container resource limits - ## @param cron.organizations.resources.requests [object] Cronjob container resource requests - ## - resources: - ## Example: - ## limits: - ## cpu: 500m - ## memory: 1Gi - limits: {} - requests: {} - locations: + - name: "locations" enabled: true + taskName: "autoLocation" concurency: Forbid schedule: "* * * * *" - visits: + - name: "visits" enabled: true + taskName: "autoVisit" concurency: Forbid schedule: "* * * * *" - utmcode: + - name: "utmcode" enabled: true + taskName: "forms_fill_bgatlas2008_utmcode" concurency: Forbid schedule: "* * * * *" - birdsNewSpeciesModeratorReview: + - name: "modreview" enabled: true + taskName: "birdsNewSpeciesModeratorReview" concurency: Forbid schedule: "* * * * *" - stats: + - name: "stats" enabled: true + taskName: "stats:generate" concurency: Forbid schedule: "43 * * * *" - refreshBgatlas2008: + - name: "refresh" enabled: true + taskName: "bgatlas2008_refresh" concurency: Forbid schedule: "30 1 * * *" - banners: + - name: "banners" enabled: true + taskName: "banner:generate" concurency: Forbid schedule: "25 3 * * *" - mailchimp: - enabled: true + - name: "mailchimp" + enabled: false + taskName: "stats:mailchimp" concurency: Forbid schedule: "35 3 * * *" - atlasBspbStats: + - name: "bspborg" enabled: true + taskName: "AtlasBspbStats" concurency: Forbid schedule: "45 3 * * *" From 8cbaf1d1b21014c111085368b4dba3c19265c229 Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Fri, 21 Jan 2022 09:39:19 +0200 Subject: [PATCH 10/10] Use standalone architecture for redis on CI --- charts/smartbirds-server/ci/ct-values.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/charts/smartbirds-server/ci/ct-values.yaml b/charts/smartbirds-server/ci/ct-values.yaml index 1b7e3a9..93bf926 100644 --- a/charts/smartbirds-server/ci/ct-values.yaml +++ b/charts/smartbirds-server/ci/ct-values.yaml @@ -3,3 +3,6 @@ persistence: cron: enabled: false + +redis: + architecture: standalone