Skip to content

Commit

Permalink
Add annotations to all Kubernetes resources (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
raminqaf authored Oct 29, 2024
1 parent 8cafb5b commit 4b32eec
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 33 deletions.
13 changes: 13 additions & 0 deletions charts/producer-app-cleanup-job/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ 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 -}}


{{/*
Helper function to add annotations to resources
*/}}
{{- define "producer-app.annotations" -}}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions charts/producer-app-cleanup-job/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "producer-app.name" . }}
{{- include "producer-app.annotations" . }}
data:
{{- range $key, $value := .Values.files }}
{{ $key }}: {{ $value.content | quote }}
Expand Down
7 changes: 1 addition & 6 deletions charts/producer-app-cleanup-job/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "producer-app.fullname" . }}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
Expand Down
1 change: 1 addition & 0 deletions charts/producer-app-cleanup-job/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
type: Opaque
data:
{{- range $key, $value := .Values.secrets }}
Expand Down
12 changes: 12 additions & 0 deletions charts/producer-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ 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 -}}

{{/*
Helper function to add annotations to resources
*/}}
{{- define "producer-app.annotations" -}}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions charts/producer-app/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "producer-app.name" . }}
{{- include "producer-app.annotations" . }}
data:
{{- range $key, $value := .Values.files }}
{{ $key }}: {{ $value.content | quote }}
Expand Down
7 changes: 1 addition & 6 deletions charts/producer-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: {{ template "producer-app.fullname" . }}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
Expand Down
7 changes: 1 addition & 6 deletions charts/producer-app/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ kind: Job
{{- end }}
metadata:
name: {{ template "producer-app.fullname" . }}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
Expand Down
1 change: 1 addition & 0 deletions charts/producer-app/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
type: Opaque
data:
{{- range $key, $value := .Values.secrets }}
Expand Down
1 change: 1 addition & 0 deletions charts/producer-app/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "producer-app.fullname" . }}
{{- include "producer-app.annotations" . }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
Expand Down
12 changes: 12 additions & 0 deletions charts/streams-app-cleanup-job/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ Create chart name and version as used by the chart label.
{{- define "streams-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Helper function to add annotations to resources
*/}}
{{- define "streams-app.annotations" -}}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions charts/streams-app-cleanup-job/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "streams-app.name" . }}
{{- include "streams-app.annotations" . }}
data:
{{- range $key, $value := .Values.files }}
{{ $key }}: {{ $value.content | quote }}
Expand Down
7 changes: 1 addition & 6 deletions charts/streams-app-cleanup-job/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "streams-app.fullname" . }}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- include "streams-app.annotations" . }}
labels:
app: {{ template "streams-app.name" . }}
chart: {{ template "streams-app.chart" . }}
Expand Down
1 change: 1 addition & 0 deletions charts/streams-app-cleanup-job/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "streams-app.fullname" . }}
{{- include "streams-app.annotations" . }}
type: Opaque
data:
{{- range $key, $value := .Values.secrets }}
Expand Down
32 changes: 32 additions & 0 deletions charts/streams-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,35 @@ Create chart name and version as used by the chart label.
{{- define "streams-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Define default annotations from .Values.annotations.
This will be used across resources.
*/}}
{{- define "streams-app.annotations" -}}
{{- if or .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Define annotations helper for Deployment.
Includes default annotations and conditionally adds consumerGroup if applicable.
*/}}
{{- define "streams-app.deployment-annotations" -}}
{{- if or .Values.annotations .Values.kafka.applicationId }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}

{{- /* Conditionally add the consumerGroup annotation if needed */ -}}
{{- if and .Values.kafka.applicationId (not .Values.annotations.consumerGroup) }}
consumerGroup: {{ .Values.kafka.applicationId | quote }}
{{- end }}
{{- end }}
{{- end }}

1 change: 1 addition & 0 deletions charts/streams-app/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "streams-app.name" . }}
{{- include "streams-app.annotations" . }}
data:
{{- range $key, $value := .Values.files }}
{{ $key }}: {{ $value.content | quote }}
Expand Down
10 changes: 1 addition & 9 deletions charts/streams-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@ kind: Deployment
{{- end }}
metadata:
name: {{ template "streams-app.fullname" . }}
{{- if or .Values.kafka.applicationId .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- if and .Values.kafka.applicationId (not .Values.annotations.consumerGroup) }}
consumerGroup: {{ .Values.kafka.applicationId | quote }}
{{- end }}
{{- end }}
{{- include "streams-app.deployment-annotations" . }}
labels:
app: {{ template "streams-app.name" . }}
chart: {{ template "streams-app.chart" . }}
Expand Down
1 change: 1 addition & 0 deletions charts/streams-app/templates/jmx-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "streams-app.name" . }}-jmx-configmap
{{- include "streams-app.annotations" . }}
labels:
app: {{ template "streams-app.name" . }}
chart: {{ template "streams-app.chart" . }}
Expand Down
1 change: 1 addition & 0 deletions charts/streams-app/templates/scaled-object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: {{ template "streams-app.fullname" . }}-so
{{- include "streams-app.annotations" . }}
spec:
scaleTargetRef:
{{- if .Capabilities.APIVersions.Has "apps/v1" }}
Expand Down
1 change: 1 addition & 0 deletions charts/streams-app/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "streams-app.fullname" . }}
{{- include "streams-app.annotations" . }}
type: Opaque
data:
{{- range $key, $value := .Values.secrets }}
Expand Down
1 change: 1 addition & 0 deletions charts/streams-app/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "streams-app.fullname" . }}
{{- include "streams-app.annotations" . }}
labels:
app: {{ template "streams-app.name" . }}
chart: {{ template "streams-app.chart" . }}
Expand Down

0 comments on commit 4b32eec

Please sign in to comment.