From 68b36731e4b562b761d5686311721681e1b3ba4d Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Wed, 10 Nov 2021 19:19:04 +0000 Subject: [PATCH 01/21] Fix missing REDIS_HOST on pod env --- k8s/templates/_helpers.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/k8s/templates/_helpers.tpl b/k8s/templates/_helpers.tpl index ebeb4ae3e..b26ba66b2 100644 --- a/k8s/templates/_helpers.tpl +++ b/k8s/templates/_helpers.tpl @@ -77,6 +77,8 @@ Define environment variables shared by some pods. value: "{{ .Values.postgresql.postgresqlPassword }}" - name: POSTGRESQL_DATABASE value: "{{ .Values.postgresql.postgresqlDatabase }}" +- name: REDIS_HOST + value: "{{ .Release.Name }}-redis-master" - name: LIFEMONITOR_TLS_KEY value: "/lm/certs/tls.key" - name: LIFEMONITOR_TLS_CERT From 1334955d3dfc4c9114e93b6dd0842f984fd3458e Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Wed, 10 Nov 2021 19:19:26 +0000 Subject: [PATCH 02/21] Fix missing WORKER_PROCESSES on pod env --- k8s/templates/_helpers.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/k8s/templates/_helpers.tpl b/k8s/templates/_helpers.tpl index b26ba66b2..afaf478af 100644 --- a/k8s/templates/_helpers.tpl +++ b/k8s/templates/_helpers.tpl @@ -79,6 +79,8 @@ Define environment variables shared by some pods. value: "{{ .Values.postgresql.postgresqlDatabase }}" - name: REDIS_HOST value: "{{ .Release.Name }}-redis-master" +- name: WORKER_PROCESSES + value: "{{ .Values.lifemonitor.worker_processes }}" - name: LIFEMONITOR_TLS_KEY value: "/lm/certs/tls.key" - name: LIFEMONITOR_TLS_CERT From 44eb4a7fc0b0d3bd38dcca11cada49fa788a84f9 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 08:21:56 +0000 Subject: [PATCH 03/21] Fix back-end selector --- k8s/templates/backend-deployment.yaml | 3 +++ k8s/templates/service.yaml | 1 + 2 files changed, 4 insertions(+) diff --git a/k8s/templates/backend-deployment.yaml b/k8s/templates/backend-deployment.yaml index 7ee59cd8f..6c2b85387 100644 --- a/k8s/templates/backend-deployment.yaml +++ b/k8s/templates/backend-deployment.yaml @@ -4,6 +4,7 @@ metadata: name: {{ include "chart.fullname" . }}-backend labels: {{- include "chart.labels" . | nindent 4 }} + app.kubernetes.io/component: backend spec: {{- if not .Values.lifemonitor.autoscaling.enabled }} replicas: {{ .Values.lifemonitor.replicaCount }} @@ -11,6 +12,7 @@ spec: selector: matchLabels: {{- include "chart.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: backend template: metadata: {{- with .Values.lifemonitor.podAnnotations }} @@ -19,6 +21,7 @@ spec: {{- end }} labels: {{- include "chart.selectorLabels" . | nindent 8 }} + app.kubernetes.io/component: backend spec: {{- with .Values.lifemonitor.imagePullSecrets }} imagePullSecrets: diff --git a/k8s/templates/service.yaml b/k8s/templates/service.yaml index 90cb29f12..ac8c8ccf6 100644 --- a/k8s/templates/service.yaml +++ b/k8s/templates/service.yaml @@ -13,3 +13,4 @@ spec: name: http selector: {{- include "chart.selectorLabels" . | nindent 4 }} + app.kubernetes.io/component: backend From 88501c16e63d899a1b090316503d38b05283aad2 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 08:23:36 +0000 Subject: [PATCH 04/21] Update container name of worker process --- k8s/templates/worker-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/templates/worker-deployment.yaml b/k8s/templates/worker-deployment.yaml index cede78b95..7938674da 100644 --- a/k8s/templates/worker-deployment.yaml +++ b/k8s/templates/worker-deployment.yaml @@ -33,7 +33,7 @@ spec: imagePullPolicy: IfNotPresent args: ["job", "{{ include "chart.fullname" . }}-init"] containers: - - name: app + - name: worker securityContext: {{- toYaml .Values.lifemonitor.securityContext | nindent 12 }} image: {{ .Values.lifemonitor.image }} From 2798637f0df9c64485be343024d75b26767b9ccb Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 08:47:31 +0000 Subject: [PATCH 05/21] Add dedicated values for workers --- k8s/templates/_helpers.tpl | 2 +- k8s/templates/secret.yaml | 2 +- k8s/templates/worker-deployment.yaml | 48 ++++++++++++------------ k8s/values.yaml | 56 ++++++++++++++++++++++++++-- 4 files changed, 78 insertions(+), 30 deletions(-) diff --git a/k8s/templates/_helpers.tpl b/k8s/templates/_helpers.tpl index afaf478af..57da81499 100644 --- a/k8s/templates/_helpers.tpl +++ b/k8s/templates/_helpers.tpl @@ -80,7 +80,7 @@ Define environment variables shared by some pods. - name: REDIS_HOST value: "{{ .Release.Name }}-redis-master" - name: WORKER_PROCESSES - value: "{{ .Values.lifemonitor.worker_processes }}" + value: "{{ .Values.worker.processes }}" - name: LIFEMONITOR_TLS_KEY value: "/lm/certs/tls.key" - name: LIFEMONITOR_TLS_CERT diff --git a/k8s/templates/secret.yaml b/k8s/templates/secret.yaml index 936cfc7e0..0ed2204cc 100644 --- a/k8s/templates/secret.yaml +++ b/k8s/templates/secret.yaml @@ -37,7 +37,7 @@ stringData: POSTGRESQL_PASSWORD={{ .Values.postgresql.postgresqlPassword }} # Dramatiq worker settings - WORKER_PROCESSES={{ .Values.lifemonitor.worker_processes }} + WORKER_PROCESSES={{ .Values.worker.processes }} # Redis settings REDIS_HOST={{ .Release.Name }}-redis-master diff --git a/k8s/templates/worker-deployment.yaml b/k8s/templates/worker-deployment.yaml index 7938674da..073390975 100644 --- a/k8s/templates/worker-deployment.yaml +++ b/k8s/templates/worker-deployment.yaml @@ -5,28 +5,28 @@ metadata: labels: {{- include "chart.labels" . | nindent 4 }} spec: - {{- if not .Values.lifemonitor.autoscaling.enabled }} - replicas: {{ .Values.lifemonitor.replicaCount }} + {{- if not .Values.worker.autoscaling.enabled }} + replicas: {{ .Values.worker.replicaCount }} {{- end }} selector: matchLabels: {{- include "chart.selectorLabels" . | nindent 6 }} template: metadata: - {{- with .Values.lifemonitor.podAnnotations }} + {{- with .Values.worker.podAnnotations }} annotations: {{- toYaml . | nindent 8 }} {{- end }} labels: {{- include "chart.selectorLabels" . | nindent 8 }} spec: - {{- with .Values.lifemonitor.imagePullSecrets }} + {{- with .Values.worker.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "chart.serviceAccountName" . }} securityContext: - {{- toYaml .Values.lifemonitor.podSecurityContext | nindent 8 }} + {{- toYaml .Values.worker.podSecurityContext | nindent 8 }} initContainers: - name: init image: "crs4/k8s-wait-for:latest" @@ -35,40 +35,40 @@ spec: containers: - name: worker securityContext: - {{- toYaml .Values.lifemonitor.securityContext | nindent 12 }} - image: {{ .Values.lifemonitor.image }} - imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} + {{- toYaml .Values.worker.securityContext | nindent 12 }} + image: {{ .Values.worker.image }} + imagePullPolicy: {{ .Values.worker.imagePullPolicy }} command: ["/bin/sh","-c"] args: ["/usr/local/bin/worker_entrypoint.sh"] env: {{ include "lifemonitor.common-env" . | indent 12 }} volumeMounts: {{ include "lifemonitor.common-volume-mounts" . | indent 12 }} - livenessProbe: - httpGet: - scheme: HTTPS - path: /health - port: 8000 - readinessProbe: - httpGet: - scheme: HTTPS - path: /health - port: 8000 - initialDelaySeconds: 5 - periodSeconds: 3 + # livenessProbe: + # httpGet: + # scheme: HTTPS + # path: /health + # port: 8000 + # readinessProbe: + # httpGet: + # scheme: HTTPS + # path: /health + # port: 8000 + # initialDelaySeconds: 5 + # periodSeconds: 3 resources: - {{- toYaml .Values.lifemonitor.resources | nindent 12 }} + {{- toYaml .Values.worker.resources | nindent 12 }} volumes: {{ include "lifemonitor.common-volume" . | indent 12 }} - {{- with .Values.lifemonitor.nodeSelector }} + {{- with .Values.worker.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.lifemonitor.affinity }} + {{- with .Values.worker.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.lifemonitor.tolerations }} + {{- with .Values.worker.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} diff --git a/k8s/values.yaml b/k8s/values.yaml index e0c9fef4c..980b820c7 100644 --- a/k8s/values.yaml +++ b/k8s/values.yaml @@ -96,16 +96,64 @@ lifemonitor: type: ClusterIP port: 8000 - # Dramatiq worker settings - worker_processes: 1 - persistence: storageClass: *storageClass # Enable/Disable the pod to test connection to the LifeMonitor back-end enableTestConnection: false - resources: {} + 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:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + nodeSelector: {} + + tolerations: [] + + affinity: {} + +worker: + image: *lifemonitorImage + imagePullPolicy: *lifemonitorImagePullPolicy + imagePullSecrets: [] + + processes: 1 + + podAnnotations: {} + + podSecurityContext: + {} + # fsGroup: 2000 + + securityContext: + {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + replicaCount: 1 + + 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 From 8a533f9295c7607afc4d53f7c7f54cc7173617fe Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 08:57:27 +0000 Subject: [PATCH 06/21] Add values to configure cache --- k8s/templates/secret.yaml | 12 +++++++----- k8s/values.yaml | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/k8s/templates/secret.yaml b/k8s/templates/secret.yaml index 0ed2204cc..adb370bf3 100644 --- a/k8s/templates/secret.yaml +++ b/k8s/templates/secret.yaml @@ -45,11 +45,13 @@ stringData: REDIS_PASSWORD={{ .Values.redis.auth.password }} # Redis Cache - CACHE_REDIS_DB=0 - CACHE_REDIS_URL=redis://:{{ .Values.redis.auth.password }}@{{ .Release.Name }}-redis-master:{{ .Values.redis.master.service.port }}/0 - CACHE_DEFAULT_TIMEOUT=300 - CACHE_SESSION_TIMEOUT=3600 - CACHE_BUILDS_TIMEOUT=84600 + CACHE_REDIS_HOST={{ .Release.Name }}-redis-master + CACHE_REDIS_DB={{ .Values.cache.db }} + CACHE_REDIS_URL=redis://:{{ .Values.redis.auth.password }}@{{ .Release.Name }}-redis-master:{{ .Values.redis.master.service.port }}/{{ .Values.cachedb }} + CACHE_DEFAULT_TIMEOUT={{ .Values.cache.timeout.default }} + CACHE_REQUEST_TIMEOUT={{ .Values.cache.timeout.request }} + CACHE_SESSION_TIMEOUT={{ .Values.cache.timeout.session }} + CACHE_BUILD_TIMEOUT={{ .Values.cache.timeout.build }} # Set admin credentials LIFEMONITOR_ADMIN_PASSWORD={{ .Values.lifemonitor.administrator.password }} diff --git a/k8s/values.yaml b/k8s/values.yaml index 980b820c7..b5a61582e 100644 --- a/k8s/values.yaml +++ b/k8s/values.yaml @@ -59,6 +59,14 @@ testing_services: # token: # type: travis +cache: + db: 0 + timeout: + default: 30 + request: 15 + session: 3600 + build: 84600 + lifemonitor: replicaCount: 1 From 2a46c871599d0bf5e43ec70574697440d701c317 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 09:46:21 +0000 Subject: [PATCH 07/21] Fix typo --- k8s/templates/secret.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/templates/secret.yaml b/k8s/templates/secret.yaml index adb370bf3..bbe1a757b 100644 --- a/k8s/templates/secret.yaml +++ b/k8s/templates/secret.yaml @@ -47,7 +47,7 @@ stringData: # Redis Cache CACHE_REDIS_HOST={{ .Release.Name }}-redis-master CACHE_REDIS_DB={{ .Values.cache.db }} - CACHE_REDIS_URL=redis://:{{ .Values.redis.auth.password }}@{{ .Release.Name }}-redis-master:{{ .Values.redis.master.service.port }}/{{ .Values.cachedb }} + CACHE_REDIS_URL=redis://:{{ .Values.redis.auth.password }}@{{ .Release.Name }}-redis-master:{{ .Values.redis.master.service.port }}/{{ .Values.cache.db }} CACHE_DEFAULT_TIMEOUT={{ .Values.cache.timeout.default }} CACHE_REQUEST_TIMEOUT={{ .Values.cache.timeout.request }} CACHE_SESSION_TIMEOUT={{ .Values.cache.timeout.session }} From 5bd22da15b440bf2b14d175758921d0d78d8705d Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 11:34:36 +0000 Subject: [PATCH 08/21] Rename filename of init job --- k8s/templates/{init-job.yaml => job-init.yaml} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename k8s/templates/{init-job.yaml => job-init.yaml} (93%) diff --git a/k8s/templates/init-job.yaml b/k8s/templates/job-init.yaml similarity index 93% rename from k8s/templates/init-job.yaml rename to k8s/templates/job-init.yaml index 243a1c8a6..07fe94ea7 100644 --- a/k8s/templates/init-job.yaml +++ b/k8s/templates/job-init.yaml @@ -13,6 +13,7 @@ spec: imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} command: ["/bin/sh","-c"] args: ["wait-for-postgres.sh && flask init db"] +# args: ["wait-for-postgres.sh && sleep infinity"] env: {{ include "lifemonitor.common-env" . | indent 10 }} volumeMounts: @@ -32,4 +33,4 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} - backoffLimit: 4 \ No newline at end of file + backoffLimit: 4 From 1fa66cf64e362ec8682547b0548b2d7d39a58991 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 11:35:03 +0000 Subject: [PATCH 09/21] Add job to handle upgrades --- k8s/templates/job-upgrade.yaml | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 k8s/templates/job-upgrade.yaml diff --git a/k8s/templates/job-upgrade.yaml b/k8s/templates/job-upgrade.yaml new file mode 100644 index 000000000..065497dfd --- /dev/null +++ b/k8s/templates/job-upgrade.yaml @@ -0,0 +1,41 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "chart.fullname" . }}-upgrade + labels: + {{- include "chart.labels" . | nindent 4 }} + annotations: + # This is what defines this resource as a hook. Without this line, the + # job is considered part of the release. + "helm.sh/hook": post-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + spec: + containers: + - name: lifemonitor-upgrade + image: "{{ .Values.lifemonitor.image }}" + imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} + command: ["/bin/sh","-c"] + args: ["wait-for-postgres.sh && flask init db"] + env: +{{ include "lifemonitor.common-env" . | indent 10 }} + volumeMounts: +{{ include "lifemonitor.common-volume-mounts" . | indent 10 }} + restartPolicy: Never + volumes: +{{ include "lifemonitor.common-volume" . | indent 8 }} + {{- with .Values.lifemonitor.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.lifemonitor.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.lifemonitor.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + backoffLimit: 4 From be17346699d5da314d74fbd6fd25d0c0421d3d6e Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 11:36:09 +0000 Subject: [PATCH 10/21] Auto restart worker and back-end when settings change --- k8s/templates/backend-deployment.yaml | 7 ++++--- k8s/templates/worker-deployment.yaml | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/k8s/templates/backend-deployment.yaml b/k8s/templates/backend-deployment.yaml index 6c2b85387..4f6f9ce82 100644 --- a/k8s/templates/backend-deployment.yaml +++ b/k8s/templates/backend-deployment.yaml @@ -14,11 +14,12 @@ spec: {{- include "chart.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: backend template: - metadata: - {{- with .Values.lifemonitor.podAnnotations }} + metadata: annotations: + checksum/settings: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + {{- with .Values.lifemonitor.podAnnotations }} {{- toYaml . | nindent 8 }} - {{- end }} + {{- end }} labels: {{- include "chart.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: backend diff --git a/k8s/templates/worker-deployment.yaml b/k8s/templates/worker-deployment.yaml index 073390975..42bd9b871 100644 --- a/k8s/templates/worker-deployment.yaml +++ b/k8s/templates/worker-deployment.yaml @@ -13,8 +13,9 @@ spec: {{- include "chart.selectorLabels" . | nindent 6 }} template: metadata: - {{- with .Values.worker.podAnnotations }} annotations: + checksum/settings: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + {{- with .Values.worker.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} labels: From 28fac5cb25cc44816c0514dcfc097465588d8415 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 17:09:05 +0000 Subject: [PATCH 11/21] Add helper function to set the default image --- k8s/templates/_helpers.tpl | 13 +++++++++++++ k8s/templates/backend-deployment.yaml | 2 +- k8s/templates/job-init.yaml | 3 +-- k8s/templates/job-upgrade.yaml | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/k8s/templates/_helpers.tpl b/k8s/templates/_helpers.tpl index 57da81499..e3b010810 100644 --- a/k8s/templates/_helpers.tpl +++ b/k8s/templates/_helpers.tpl @@ -48,6 +48,19 @@ app.kubernetes.io/name: {{ include "chart.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{/* + +Define lifemonitor image +*/}} +{{- define "chart.lifemonitor.image" -}} +{{- if .Values.lifemonitor.image }} +{{- printf "%s" .Values.lifemonitor.image }} +{{- else }} +{{- printf "crs4/lifemonitor:%s" .Chart.AppVersion }} +{{- end }} +{{- end }} + + {{/* Create the name of the service account to use */}} diff --git a/k8s/templates/backend-deployment.yaml b/k8s/templates/backend-deployment.yaml index 4f6f9ce82..77e1d1d93 100644 --- a/k8s/templates/backend-deployment.yaml +++ b/k8s/templates/backend-deployment.yaml @@ -40,7 +40,7 @@ spec: - name: app securityContext: {{- toYaml .Values.lifemonitor.securityContext | nindent 12 }} - image: {{ .Values.lifemonitor.image }} + image: {{ include "chart.lifemonitor.image" . }} imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} env: {{ include "lifemonitor.common-env" . | indent 12 }} diff --git a/k8s/templates/job-init.yaml b/k8s/templates/job-init.yaml index 07fe94ea7..70d08e82e 100644 --- a/k8s/templates/job-init.yaml +++ b/k8s/templates/job-init.yaml @@ -9,11 +9,10 @@ spec: spec: containers: - name: lifemonitor-init - image: "{{ .Values.lifemonitor.image }}" + image: {{ include "chart.lifemonitor.image" . }} imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} command: ["/bin/sh","-c"] args: ["wait-for-postgres.sh && flask init db"] -# args: ["wait-for-postgres.sh && sleep infinity"] env: {{ include "lifemonitor.common-env" . | indent 10 }} volumeMounts: diff --git a/k8s/templates/job-upgrade.yaml b/k8s/templates/job-upgrade.yaml index 065497dfd..11f3fd022 100644 --- a/k8s/templates/job-upgrade.yaml +++ b/k8s/templates/job-upgrade.yaml @@ -15,7 +15,7 @@ spec: spec: containers: - name: lifemonitor-upgrade - image: "{{ .Values.lifemonitor.image }}" + image: {{ include "chart.lifemonitor.image" . }} imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} command: ["/bin/sh","-c"] args: ["wait-for-postgres.sh && flask init db"] From 7a3ae56776d312547ddb817abb5b287916ffbb4a Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 17:09:19 +0000 Subject: [PATCH 12/21] Fix labels --- k8s/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/templates/_helpers.tpl b/k8s/templates/_helpers.tpl index e3b010810..40f949c38 100644 --- a/k8s/templates/_helpers.tpl +++ b/k8s/templates/_helpers.tpl @@ -35,9 +35,9 @@ Common labels */}} {{- define "chart.labels" -}} app.kubernetes.io/name: {{ include "chart.name" . }} -helm.sh/chart: {{ include "chart.chart" . }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} +helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" {{- end }} {{/* From 70c07f31b377d159784e9bebff737bdd3a8f00b9 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 17:09:48 +0000 Subject: [PATCH 13/21] Remove blanks --- k8s/templates/backend-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/templates/backend-deployment.yaml b/k8s/templates/backend-deployment.yaml index 77e1d1d93..d881a717a 100644 --- a/k8s/templates/backend-deployment.yaml +++ b/k8s/templates/backend-deployment.yaml @@ -14,7 +14,7 @@ spec: {{- include "chart.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: backend template: - metadata: + metadata: annotations: checksum/settings: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} {{- with .Values.lifemonitor.podAnnotations }} From 1288f7801ba246fbe829626ebb0dbbf4b66ee9db Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 17:11:40 +0000 Subject: [PATCH 14/21] Fix image of workers --- k8s/templates/worker-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/templates/worker-deployment.yaml b/k8s/templates/worker-deployment.yaml index 42bd9b871..73be1b14b 100644 --- a/k8s/templates/worker-deployment.yaml +++ b/k8s/templates/worker-deployment.yaml @@ -37,7 +37,7 @@ spec: - name: worker securityContext: {{- toYaml .Values.worker.securityContext | nindent 12 }} - image: {{ .Values.worker.image }} + image: {{ include "chart.lifemonitor.image" . }} imagePullPolicy: {{ .Values.worker.imagePullPolicy }} command: ["/bin/sh","-c"] args: ["/usr/local/bin/worker_entrypoint.sh"] From df956ef56a0a2302ebadede6ebc56819ea54f317 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 17:20:36 +0000 Subject: [PATCH 15/21] Fix indentation --- k8s/templates/backend-deployment.yaml | 6 +++--- k8s/templates/job-init.yaml | 10 +++++----- k8s/templates/worker-deployment.yaml | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/k8s/templates/backend-deployment.yaml b/k8s/templates/backend-deployment.yaml index d881a717a..3c9ec93df 100644 --- a/k8s/templates/backend-deployment.yaml +++ b/k8s/templates/backend-deployment.yaml @@ -43,9 +43,9 @@ spec: image: {{ include "chart.lifemonitor.image" . }} imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} env: -{{ include "lifemonitor.common-env" . | indent 12 }} + {{- include "lifemonitor.common-env" . | nindent 12 }} volumeMounts: -{{ include "lifemonitor.common-volume-mounts" . | indent 12 }} + {{- include "lifemonitor.common-volume-mounts" . | nindent 12 }} ports: - name: http containerPort: 8000 @@ -65,7 +65,7 @@ spec: resources: {{- toYaml .Values.lifemonitor.resources | nindent 12 }} volumes: -{{ include "lifemonitor.common-volume" . | indent 12 }} + {{- include "lifemonitor.common-volume" . | nindent 8 }} {{- with .Values.lifemonitor.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/k8s/templates/job-init.yaml b/k8s/templates/job-init.yaml index 70d08e82e..4ebca0339 100644 --- a/k8s/templates/job-init.yaml +++ b/k8s/templates/job-init.yaml @@ -14,12 +14,12 @@ spec: command: ["/bin/sh","-c"] args: ["wait-for-postgres.sh && flask init db"] env: -{{ include "lifemonitor.common-env" . | indent 10 }} + {{- include "lifemonitor.common-env" . | nindent 10 }} volumeMounts: -{{ include "lifemonitor.common-volume-mounts" . | indent 10 }} - restartPolicy: Never + {{- include "lifemonitor.common-volume-mounts" . | nindent 10 }} + restartPolicy: OnFailure volumes: -{{ include "lifemonitor.common-volume" . | indent 8 }} + {{- include "lifemonitor.common-volume" . | nindent 8 }} {{- with .Values.lifemonitor.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} @@ -30,6 +30,6 @@ spec: {{- end }} {{- with .Values.lifemonitor.tolerations }} tolerations: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 8 }} {{- end }} backoffLimit: 4 diff --git a/k8s/templates/worker-deployment.yaml b/k8s/templates/worker-deployment.yaml index 73be1b14b..ce99c4c61 100644 --- a/k8s/templates/worker-deployment.yaml +++ b/k8s/templates/worker-deployment.yaml @@ -42,9 +42,9 @@ spec: command: ["/bin/sh","-c"] args: ["/usr/local/bin/worker_entrypoint.sh"] env: -{{ include "lifemonitor.common-env" . | indent 12 }} + {{- include "lifemonitor.common-env" . | nindent 12 }} volumeMounts: -{{ include "lifemonitor.common-volume-mounts" . | indent 12 }} + {{- include "lifemonitor.common-volume-mounts" . | nindent 12 }} # livenessProbe: # httpGet: # scheme: HTTPS @@ -60,7 +60,7 @@ spec: resources: {{- toYaml .Values.worker.resources | nindent 12 }} volumes: -{{ include "lifemonitor.common-volume" . | indent 12 }} + {{- include "lifemonitor.common-volume" . | nindent 8 }} {{- with .Values.worker.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} From f3daf9f05245a7832901ff5aa15c23d32b61e949 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 11 Nov 2021 17:31:17 +0000 Subject: [PATCH 16/21] Bump chart version number --- k8s/Chart.yaml | 4 ++-- k8s/values.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/k8s/Chart.yaml b/k8s/Chart.yaml index 208c09375..1d3baf92c 100644 --- a/k8s/Chart.yaml +++ b/k8s/Chart.yaml @@ -7,12 +7,12 @@ 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.3.0 +version: 0.4.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 # follow Semantic Versioning. They should reflect the version the application is using. -appVersion: 0.1.0 +appVersion: 0.4.0 # Chart dependencies dependencies: diff --git a/k8s/values.yaml b/k8s/values.yaml index b5a61582e..c801d983a 100644 --- a/k8s/values.yaml +++ b/k8s/values.yaml @@ -70,7 +70,7 @@ cache: lifemonitor: replicaCount: 1 - image: &lifemonitorImage crs4/lifemonitor:master + image: &lifemonitorImage crs4/lifemonitor:0.4.0 imagePullPolicy: &lifemonitorImagePullPolicy Always imagePullSecrets: [] From cb719e366ac6a3347af700c01a7c155cc92ed845 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Mon, 15 Nov 2021 19:41:45 +0100 Subject: [PATCH 17/21] Allow to configure cache timeout for workflows --- k8s/templates/secret.yaml | 1 + k8s/values.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/k8s/templates/secret.yaml b/k8s/templates/secret.yaml index bbe1a757b..df8697f90 100644 --- a/k8s/templates/secret.yaml +++ b/k8s/templates/secret.yaml @@ -51,6 +51,7 @@ stringData: CACHE_DEFAULT_TIMEOUT={{ .Values.cache.timeout.default }} CACHE_REQUEST_TIMEOUT={{ .Values.cache.timeout.request }} CACHE_SESSION_TIMEOUT={{ .Values.cache.timeout.session }} + CACHE_WORKFLOW_TIMEOUT={{ .Values.cache.timeout.workflow }} CACHE_BUILD_TIMEOUT={{ .Values.cache.timeout.build }} # Set admin credentials diff --git a/k8s/values.yaml b/k8s/values.yaml index c801d983a..296ba6abb 100644 --- a/k8s/values.yaml +++ b/k8s/values.yaml @@ -65,6 +65,7 @@ cache: default: 30 request: 15 session: 3600 + workflow: 1800 build: 84600 lifemonitor: From a0b9a75c8f16a43da1d158b066944a93bfe30e58 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Tue, 23 Nov 2021 17:10:00 +0000 Subject: [PATCH 18/21] Reset task-queue after install/update --- k8s/templates/job-init.yaml | 2 +- k8s/templates/job-upgrade.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/k8s/templates/job-init.yaml b/k8s/templates/job-init.yaml index 4ebca0339..a20595777 100644 --- a/k8s/templates/job-init.yaml +++ b/k8s/templates/job-init.yaml @@ -12,7 +12,7 @@ spec: image: {{ include "chart.lifemonitor.image" . }} imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} command: ["/bin/sh","-c"] - args: ["wait-for-postgres.sh && flask init db"] + args: ["wait-for-postgres.sh && flask init db && flask task-queue reset"] env: {{- include "lifemonitor.common-env" . | nindent 10 }} volumeMounts: diff --git a/k8s/templates/job-upgrade.yaml b/k8s/templates/job-upgrade.yaml index 11f3fd022..34008f66f 100644 --- a/k8s/templates/job-upgrade.yaml +++ b/k8s/templates/job-upgrade.yaml @@ -18,7 +18,7 @@ spec: image: {{ include "chart.lifemonitor.image" . }} imagePullPolicy: {{ .Values.lifemonitor.imagePullPolicy }} command: ["/bin/sh","-c"] - args: ["wait-for-postgres.sh && flask init db"] + args: ["wait-for-postgres.sh && flask init db && flask task-queue reset"] env: {{ include "lifemonitor.common-env" . | indent 10 }} volumeMounts: From 4daadfe01a0f250191fe1ed5a0e7ff7ed10a49dd Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Tue, 23 Nov 2021 17:29:26 +0000 Subject: [PATCH 19/21] Update default host of PostgreSQL service --- settings.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.conf b/settings.conf index 8e7b80cc5..e817ee59e 100644 --- a/settings.conf +++ b/settings.conf @@ -35,7 +35,7 @@ FLASK_ENV=development LIFEMONITOR_ADMIN_PASSWORD=admin # PostgreSQL DBMS settings -#POSTGRESQL_HOST=0.0.0.0 +POSTGRESQL_HOST=db POSTGRESQL_PORT=5432 POSTGRESQL_DATABASE=lm POSTGRESQL_USERNAME=lm From 115f1aa9109aac9b5bdd9e1c4d64eb3dbc4c11c9 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Tue, 23 Nov 2021 18:15:27 +0000 Subject: [PATCH 20/21] Allow to configure worker threads --- docker/worker_entrypoint.sh | 8 +++++++- k8s/templates/secret.yaml | 3 +++ k8s/values.yaml | 1 + settings.conf | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docker/worker_entrypoint.sh b/docker/worker_entrypoint.sh index 056a20b17..875ada86d 100755 --- a/docker/worker_entrypoint.sh +++ b/docker/worker_entrypoint.sh @@ -41,11 +41,17 @@ if [[ -n "${WORKER_PROCESSES:-}" ]]; then log "Worker starting ${WORKER_PROCESSES} processes" fi +if [[ -n "${WORKER_THREADS:-}" ]]; then + processes="--threads ${WORKER_THREADS}" + log "Worker starting with ${WORKER_THREADS} threads per process" +fi + while : ; do - /usr/local/bin/dramatiq \ + /opt/homebrew/bin/dramatiq \ ${verbose:-} \ ${watch:-} \ ${processes:-} \ + ${threads:-} \ lifemonitor.tasks.worker:broker lifemonitor.tasks.tasks exit_code=$? if [[ $exit_code == 3 ]]; then diff --git a/k8s/templates/secret.yaml b/k8s/templates/secret.yaml index df8697f90..73af94f14 100644 --- a/k8s/templates/secret.yaml +++ b/k8s/templates/secret.yaml @@ -38,6 +38,9 @@ stringData: # Dramatiq worker settings WORKER_PROCESSES={{ .Values.worker.processes }} + {{- if .Values.worker.threads }} + WORKER_THREADS={{ .Values.worker.threads }} + {{- end }} # Redis settings REDIS_HOST={{ .Release.Name }}-redis-master diff --git a/k8s/values.yaml b/k8s/values.yaml index 296ba6abb..07683f742 100644 --- a/k8s/values.yaml +++ b/k8s/values.yaml @@ -143,6 +143,7 @@ worker: imagePullSecrets: [] processes: 1 + #threads: 1 podAnnotations: {} diff --git a/settings.conf b/settings.conf index e817ee59e..abd95c5d4 100644 --- a/settings.conf +++ b/settings.conf @@ -47,6 +47,7 @@ GUNICORN_THREADS=2 # Dramatiq worker settings WORKER_PROCESSES=1 +WORKER_THREADS=3 # Redis settings REDIS_HOST=redis From e41e13dbea1a199df691dc1a438a250bf9523d94 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Wed, 24 Nov 2021 08:12:04 +0000 Subject: [PATCH 21/21] Restore path of dramatiq --- docker/worker_entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/worker_entrypoint.sh b/docker/worker_entrypoint.sh index 875ada86d..9e78003c1 100755 --- a/docker/worker_entrypoint.sh +++ b/docker/worker_entrypoint.sh @@ -47,7 +47,7 @@ if [[ -n "${WORKER_THREADS:-}" ]]; then fi while : ; do - /opt/homebrew/bin/dramatiq \ + /usr/local/bin/dramatiq \ ${verbose:-} \ ${watch:-} \ ${processes:-} \