Skip to content

Commit 1c340c6

Browse files
yujunzFxKu
authored andcommitted
Simplify service account name in helm chart (zalando#612)
* Simplify service account name in helm chart (zalando#610)
1 parent 7c19cf5 commit 1c340c6

File tree

8 files changed

+17
-42
lines changed

8 files changed

+17
-42
lines changed

charts/postgres-operator/templates/_helpers.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ If release name contains chart name it will be used as a full name.
2424
{{- end -}}
2525
{{- end -}}
2626

27+
{{/*
28+
Create a service account name.
29+
*/}}
30+
{{- define "postgres-operator.serviceAccountName" -}}
31+
{{ default (include "postgres-operator.fullname" .) .Values.serviceAccount.name }}
32+
{{- end -}}
33+
2734
{{/*
2835
Create chart name and version as used by the chart label.
2936
*/}}

charts/postgres-operator/templates/clusterrole.yaml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
apiVersion: rbac.authorization.k8s.io/v1beta1
33
kind: ClusterRole
44
metadata:
5-
name: {{- if eq .Values.serviceAccount.name "" }}
6-
{{ template "postgres-operator.fullname" . }}
7-
{{- else }}
8-
{{ .Values.serviceAccount.name }}
9-
{{- end }}
5+
name: {{ include "postgres-operator.serviceAccountName" . }}
106
labels:
117
app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
128
helm.sh/chart: {{ template "postgres-operator.chart" . }}
@@ -145,11 +141,7 @@ rules:
145141
verbs:
146142
- bind
147143
resourceNames:
148-
- {{- if eq .Values.serviceAccount.name "" }}
149-
{{ template "postgres-operator.fullname" . }}
150-
{{- else }}
151-
{{ .Values.serviceAccount.name }}
152-
{{- end }}
144+
- {{ include "postgres-operator.serviceAccountName" . }}
153145
- apiGroups:
154146
- batch
155147
resources:

charts/postgres-operator/templates/clusterrolebinding.yaml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: ClusterRoleBinding
44
metadata:
5-
name: {{- if eq .Values.serviceAccount.name "" }}
6-
{{ template "postgres-operator.fullname" . }}
7-
{{- else }}
8-
{{ .Values.serviceAccount.name }}
9-
{{- end }}
5+
name: {{ include "postgres-operator.serviceAccountName" . }}
106
labels:
117
app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
128
helm.sh/chart: {{ template "postgres-operator.chart" . }}
@@ -15,19 +11,11 @@ metadata:
1511
roleRef:
1612
apiGroup: rbac.authorization.k8s.io
1713
kind: ClusterRole
18-
name: {{- if eq .Values.serviceAccount.name "" }}
19-
{{ template "postgres-operator.fullname" . }}
20-
{{- else }}
21-
{{ .Values.serviceAccount.name }}
22-
{{- end }}
14+
name: {{ include "postgres-operator.serviceAccountName" . }}
2315
subjects:
2416
- kind: ServiceAccount
2517
# note: the cluster role binding needs to be defined
2618
# for every namespace the operator service account lives in.
27-
name: {{- if eq .Values.serviceAccount.name "" }}
28-
{{ template "postgres-operator.fullname" . }}
29-
{{- else }}
30-
{{ .Values.serviceAccount.name }}
31-
{{- end }}
19+
name: {{ include "postgres-operator.serviceAccountName" . }}
3220
namespace: {{ .Release.Namespace }}
3321
{{ end }}

charts/postgres-operator/templates/configmap.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ metadata:
99
app.kubernetes.io/managed-by: {{ .Release.Service }}
1010
app.kubernetes.io/instance: {{ .Release.Name }}
1111
data:
12-
pod_service_account_name: {{- if eq .Values.serviceAccount.name "" }}
13-
{{ template "postgres-operator.fullname" . }}
14-
{{- else }}
15-
{{ .Values.serviceAccount.name }}
16-
{{- end }}
12+
pod_service_account_name: {{ include "postgres-operator.serviceAccountName" . }}
1713
{{ toYaml .Values.configGeneral | indent 2 }}
1814
{{ toYaml .Values.configUsers | indent 2 }}
1915
{{ toYaml .Values.configKubernetes | indent 2 }}

charts/postgres-operator/templates/deployment.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ spec:
3131
{{ toYaml .Values.podLabels | indent 8 }}
3232
{{- end }}
3333
spec:
34-
serviceAccountName: {{- if eq .Values.serviceAccount.name "" }}
35-
{{ template "postgres-operator.fullname" . }}
36-
{{- else }}
37-
{{ .Values.serviceAccount.name }}
38-
{{- end }}
34+
serviceAccountName: {{ include "postgres-operator.serviceAccountName" . }}
3935
containers:
4036
- name: {{ .Chart.Name }}
4137
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"

charts/postgres-operator/templates/serviceaccount.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
apiVersion: v1
33
kind: ServiceAccount
44
metadata:
5-
name: {{- if eq .Values.serviceAccount.name "" }}
6-
{{ template "postgres-operator.fullname" . }}
7-
{{- else }}
8-
{{ .Values.serviceAccount.name }}
9-
{{- end }}
5+
name: {{ include "postgres-operator.serviceAccountName" . }}
106
labels:
117
app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
128
helm.sh/chart: {{ template "postgres-operator.chart" . }}

charts/postgres-operator/values-crd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ serviceAccount:
245245
# If not set and create is true, a name is generated using the fullname template
246246
# When relying solely on the OperatorConfiguration CRD, set this value to "operator"
247247
# Otherwise, the operator tries to use the "default" service account which is forbidden
248-
name: "operator"
248+
name: operator
249249

250250
priorityClassName: ""
251251

charts/postgres-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ serviceAccount:
226226
# If not set and create is true, a name is generated using the fullname template
227227
# When relying solely on the OperatorConfiguration CRD, set this value to "operator"
228228
# Otherwise, the operator tries to use the "default" service account which is forbidden
229-
name: ""
229+
name:
230230

231231
priorityClassName: ""
232232

0 commit comments

Comments
 (0)