From f463e79bded1e50308e7e0aced11b7cfe2c010d2 Mon Sep 17 00:00:00 2001 From: Lars Francke Date: Thu, 27 Aug 2026 22:48:41 +0200 Subject: [PATCH] chore: Namespace the Helm defined templates with the chart name Helm shares one namespace for defined templates between a chart and all of its subcharts, so identically named ones collide under an umbrella Chart. A define name is fixed when Helm parses the template, so the chart name has to be substituted at generation time. That makes the three helper files and service.yaml Jinja templates. The call sites in the files each operator owns are not templated, so every generated PR needs a follow-up commit renaming them before it can merge. https://github.com/stackabletech/issues/issues/882 --- .../{_helpers.tpl => _helpers.tpl.j2} | 28 +++++++++---------- .../{_maintenance.tpl => _maintenance.tpl.j2} | 2 +- .../{_telemetry.tpl => _telemetry.tpl.j2} | 4 +-- .../[[operator]]/templates/deployment.yaml.j2 | 24 ++++++++-------- .../{service.yaml => service.yaml.j2} | 6 ++-- .../templates/serviceaccount.yaml.j2 | 12 ++++---- 6 files changed, 38 insertions(+), 38 deletions(-) rename template/deploy/helm/[[operator]]/templates/{_helpers.tpl => _helpers.tpl.j2} (71%) rename template/deploy/helm/[[operator]]/templates/{_maintenance.tpl => _maintenance.tpl.j2} (91%) rename template/deploy/helm/[[operator]]/templates/{_telemetry.tpl => _telemetry.tpl.j2} (93%) rename template/deploy/helm/[[operator]]/templates/{service.yaml => service.yaml.j2} (74%) diff --git a/template/deploy/helm/[[operator]]/templates/_helpers.tpl b/template/deploy/helm/[[operator]]/templates/_helpers.tpl.j2 similarity index 71% rename from template/deploy/helm/[[operator]]/templates/_helpers.tpl rename to template/deploy/helm/[[operator]]/templates/_helpers.tpl.j2 index e5354470..a4e41789 100644 --- a/template/deploy/helm/[[operator]]/templates/_helpers.tpl +++ b/template/deploy/helm/[[operator]]/templates/_helpers.tpl.j2 @@ -1,14 +1,14 @@ {{/* Expand the name of the chart. */}} -{{- define "operator.name" -}} +{{- define "{[ operator.name }].name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-operator" }} {{- end }} {{/* Expand the name of the chart. */}} -{{- define "operator.appname" -}} +{{- define "{[ operator.name }].appname" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} @@ -17,7 +17,7 @@ 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 "operator.fullname" -}} +{{- define "{[ operator.name }].fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} @@ -33,16 +33,16 @@ If release name contains chart name it will be used as a full name. {{/* Create chart name and version as used by the chart label. */}} -{{- define "operator.chart" -}} +{{- define "{[ operator.name }].chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Common labels */}} -{{- define "operator.labels" -}} -helm.sh/chart: {{ include "operator.chart" . }} -{{ include "operator.selectorLabels" . }} +{{- define "{[ operator.name }].labels" -}} +helm.sh/chart: {{ include "{[ operator.name }].chart" . }} +{{ include "{[ operator.name }].selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -52,8 +52,8 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{/* Selector labels */}} -{{- define "operator.selectorLabels" -}} -app.kubernetes.io/name: {{ include "operator.appname" . }} +{{- define "{[ operator.name }].selectorLabels" -}} +app.kubernetes.io/name: {{ include "{[ operator.name }].appname" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- with .Values.labels }} {{ toYaml . }} @@ -63,9 +63,9 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{/* Create the name of the service account to use */}} -{{- define "operator.serviceAccountName" -}} +{{- define "{[ operator.name }].serviceAccountName" -}} {{- if .Values.serviceAccount.create }} -{{- default (printf "%s-serviceaccount" (include "operator.fullname" .)) .Values.serviceAccount.name }} +{{- default (printf "%s-serviceaccount" (include "{[ operator.name }].fullname" .)) .Values.serviceAccount.name }} {{- else }} {{- required "serviceAccount.name is required when serviceAccount.create is false, because the chart then does not create a ServiceAccount for the operator to run as." .Values.serviceAccount.name }} {{- end }} @@ -74,13 +74,13 @@ Create the name of the service account to use {{/* Labels for Kubernetes objects created by helm test */}} -{{- define "operator.testLabels" -}} -helm.sh/test: {{ include "operator.chart" . }} +{{- define "{[ operator.name }].testLabels" -}} +helm.sh/test: {{ include "{[ operator.name }].chart" . }} {{- end }} {{/* Build the full operator container image reference. */}} -{{- define "operator.image" -}} +{{- define "{[ operator.name }].image" -}} {{- printf "%s/%s:%s" .Values.image.repository .Chart.Name (.Values.image.tag | default .Chart.AppVersion) -}} {{- end }} diff --git a/template/deploy/helm/[[operator]]/templates/_maintenance.tpl b/template/deploy/helm/[[operator]]/templates/_maintenance.tpl.j2 similarity index 91% rename from template/deploy/helm/[[operator]]/templates/_maintenance.tpl rename to template/deploy/helm/[[operator]]/templates/_maintenance.tpl.j2 index 85afd7f2..141b6265 100644 --- a/template/deploy/helm/[[operator]]/templates/_maintenance.tpl +++ b/template/deploy/helm/[[operator]]/templates/_maintenance.tpl.j2 @@ -1,7 +1,7 @@ {{/* Create a list of maintenance related env vars. */}} -{{- define "maintenance.envVars" -}} +{{- define "{[ operator.name }].maintenance.envVars" -}} {{- with .Values.maintenance }} {{- if not .endOfSupportCheck.enabled }} - name: EOS_DISABLED diff --git a/template/deploy/helm/[[operator]]/templates/_telemetry.tpl b/template/deploy/helm/[[operator]]/templates/_telemetry.tpl.j2 similarity index 93% rename from template/deploy/helm/[[operator]]/templates/_telemetry.tpl rename to template/deploy/helm/[[operator]]/templates/_telemetry.tpl.j2 index 8ef99bbf..ccf5b5cf 100644 --- a/template/deploy/helm/[[operator]]/templates/_telemetry.tpl +++ b/template/deploy/helm/[[operator]]/templates/_telemetry.tpl.j2 @@ -1,7 +1,7 @@ {{/* Create a list of telemetry related env vars. */}} -{{- define "telemetry.envVars" -}} +{{- define "{[ operator.name }].telemetry.envVars" -}} {{- with .Values.telemetry }} {{- if not .consoleLog.enabled }} - name: CONSOLE_LOG_DISABLED @@ -17,7 +17,7 @@ Create a list of telemetry related env vars. {{ end }} {{- if .fileLog.enabled }} - name: FILE_LOG_DIRECTORY - value: /stackable/logs/{{ include "operator.appname" $ }} + value: /stackable/logs/{{ include "{[ operator.name }].appname" $ }} {{- end }} {{- if and .fileLog.enabled .fileLog.level }} - name: FILE_LOG_LEVEL diff --git a/template/deploy/helm/[[operator]]/templates/deployment.yaml.j2 b/template/deploy/helm/[[operator]]/templates/deployment.yaml.j2 index fc7fdf63..fec22b49 100644 --- a/template/deploy/helm/[[operator]]/templates/deployment.yaml.j2 +++ b/template/deploy/helm/[[operator]]/templates/deployment.yaml.j2 @@ -3,20 +3,20 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "operator.fullname" . }}-deployment + name: {{ include "{[ operator.name }].fullname" . }}-deployment labels: - {{- include "operator.labels" . | nindent 4 }} + {{- include "{[ operator.name }].labels" . | nindent 4 }} spec: replicas: 1 strategy: type: Recreate selector: matchLabels: - {{- include "operator.selectorLabels" . | nindent 6 }} + {{- include "{[ operator.name }].selectorLabels" . | nindent 6 }} template: metadata: annotations: - internal.stackable.tech/image: {{ include "operator.image" . }} + internal.stackable.tech/image: {{ include "{[ operator.name }].image" . }} {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} @@ -24,20 +24,20 @@ spec: {{- if .Values.maintenance.customResourceDefinitions.maintain }} webhook.stackable.tech/conversion: enabled {{- end }} - {{- include "operator.selectorLabels" . | nindent 8 }} + {{- include "{[ operator.name }].selectorLabels" . | nindent 8 }} spec: {{- with .Values.image.pullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ include "operator.serviceAccountName" . }} + serviceAccountName: {{ include "{[ operator.name }].serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - - name: {{ include "operator.appname" . }} + - name: {{ include "{[ operator.name }].appname" . }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - image: {{ include "operator.image" . }} + image: {{ include "{[ operator.name }].image" . }} imagePullPolicy: {{ .Values.image.pullPolicy }} resources: {{- toYaml .Values.resources | nindent 12 }} @@ -65,7 +65,7 @@ spec: # The name of the Kubernetes Service that point to the operator Pod, e.g. used to # construct the conversion webhook endpoint. - name: OPERATOR_SERVICE_NAME - value: {{ include "operator.fullname" . }} + value: {{ include "{[ operator.name }].fullname" . }} {[% if operator.config.has_product | default(true) %}] # The product image repository, like "oci.stackable.tech/sdp". @@ -89,11 +89,11 @@ spec: value: {{ .Values.kubernetesClusterDomain | quote }} {{- end }} - {{- include "telemetry.envVars" . | nindent 12 }} - {{- include "maintenance.envVars" . | nindent 12 }} + {{- include "{[ operator.name }].telemetry.envVars" . | nindent 12 }} + {{- include "{[ operator.name }].maintenance.envVars" . | nindent 12 }} {[% if operator.product_string in ['opa'] %}] - name: OPA_BUNDLE_BUILDER_CLUSTERROLE - value: {{ include "operator.fullname" . }}-opa-bundle-builder-clusterrole + value: {{ include "{[ operator.name }].fullname" . }}-opa-bundle-builder-clusterrole {[% endif %}] {{- with .Values.nodeSelector }} nodeSelector: diff --git a/template/deploy/helm/[[operator]]/templates/service.yaml b/template/deploy/helm/[[operator]]/templates/service.yaml.j2 similarity index 74% rename from template/deploy/helm/[[operator]]/templates/service.yaml rename to template/deploy/helm/[[operator]]/templates/service.yaml.j2 index 978f914d..8b34cd84 100644 --- a/template/deploy/helm/[[operator]]/templates/service.yaml +++ b/template/deploy/helm/[[operator]]/templates/service.yaml.j2 @@ -6,15 +6,15 @@ metadata: # Note(@sbernauer): We could also call the Service something like # "product-operator-conversion-webhook". However, in the future we will have more webhooks, and # it seems like an overkill to have a dedicated Service per webhook. - name: {{ include "operator.fullname" . }} + name: {{ include "{[ operator.name }].fullname" . }} labels: - {{- include "operator.labels" . | nindent 4 }} + {{- include "{[ operator.name }].labels" . | nindent 4 }} spec: selector: {{- if .Values.maintenance.customResourceDefinitions.maintain }} webhook.stackable.tech/conversion: enabled {{- end }} - {{- include "operator.selectorLabels" . | nindent 4 }} + {{- include "{[ operator.name }].selectorLabels" . | nindent 4 }} ports: - name: conversion-webhook protocol: TCP diff --git a/template/deploy/helm/[[operator]]/templates/serviceaccount.yaml.j2 b/template/deploy/helm/[[operator]]/templates/serviceaccount.yaml.j2 index e0d959e2..72d2d86b 100644 --- a/template/deploy/helm/[[operator]]/templates/serviceaccount.yaml.j2 +++ b/template/deploy/helm/[[operator]]/templates/serviceaccount.yaml.j2 @@ -3,9 +3,9 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "operator.serviceAccountName" . }} + name: {{ include "{[ operator.name }].serviceAccountName" . }} labels: - {{- include "operator.labels" . | nindent 4 }} + {{- include "{[ operator.name }].labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} @@ -17,14 +17,14 @@ apiVersion: rbac.authorization.k8s.io/v1 # operator watch and manage its custom resources across the cluster. kind: ClusterRoleBinding metadata: - name: {{ include "operator.fullname" . }}-clusterrolebinding + name: {{ include "{[ operator.name }].fullname" . }}-clusterrolebinding labels: - {{- include "operator.labels" . | nindent 4 }} + {{- include "{[ operator.name }].labels" . | nindent 4 }} subjects: - kind: ServiceAccount - name: {{ include "operator.serviceAccountName" . }} + name: {{ include "{[ operator.name }].serviceAccountName" . }} namespace: {{ .Release.Namespace }} roleRef: kind: ClusterRole - name: {{ include "operator.fullname" . }}-clusterrole + name: {{ include "{[ operator.name }].fullname" . }}-clusterrole apiGroup: rbac.authorization.k8s.io