Skip to content

Commit

Permalink
Simplify service account name in helm chart (zalando#612)
Browse files Browse the repository at this point in the history
* Simplify service account name in helm chart (zalando#610)
  • Loading branch information
yujunz authored and FxKu committed Jul 10, 2019
1 parent 7c19cf5 commit 1c340c6
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 42 deletions.
7 changes: 7 additions & 0 deletions charts/postgres-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ If release name contains chart name it will be used as a full name.
{{- end -}}
{{- end -}}

{{/*
Create a service account name.
*/}}
{{- define "postgres-operator.serviceAccountName" -}}
{{ default (include "postgres-operator.fullname" .) .Values.serviceAccount.name }}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
Expand Down
12 changes: 2 additions & 10 deletions charts/postgres-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
name: {{ include "postgres-operator.serviceAccountName" . }}
labels:
app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
helm.sh/chart: {{ template "postgres-operator.chart" . }}
Expand Down Expand Up @@ -145,11 +141,7 @@ rules:
verbs:
- bind
resourceNames:
- {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
- {{ include "postgres-operator.serviceAccountName" . }}
- apiGroups:
- batch
resources:
Expand Down
18 changes: 3 additions & 15 deletions charts/postgres-operator/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
name: {{ include "postgres-operator.serviceAccountName" . }}
labels:
app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
helm.sh/chart: {{ template "postgres-operator.chart" . }}
Expand All @@ -15,19 +11,11 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
name: {{ include "postgres-operator.serviceAccountName" . }}
subjects:
- kind: ServiceAccount
# note: the cluster role binding needs to be defined
# for every namespace the operator service account lives in.
name: {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
name: {{ include "postgres-operator.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{ end }}
6 changes: 1 addition & 5 deletions charts/postgres-operator/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ metadata:
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
data:
pod_service_account_name: {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
pod_service_account_name: {{ include "postgres-operator.serviceAccountName" . }}
{{ toYaml .Values.configGeneral | indent 2 }}
{{ toYaml .Values.configUsers | indent 2 }}
{{ toYaml .Values.configKubernetes | indent 2 }}
Expand Down
6 changes: 1 addition & 5 deletions charts/postgres-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ spec:
{{ toYaml .Values.podLabels | indent 8 }}
{{- end }}
spec:
serviceAccountName: {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
serviceAccountName: {{ include "postgres-operator.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Expand Down
6 changes: 1 addition & 5 deletions charts/postgres-operator/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{- if eq .Values.serviceAccount.name "" }}
{{ template "postgres-operator.fullname" . }}
{{- else }}
{{ .Values.serviceAccount.name }}
{{- end }}
name: {{ include "postgres-operator.serviceAccountName" . }}
labels:
app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
helm.sh/chart: {{ template "postgres-operator.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion charts/postgres-operator/values-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ serviceAccount:
# If not set and create is true, a name is generated using the fullname template
# When relying solely on the OperatorConfiguration CRD, set this value to "operator"
# Otherwise, the operator tries to use the "default" service account which is forbidden
name: "operator"
name: operator

priorityClassName: ""

Expand Down
2 changes: 1 addition & 1 deletion charts/postgres-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ serviceAccount:
# If not set and create is true, a name is generated using the fullname template
# When relying solely on the OperatorConfiguration CRD, set this value to "operator"
# Otherwise, the operator tries to use the "default" service account which is forbidden
name: ""
name:

priorityClassName: ""

Expand Down

0 comments on commit 1c340c6

Please sign in to comment.