diff --git a/charts/producer-app-cleanup-job/templates/_helpers.tpl b/charts/producer-app-cleanup-job/templates/_helpers.tpl index f21b03b8..62aa7f71 100644 --- a/charts/producer-app-cleanup-job/templates/_helpers.tpl +++ b/charts/producer-app-cleanup-job/templates/_helpers.tpl @@ -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 }} diff --git a/charts/producer-app-cleanup-job/templates/configmap.yaml b/charts/producer-app-cleanup-job/templates/configmap.yaml index da5bb989..80de6dab 100644 --- a/charts/producer-app-cleanup-job/templates/configmap.yaml +++ b/charts/producer-app-cleanup-job/templates/configmap.yaml @@ -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 }} diff --git a/charts/producer-app-cleanup-job/templates/job.yaml b/charts/producer-app-cleanup-job/templates/job.yaml index 6bb59be3..5a59b8ec 100644 --- a/charts/producer-app-cleanup-job/templates/job.yaml +++ b/charts/producer-app-cleanup-job/templates/job.yaml @@ -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" . }} diff --git a/charts/producer-app-cleanup-job/templates/secrets.yaml b/charts/producer-app-cleanup-job/templates/secrets.yaml index 7dccd797..ed82c698 100644 --- a/charts/producer-app-cleanup-job/templates/secrets.yaml +++ b/charts/producer-app-cleanup-job/templates/secrets.yaml @@ -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 }} diff --git a/charts/producer-app/templates/_helpers.tpl b/charts/producer-app/templates/_helpers.tpl index 9e91e893..fab64375 100644 --- a/charts/producer-app/templates/_helpers.tpl +++ b/charts/producer-app/templates/_helpers.tpl @@ -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 }} diff --git a/charts/producer-app/templates/configmap.yaml b/charts/producer-app/templates/configmap.yaml index da5bb989..80de6dab 100644 --- a/charts/producer-app/templates/configmap.yaml +++ b/charts/producer-app/templates/configmap.yaml @@ -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 }} diff --git a/charts/producer-app/templates/deployment.yaml b/charts/producer-app/templates/deployment.yaml index 1799ecb0..dceae867 100644 --- a/charts/producer-app/templates/deployment.yaml +++ b/charts/producer-app/templates/deployment.yaml @@ -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" . }} diff --git a/charts/producer-app/templates/job.yaml b/charts/producer-app/templates/job.yaml index f884c708..bbd729aa 100644 --- a/charts/producer-app/templates/job.yaml +++ b/charts/producer-app/templates/job.yaml @@ -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" . }} diff --git a/charts/producer-app/templates/secrets.yaml b/charts/producer-app/templates/secrets.yaml index 7dccd797..ed82c698 100644 --- a/charts/producer-app/templates/secrets.yaml +++ b/charts/producer-app/templates/secrets.yaml @@ -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 }} diff --git a/charts/producer-app/templates/service.yaml b/charts/producer-app/templates/service.yaml index 41cc7c02..fa4ca75a 100644 --- a/charts/producer-app/templates/service.yaml +++ b/charts/producer-app/templates/service.yaml @@ -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" . }} diff --git a/charts/streams-app-cleanup-job/templates/_helpers.tpl b/charts/streams-app-cleanup-job/templates/_helpers.tpl index 4944f922..efecc7d0 100644 --- a/charts/streams-app-cleanup-job/templates/_helpers.tpl +++ b/charts/streams-app-cleanup-job/templates/_helpers.tpl @@ -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 }} diff --git a/charts/streams-app-cleanup-job/templates/configmap.yaml b/charts/streams-app-cleanup-job/templates/configmap.yaml index 98c4aee3..03f0db84 100644 --- a/charts/streams-app-cleanup-job/templates/configmap.yaml +++ b/charts/streams-app-cleanup-job/templates/configmap.yaml @@ -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 }} diff --git a/charts/streams-app-cleanup-job/templates/job.yaml b/charts/streams-app-cleanup-job/templates/job.yaml index c1957cf7..d03a5f01 100644 --- a/charts/streams-app-cleanup-job/templates/job.yaml +++ b/charts/streams-app-cleanup-job/templates/job.yaml @@ -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" . }} diff --git a/charts/streams-app-cleanup-job/templates/secrets.yaml b/charts/streams-app-cleanup-job/templates/secrets.yaml index feb79e5b..8c818c94 100644 --- a/charts/streams-app-cleanup-job/templates/secrets.yaml +++ b/charts/streams-app-cleanup-job/templates/secrets.yaml @@ -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 }} diff --git a/charts/streams-app/templates/_helpers.tpl b/charts/streams-app/templates/_helpers.tpl index 4944f922..4ab36d95 100644 --- a/charts/streams-app/templates/_helpers.tpl +++ b/charts/streams-app/templates/_helpers.tpl @@ -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 }} + diff --git a/charts/streams-app/templates/configmap.yaml b/charts/streams-app/templates/configmap.yaml index 98c4aee3..03f0db84 100644 --- a/charts/streams-app/templates/configmap.yaml +++ b/charts/streams-app/templates/configmap.yaml @@ -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 }} diff --git a/charts/streams-app/templates/deployment.yaml b/charts/streams-app/templates/deployment.yaml index 5e5c9b43..781ee057 100644 --- a/charts/streams-app/templates/deployment.yaml +++ b/charts/streams-app/templates/deployment.yaml @@ -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" . }} diff --git a/charts/streams-app/templates/jmx-configmap.yaml b/charts/streams-app/templates/jmx-configmap.yaml index 14ff70aa..42339d73 100644 --- a/charts/streams-app/templates/jmx-configmap.yaml +++ b/charts/streams-app/templates/jmx-configmap.yaml @@ -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" . }} diff --git a/charts/streams-app/templates/scaled-object.yaml b/charts/streams-app/templates/scaled-object.yaml index c484b492..1eca859e 100644 --- a/charts/streams-app/templates/scaled-object.yaml +++ b/charts/streams-app/templates/scaled-object.yaml @@ -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" }} diff --git a/charts/streams-app/templates/secrets.yaml b/charts/streams-app/templates/secrets.yaml index feb79e5b..8c818c94 100644 --- a/charts/streams-app/templates/secrets.yaml +++ b/charts/streams-app/templates/secrets.yaml @@ -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 }} diff --git a/charts/streams-app/templates/service.yaml b/charts/streams-app/templates/service.yaml index df54dc0a..596d7f1e 100644 --- a/charts/streams-app/templates/service.yaml +++ b/charts/streams-app/templates/service.yaml @@ -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" . }}