Skip to content

Commit

Permalink
Merge pull request #167 from maykinmedia/feature/helm-library
Browse files Browse the repository at this point in the history
✨ Added helm library chart
  • Loading branch information
alextreme authored Jan 22, 2025
2 parents b451956 + a5035a2 commit 8739489
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/maykin-utils-lib/.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/
7 changes: 7 additions & 0 deletions charts/maykin-utils-lib/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: maykin-utils-lib
description: A Library Helm chart containing code shared between Maykin helm charts

type: library
version: 0.1.0

9 changes: 9 additions & 0 deletions charts/maykin-utils-lib/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/maykin-utils-lib/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/maykin-utils-lib/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 }}

0 comments on commit 8739489

Please sign in to comment.