Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#165] Liveness probes experiment [DONT merge] #166

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions charts/maykinhelmlib/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
12 changes: 12 additions & 0 deletions charts/maykinhelmlib/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v2
name: maykinhelmlib
description: A Library Helm chart containing code shared between Maykin helm charts

type: library

# 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.0


9 changes: 9 additions & 0 deletions charts/maykinhelmlib/templates/_celery-configmap.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- define "maykinhelmlib.celeryEnvConfigmap" -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "project.fullname" . }}-worker-{{ .Values.worker.label | default "celery" }}
data:
CELERY_WORKER_QUEUE: {{ .Values.worker.queueName | default "" }}
CELERY_WORKER_NAME: {{ .Values.worker.name | default "" }}
{{- end -}}
31 changes: 31 additions & 0 deletions charts/maykinhelmlib/templates/_celery-liveness-configmap.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- define "maykinhelmlib.celeryLivenessConfigmap" -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "project.fullname" . }}-celery-liveness
data:
liveness-probe.sh: |
#!/bin/bash

# Exit immediately if a non-zero exit code is returned
set -e

QUEUE_NAME=${CELERY_WORKER_QUEUE:-celery}

# Check if CELERY_WORKER_NAME is set
if [ -z "$CELERY_WORKER_NAME" ]; then
# If not set
WORKER_NAME="${QUEUE_NAME}@${HOSTNAME}"
else
# If set and contains the '@' symbol
if [[ "$CELERY_WORKER_NAME" != *"@"* ]]; then
# If not, update CELERY_WORKER_NAME to celery@${CELERY_WORKER_NAME}
WORKER_NAME="celery@${CELERY_WORKER_NAME}"
else
WORKER_NAME="${CELERY_WORKER_NAME}"
fi
fi

# Use CELERY_WORKER_NAME to set the --destination flag
celery --workdir src --app {{ include "application.name" . }}.celery inspect --destination "$WORKER_NAME" active
{{- end -}}
25 changes: 25 additions & 0 deletions charts/maykinhelmlib/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- define "application.name" -}}
{{- default .Values.pythonAppName }}
{{- end }}

{{- define "project.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "project.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
7 changes: 5 additions & 2 deletions charts/openarchiefbeheer/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ dependencies:
- name: redis
repository: https://charts.bitnami.com/bitnami
version: 17.3.14
digest: sha256:9a575d102b6aa617223725968198a70072cee90595377df08ae62cef7c32cf4a
generated: "2023-02-28T13:57:35.331737607+01:00"
- name: maykinhelmlib
repository: file://../maykinhelmlib
version: 0.1.0
digest: sha256:6bba46f6db2fb930fa5a94723b5c1cdde49ada53fd94bb78e6787b46ee63440b
generated: "2025-01-15T12:10:10.907988903+01:00"
5 changes: 4 additions & 1 deletion charts/openarchiefbeheer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ dependencies:
version: 17.3.14
repository: https://charts.bitnami.com/bitnami
tags:
- redis
- redis
- name: maykinhelmlib
version: 0.1.0
repository: file://../maykinhelmlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if .Values.worker.livenessProbe.enabled }}
{{- include "maykinhelmlib.celeryLivenessConfigmap" . -}}
{{- end }}
1 change: 1 addition & 0 deletions charts/openarchiefbeheer/templates/configmap-celery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- include "maykinhelmlib.celeryEnvConfigmap" . -}}
13 changes: 13 additions & 0 deletions charts/openarchiefbeheer/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ spec:
name: {{ .Values.existingSecret | default (include "openarchiefbeheer.fullname" .) }}
- configMapRef:
name: {{ include "openarchiefbeheer.fullname" . }}
- configMapRef:
name: {{ include "project.fullname" . }}-worker-{{ .Values.worker.label | default "celery" }}
env:
{{- if .Values.extraEnvVars }}
{{- include "openarchiefbeheer.tplvalues.render" (dict "value" .Values.extraEnvVars "context" $) | nindent 12 }}
Expand Down Expand Up @@ -300,6 +302,11 @@ spec:
{{- if .Values.extraVolumeMounts }}
{{- include "openarchiefbeheer.tplvalues.render" ( dict "value" .Values.extraVolumeMounts "context" $ ) | nindent 12 }}
{{- end }}
{{- if .Values.worker.livenessProbe.enabled }}
- name: liveness
mountPath: /app/liveness/
readOnly: true
{{- end }}
volumes:
- name: media
persistentVolumeClaim:
Expand All @@ -311,6 +318,12 @@ spec:
{{- if .Values.extraVolumes }}
{{- include "openarchiefbeheer.tplvalues.render" ( dict "value" .Values.extraVolumes "context" $ ) | nindent 8 }}
{{- end }}
{{- if .Values.worker.livenessProbe.enabled }}
- name: liveness
configMap:
name: {{ include "project.fullname" . }}-celery-liveness
defaultMode: 0555
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
10 changes: 6 additions & 4 deletions charts/openarchiefbeheer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ extraEnvVars: []
extraVolumes: []
extraVolumeMounts: []

pythonAppName: openarchiefbeheer
settings:
allowedHosts: ""
djangoSettingsModule: openarchiefbeheer.conf.docker
Expand Down Expand Up @@ -251,17 +252,18 @@ settings:
frontendUrl: ""

worker:
label: "1"
name: ""
queueName: ""
replicaCount: 1
concurrency: 4
podLabels: {}
resources: {}
livenessProbe:
enabled: false
enabled: true
exec:
command:
- /bin/sh
- -c
- celery --workdir src --app openarchiefbeheer.celery inspect --destination celery@${HOSTNAME} active
- /app/liveness/liveness-probe.sh
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 10
Expand Down
Loading