Skip to content

Commit bcf54b7

Browse files
authored
chore: Namespace the Helm defined templates with the chart name (#645)
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. stackabletech/issues#882
1 parent 76da12b commit bcf54b7

6 files changed

Lines changed: 38 additions & 38 deletions

File tree

template/deploy/helm/[[operator]]/templates/_helpers.tpl renamed to template/deploy/helm/[[operator]]/templates/_helpers.tpl.j2

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{{/*
22
Expand the name of the chart.
33
*/}}
4-
{{- define "operator.name" -}}
4+
{{- define "{[ operator.name }].name" -}}
55
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-operator" }}
66
{{- end }}
77

88
{{/*
99
Expand the name of the chart.
1010
*/}}
11-
{{- define "operator.appname" -}}
11+
{{- define "{[ operator.name }].appname" -}}
1212
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
1313
{{- end }}
1414

@@ -17,7 +17,7 @@ Create a default fully qualified app name.
1717
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1818
If release name contains chart name it will be used as a full name.
1919
*/}}
20-
{{- define "operator.fullname" -}}
20+
{{- define "{[ operator.name }].fullname" -}}
2121
{{- if .Values.fullnameOverride }}
2222
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
2323
{{- else }}
@@ -33,16 +33,16 @@ If release name contains chart name it will be used as a full name.
3333
{{/*
3434
Create chart name and version as used by the chart label.
3535
*/}}
36-
{{- define "operator.chart" -}}
36+
{{- define "{[ operator.name }].chart" -}}
3737
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
3838
{{- end }}
3939

4040
{{/*
4141
Common labels
4242
*/}}
43-
{{- define "operator.labels" -}}
44-
helm.sh/chart: {{ include "operator.chart" . }}
45-
{{ include "operator.selectorLabels" . }}
43+
{{- define "{[ operator.name }].labels" -}}
44+
helm.sh/chart: {{ include "{[ operator.name }].chart" . }}
45+
{{ include "{[ operator.name }].selectorLabels" . }}
4646
{{- if .Chart.AppVersion }}
4747
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4848
{{- end }}
@@ -52,8 +52,8 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
5252
{{/*
5353
Selector labels
5454
*/}}
55-
{{- define "operator.selectorLabels" -}}
56-
app.kubernetes.io/name: {{ include "operator.appname" . }}
55+
{{- define "{[ operator.name }].selectorLabels" -}}
56+
app.kubernetes.io/name: {{ include "{[ operator.name }].appname" . }}
5757
app.kubernetes.io/instance: {{ .Release.Name }}
5858
{{- with .Values.labels }}
5959
{{ toYaml . }}
@@ -63,9 +63,9 @@ app.kubernetes.io/instance: {{ .Release.Name }}
6363
{{/*
6464
Create the name of the service account to use
6565
*/}}
66-
{{- define "operator.serviceAccountName" -}}
66+
{{- define "{[ operator.name }].serviceAccountName" -}}
6767
{{- if .Values.serviceAccount.create }}
68-
{{- default (printf "%s-serviceaccount" (include "operator.fullname" .)) .Values.serviceAccount.name }}
68+
{{- default (printf "%s-serviceaccount" (include "{[ operator.name }].fullname" .)) .Values.serviceAccount.name }}
6969
{{- else }}
7070
{{- 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 }}
7171
{{- end }}
@@ -74,13 +74,13 @@ Create the name of the service account to use
7474
{{/*
7575
Labels for Kubernetes objects created by helm test
7676
*/}}
77-
{{- define "operator.testLabels" -}}
78-
helm.sh/test: {{ include "operator.chart" . }}
77+
{{- define "{[ operator.name }].testLabels" -}}
78+
helm.sh/test: {{ include "{[ operator.name }].chart" . }}
7979
{{- end }}
8080

8181
{{/*
8282
Build the full operator container image reference.
8383
*/}}
84-
{{- define "operator.image" -}}
84+
{{- define "{[ operator.name }].image" -}}
8585
{{- printf "%s/%s:%s" .Values.image.repository .Chart.Name (.Values.image.tag | default .Chart.AppVersion) -}}
8686
{{- end }}

template/deploy/helm/[[operator]]/templates/_maintenance.tpl renamed to template/deploy/helm/[[operator]]/templates/_maintenance.tpl.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{/*
22
Create a list of maintenance related env vars.
33
*/}}
4-
{{- define "maintenance.envVars" -}}
4+
{{- define "{[ operator.name }].maintenance.envVars" -}}
55
{{- with .Values.maintenance }}
66
{{- if not .endOfSupportCheck.enabled }}
77
- name: EOS_DISABLED

template/deploy/helm/[[operator]]/templates/_telemetry.tpl renamed to template/deploy/helm/[[operator]]/templates/_telemetry.tpl.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{/*
22
Create a list of telemetry related env vars.
33
*/}}
4-
{{- define "telemetry.envVars" -}}
4+
{{- define "{[ operator.name }].telemetry.envVars" -}}
55
{{- with .Values.telemetry }}
66
{{- if not .consoleLog.enabled }}
77
- name: CONSOLE_LOG_DISABLED
@@ -17,7 +17,7 @@ Create a list of telemetry related env vars.
1717
{{ end }}
1818
{{- if .fileLog.enabled }}
1919
- name: FILE_LOG_DIRECTORY
20-
value: /stackable/logs/{{ include "operator.appname" $ }}
20+
value: /stackable/logs/{{ include "{[ operator.name }].appname" $ }}
2121
{{- end }}
2222
{{- if and .fileLog.enabled .fileLog.level }}
2323
- name: FILE_LOG_LEVEL

template/deploy/helm/[[operator]]/templates/deployment.yaml.j2

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@
33
apiVersion: apps/v1
44
kind: Deployment
55
metadata:
6-
name: {{ include "operator.fullname" . }}-deployment
6+
name: {{ include "{[ operator.name }].fullname" . }}-deployment
77
labels:
8-
{{- include "operator.labels" . | nindent 4 }}
8+
{{- include "{[ operator.name }].labels" . | nindent 4 }}
99
spec:
1010
replicas: 1
1111
strategy:
1212
type: Recreate
1313
selector:
1414
matchLabels:
15-
{{- include "operator.selectorLabels" . | nindent 6 }}
15+
{{- include "{[ operator.name }].selectorLabels" . | nindent 6 }}
1616
template:
1717
metadata:
1818
annotations:
19-
internal.stackable.tech/image: {{ include "operator.image" . }}
19+
internal.stackable.tech/image: {{ include "{[ operator.name }].image" . }}
2020
{{- with .Values.podAnnotations }}
2121
{{- toYaml . | nindent 8 }}
2222
{{- end }}
2323
labels:
2424
{{- if .Values.maintenance.customResourceDefinitions.maintain }}
2525
webhook.stackable.tech/conversion: enabled
2626
{{- end }}
27-
{{- include "operator.selectorLabels" . | nindent 8 }}
27+
{{- include "{[ operator.name }].selectorLabels" . | nindent 8 }}
2828
spec:
2929
{{- with .Values.image.pullSecrets }}
3030
imagePullSecrets:
3131
{{- toYaml . | nindent 8 }}
3232
{{- end }}
33-
serviceAccountName: {{ include "operator.serviceAccountName" . }}
33+
serviceAccountName: {{ include "{[ operator.name }].serviceAccountName" . }}
3434
securityContext:
3535
{{- toYaml .Values.podSecurityContext | nindent 8 }}
3636
containers:
37-
- name: {{ include "operator.appname" . }}
37+
- name: {{ include "{[ operator.name }].appname" . }}
3838
securityContext:
3939
{{- toYaml .Values.securityContext | nindent 12 }}
40-
image: {{ include "operator.image" . }}
40+
image: {{ include "{[ operator.name }].image" . }}
4141
imagePullPolicy: {{ .Values.image.pullPolicy }}
4242
resources:
4343
{{- toYaml .Values.resources | nindent 12 }}
@@ -65,7 +65,7 @@ spec:
6565
# The name of the Kubernetes Service that point to the operator Pod, e.g. used to
6666
# construct the conversion webhook endpoint.
6767
- name: OPERATOR_SERVICE_NAME
68-
value: {{ include "operator.fullname" . }}
68+
value: {{ include "{[ operator.name }].fullname" . }}
6969

7070
{[% if operator.config.has_product | default(true) %}]
7171
# The product image repository, like "oci.stackable.tech/sdp".
@@ -89,11 +89,11 @@ spec:
8989
value: {{ .Values.kubernetesClusterDomain | quote }}
9090
{{- end }}
9191

92-
{{- include "telemetry.envVars" . | nindent 12 }}
93-
{{- include "maintenance.envVars" . | nindent 12 }}
92+
{{- include "{[ operator.name }].telemetry.envVars" . | nindent 12 }}
93+
{{- include "{[ operator.name }].maintenance.envVars" . | nindent 12 }}
9494
{[% if operator.product_string in ['opa'] %}]
9595
- name: OPA_BUNDLE_BUILDER_CLUSTERROLE
96-
value: {{ include "operator.fullname" . }}-opa-bundle-builder-clusterrole
96+
value: {{ include "{[ operator.name }].fullname" . }}-opa-bundle-builder-clusterrole
9797
{[% endif %}]
9898
{{- with .Values.nodeSelector }}
9999
nodeSelector:

template/deploy/helm/[[operator]]/templates/service.yaml renamed to template/deploy/helm/[[operator]]/templates/service.yaml.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ metadata:
66
# Note(@sbernauer): We could also call the Service something like
77
# "product-operator-conversion-webhook". However, in the future we will have more webhooks, and
88
# it seems like an overkill to have a dedicated Service per webhook.
9-
name: {{ include "operator.fullname" . }}
9+
name: {{ include "{[ operator.name }].fullname" . }}
1010
labels:
11-
{{- include "operator.labels" . | nindent 4 }}
11+
{{- include "{[ operator.name }].labels" . | nindent 4 }}
1212
spec:
1313
selector:
1414
{{- if .Values.maintenance.customResourceDefinitions.maintain }}
1515
webhook.stackable.tech/conversion: enabled
1616
{{- end }}
17-
{{- include "operator.selectorLabels" . | nindent 4 }}
17+
{{- include "{[ operator.name }].selectorLabels" . | nindent 4 }}
1818
ports:
1919
- name: conversion-webhook
2020
protocol: TCP

template/deploy/helm/[[operator]]/templates/serviceaccount.yaml.j2

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
apiVersion: v1
44
kind: ServiceAccount
55
metadata:
6-
name: {{ include "operator.serviceAccountName" . }}
6+
name: {{ include "{[ operator.name }].serviceAccountName" . }}
77
labels:
8-
{{- include "operator.labels" . | nindent 4 }}
8+
{{- include "{[ operator.name }].labels" . | nindent 4 }}
99
{{- with .Values.serviceAccount.annotations }}
1010
annotations:
1111
{{- toYaml . | nindent 4 }}
@@ -17,14 +17,14 @@ apiVersion: rbac.authorization.k8s.io/v1
1717
# operator watch and manage its custom resources across the cluster.
1818
kind: ClusterRoleBinding
1919
metadata:
20-
name: {{ include "operator.fullname" . }}-clusterrolebinding
20+
name: {{ include "{[ operator.name }].fullname" . }}-clusterrolebinding
2121
labels:
22-
{{- include "operator.labels" . | nindent 4 }}
22+
{{- include "{[ operator.name }].labels" . | nindent 4 }}
2323
subjects:
2424
- kind: ServiceAccount
25-
name: {{ include "operator.serviceAccountName" . }}
25+
name: {{ include "{[ operator.name }].serviceAccountName" . }}
2626
namespace: {{ .Release.Namespace }}
2727
roleRef:
2828
kind: ClusterRole
29-
name: {{ include "operator.fullname" . }}-clusterrole
29+
name: {{ include "{[ operator.name }].fullname" . }}-clusterrole
3030
apiGroup: rbac.authorization.k8s.io

0 commit comments

Comments
 (0)