Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
[logstash] fix ServiceAccount inconsistencies (elastic#1581)
Browse files Browse the repository at this point in the history
This commit refactor the way we define the ServiceAccount name to fix an
issue where a ServiceAccount is created with a custom name but the
Statefulset is trying to use a different ServiceAccount.

Relates to elastic#1455 and 1580
  • Loading branch information
jmlrt committed Mar 1, 2022
1 parent f8b8be6 commit fa7981b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
7 changes: 7 additions & 0 deletions logstash/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Use the fullname if the serviceAccount value is not set
*/}}
{{- define "logstash.serviceAccount" -}}
{{- .Values.rbac.serviceAccountName | default (include "logstash.fullname" .) -}}
{{- end -}}
6 changes: 1 addition & 5 deletions logstash/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ metadata:
release: {{ .Release.Name | quote }}
subjects:
- kind: ServiceAccount
{{- if eq .Values.rbac.serviceAccountName "" }}
name: {{ $fullName | quote }}
{{- else }}
name: {{ .Values.rbac.serviceAccountName | quote }}
{{- end }}
name: "{{ template "logstash.serviceAccount" . }}"
namespace: {{ .Release.Namespace | quote }}
roleRef:
kind: Role
Expand Down
6 changes: 1 addition & 5 deletions logstash/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
{{- if eq .Values.rbac.serviceAccountName "" }}
name: {{ $fullName | quote }}
{{- else }}
name: {{ .Values.rbac.serviceAccountName | quote }}
{{- end }}
name: "{{ template "logstash.serviceAccount" . }}"
annotations:
{{- with .Values.rbac.serviceAccountAnnotations }}
{{- toYaml . | nindent 4 }}
Expand Down
6 changes: 2 additions & 4 deletions logstash/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ spec:
{{- end }}
securityContext:
{{ toYaml .Values.podSecurityContext | indent 8 }}
{{- if .Values.rbac.create }}
serviceAccountName: "{{ template "logstash.fullname" . }}"
{{- else if not (eq .Values.rbac.serviceAccountName "") }}
serviceAccountName: {{ .Values.rbac.serviceAccountName | quote }}
{{- if or .Values.rbac.create .Values.rbac.serviceAccountName }}
serviceAccountName: "{{ template "logstash.serviceAccount" . }}"
{{- end }}
{{- with .Values.tolerations }}
tolerations:
Expand Down

0 comments on commit fa7981b

Please sign in to comment.