Skip to content

Commit

Permalink
Use Helm best practices (#281)
Browse files Browse the repository at this point in the history
Fixes #170
  • Loading branch information
philipp94831 authored Mar 4, 2025
1 parent 4f47125 commit cb1fa69
Show file tree
Hide file tree
Showing 28 changed files with 267 additions and 135 deletions.
46 changes: 34 additions & 12 deletions charts/producer-app-cleanup-job/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,53 @@
Expand the name of the chart.
*/}}
{{- define "producer-app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- 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 "producer-app.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Values.nameOverride -}}
{{- printf "%s" $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- 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 }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "producer-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "producer-app.labels" -}}
helm.sh/chart: {{ include "producer-app.chart" . }}
{{ include "producer-app.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "producer-app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "producer-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Helper function to add annotations to resources
Expand Down
7 changes: 6 additions & 1 deletion charts/producer-app-cleanup-job/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "producer-app.name" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
{{- include "producer-app.labels" . | nindent 4 }}
{{- range $key, $value := .Values.labels }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
data:
{{- range $key, $value := .Values.files }}
{{ $key }}: {{ $value.content | quote }}
Expand Down
17 changes: 7 additions & 10 deletions charts/producer-app-cleanup-job/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "producer-app.fullname" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
release: {{ .Release.Name }}
{{- include "producer-app.labels" . | nindent 4 }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
spec:
ttlSecondsAfterFinished: 30
Expand All @@ -22,8 +20,7 @@ spec:
{{- end }}
{{- end }}
labels:
app: {{ template "producer-app.name" . }}
release: {{ .Release.Name }}
{{- include "producer-app.labels" . | nindent 8 }}
{{- range $key, $value := .Values.podLabels }}
{{ $key }}: {{ $value }}
{{- end }}
Expand All @@ -45,7 +42,7 @@ spec:
{{- toYaml .Values.imagePullSecrets | nindent 8 }}
{{- end }}
containers:
- name: {{ template "producer-app.name" . }}
- name: "kafka-app"
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
imagePullPolicy: "{{ .Values.imagePullPolicy }}"
resources:
Expand Down Expand Up @@ -79,7 +76,7 @@ spec:
- name: "{{ $key }}"
valueFrom:
secretKeyRef:
name: {{ template "producer-app.fullname" $ }}
name: {{ include "producer-app.fullname" . }}
key: "{{ $key }}"
{{- end }}
{{- range $key, $value := .Values.secretRefs }}
Expand Down Expand Up @@ -123,7 +120,7 @@ spec:
{{- if .Values.files }}
- name: config
configMap:
name: {{ template "producer-app.name" . }}
name: {{ include "producer-app.fullname" . }}
{{- end }}
{{- range .Values.secretFilesRefs }}
- name: {{ .volume }}
Expand Down
7 changes: 6 additions & 1 deletion charts/producer-app-cleanup-job/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "producer-app.fullname" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
{{- include "producer-app.labels" . | nindent 4 }}
{{- range $key, $value := .Values.labels }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
type: Opaque
data:
{{- range $key, $value := .Values.secrets }}
Expand Down
3 changes: 2 additions & 1 deletion charts/producer-app-cleanup-job/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
nameOverride: bakdata-producer-app-job
nameOverride: ""
fullnameOverride: ""

image: producerApp
imageTag: latest
Expand Down
7 changes: 4 additions & 3 deletions charts/producer-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ Alternatively, a YAML file that specifies the values for the parameters can be p
### Job

| Parameter | Description | Default |
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| `nameOverride` | The name of the Kubernetes deployment. | `bakdata-producer-app` |
|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| `nameOverride` | The name of the chart. | |
| `fullnameOverride` | The full qualified app name. | |
| `resources` | See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | see [values.yaml](values.yaml) for details |
| `annotations` | Map of custom annotations to attach to the deployment. | `{}` |
| `labels` | Map of custom labels to attach to the deployment. | `{}` |
| `tolerations` | Array containing taint references. When defined, pods can run on nodes, which would otherwise deny scheduling. Further information can be found in the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) | `{}` |
| `affinity` | Map to configure [pod affinities](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity). | `{}` |
| `affinity` | Map to configure [pod affinities](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity). | `{}` |
| `deployment` | Deploy the producer as a Kubernetes Deployment (thereby ignoring Job-related configurations) | false |
| `restartPolicy` | [Restart policy](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) to use for the job. | `OnFailure` |
| `schedule` | Cron expression to denote a schedule this producer app should be run on. It will then be deployed as a [CronJob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) instead of a [Job](https://kubernetes.io/docs/concepts/workloads/controllers/job/). | |
Expand Down
46 changes: 35 additions & 11 deletions charts/producer-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,53 @@
Expand the name of the chart.
*/}}
{{- define "producer-app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- 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 "producer-app.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Values.nameOverride -}}
{{- printf "%s" $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- 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 }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "producer-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "producer-app.labels" -}}
helm.sh/chart: {{ include "producer-app.chart" . }}
{{ include "producer-app.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "producer-app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "producer-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Helper function to add annotations to resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ metadata:
{{- end }}
{{- end }}
labels:
app: {{ template "producer-app.name" . }}
{{- include "producer-app.labels" . | nindent 4 }}
streams-bootstrap/kind: {{ .Chart.Name }}
release: {{ .Release.Name }}
{{- range $key, $value := .Values.podLabels }}
{{ $key }}: {{ $value }}
{{- end }}
Expand All @@ -37,7 +36,7 @@ spec:
{{- toYaml .Values.imagePullSecrets | nindent 8 }}
{{- end }}
containers:
- name: {{ template "producer-app.name" . }}
- name: "kafka-app"
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
imagePullPolicy: "{{ .Values.imagePullPolicy }}"
resources:
Expand Down Expand Up @@ -69,7 +68,7 @@ spec:
- name: "{{ $key }}"
valueFrom:
secretKeyRef:
name: {{ template "producer-app.fullname" $ }}
name: {{ include "producer-app.fullname" . }}
key: "{{ $key }}"
{{- end }}
{{- range $key, $value := .Values.secretRefs }}
Expand Down Expand Up @@ -129,7 +128,7 @@ spec:
{{- if .Values.files }}
- name: config
configMap:
name: {{ template "producer-app.name" . }}
name: {{ include "producer-app.fullname" . }}
{{- end }}
{{- range .Values.secretFilesRefs }}
- name: {{ .volume }}
Expand Down
7 changes: 6 additions & 1 deletion charts/producer-app/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "producer-app.name" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
{{- include "producer-app.labels" . | nindent 4 }}
{{- range $key, $value := .Values.labels }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
data:
{{- range $key, $value := .Values.files }}
{{ $key }}: {{ $value.content | quote }}
Expand Down
11 changes: 4 additions & 7 deletions charts/producer-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ apiVersion: apps/v1beta1
{{- end }}
kind: Deployment
metadata:
name: {{ template "producer-app.fullname" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
{{- include "producer-app.labels" . | nindent 4 }}
streams-bootstrap/kind: {{ .Chart.Name }}
release: {{ .Release.Name }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "producer-app.name" . }}
release: {{ .Release.Name }}
{{- include "producer-app.selectorLabels" . | nindent 6 }}
template:
{{ include "producer-app.podTemplate" . | indent 4 }}
{{- end }}
16 changes: 11 additions & 5 deletions charts/producer-app/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ apiVersion: batch/v1
kind: Job
{{- end }}
metadata:
name: {{ template "producer-app.fullname" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
{{- include "producer-app.labels" . | nindent 4 }}
streams-bootstrap/kind: {{ .Chart.Name }}
release: {{ .Release.Name }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
spec:
{{- if .Values.schedule }}
Expand All @@ -30,6 +28,14 @@ spec:
failedJobsHistoryLimit: {{ .Values.failedJobsHistoryLimit }}
concurrencyPolicy: Replace
jobTemplate:
metadata:
{{- include "producer-app.annotations" . | indent 4 }}
labels:
{{- include "producer-app.labels" . | nindent 8 }}
streams-bootstrap/kind: {{ .Chart.Name }}
{{- range $key, $value := .Values.labels }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
spec:
{{- if .Values.ttlSecondsAfterFinished }}
ttlSecondsAfterFinished: {{ .Values.ttlSecondsAfterFinished }}
Expand Down
7 changes: 6 additions & 1 deletion charts/producer-app/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "producer-app.fullname" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
{{- include "producer-app.labels" . | nindent 4 }}
{{- range $key, $value := .Values.labels }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
type: Opaque
data:
{{- range $key, $value := .Values.secrets }}
Expand Down
9 changes: 3 additions & 6 deletions charts/producer-app/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "producer-app.fullname" . }}
name: {{ include "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
release: {{ .Release.Name }}
{{- include "producer-app.labels" . | nindent 4 }}
{{- range $key, $value := .Values.service.labels }}
{{ $key }}: {{ $value }}
{{- end }}
spec:
selector:
app: {{ template "producer-app.name" . }}
release: {{ .Release.Name }}
{{- include "producer-app.selectorLabels" . | nindent 4 }}
ports:
{{- range .Values.ports }}
{{- if .servicePort }}
Expand Down
3 changes: 2 additions & 1 deletion charts/producer-app/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
nameOverride: bakdata-producer-app
nameOverride: ""
fullnameOverride: ""

image: producerApp
imageTag: latest
Expand Down
Loading

0 comments on commit cb1fa69

Please sign in to comment.