Skip to content

feat: add service account support #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,16 @@ Prints true if an upgrade job should run, false if not.
{{- end }}
{{- end }}
{{- end }}

{{/*
Returns the proper service account name depending if an explicit service account name is set
in the values file. If the name is not set it will default to either stream.fullname if serviceAccount.create
is true or default otherwise.
*/}}
{{- define "stream.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{- default (include "common.names.fullname" .) (print .Values.serviceAccount.name) -}}
{{- else -}}
{{- default "default" (print .Values.serviceAccount.name) -}}
Comment on lines +86 to +88
Copy link
Preview

Copilot AI May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using print() to coerce .Values.serviceAccount.name may be redundant if it is already a string; consider removing print() for clarity.

Suggested change
{{- default (include "common.names.fullname" .) (print .Values.serviceAccount.name) -}}
{{- else -}}
{{- default "default" (print .Values.serviceAccount.name) -}}
{{- default (include "common.names.fullname" .) .Values.serviceAccount.name -}}
{{- else -}}
{{- default "default" .Values.serviceAccount.name -}}

Copilot uses AI. Check for mistakes.

{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions templates/backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ spec:
{{- end }}
{{- end }}
spec:
serviceAccountName: {{ template "stream.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
containers:
- name: backup
image: {{ include "common.images.image" (dict "imageRoot" .Values.backup.image) }}
Expand Down
2 changes: 2 additions & 0 deletions templates/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ spec:
{{- include "common.tplvalues.render" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ template "stream.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
{{- if .Values.hostAliases }}
hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.hostAliases "context" $) | nindent 8 }}
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions templates/rbac.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if .Values.rbac.create }}
{{ if and .Values.serviceAccount.create .Values.rbac.create }}
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand All @@ -14,7 +14,7 @@ metadata:
name: {{ template "common.names.fullname" . }}-lease-updater
subjects:
- kind: ServiceAccount
name: default
name: {{ template "stream.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
Expand All @@ -36,7 +36,7 @@ metadata:
name: {{ template "common.names.fullname" . }}-pod-reader
subjects:
- kind: ServiceAccount
name: default
name: {{ template "stream.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
Expand Down
15 changes: 15 additions & 0 deletions templates/serviceaccount.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "stream.serviceAccountName" . }}
labels: {{- include "stream.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if or .Values.serviceAccount.annotations .Values.commonAnnotations }}
{{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.serviceAccount.annotations .Values.commonAnnotations ) "context" . ) }}
annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ spec:
template:
spec:
{{- include "common.images.renderPullSecrets" (dict "images" (list .Values.upgrade.image) "context" $) | nindent 6 }}
serviceAccountName: {{ template "stream.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
containers:
- name: stream-upgrade
image: {{ include "common.images.image" (dict "imageRoot" .Values.upgrade.image "global" .Values.global) }}
Expand Down
19 changes: 18 additions & 1 deletion values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,24 @@ tls:
rbac:
create: true

## Stream pods ServiceAccount
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
##
serviceAccount:
## @param serviceAccount.create Enable the creation of a ServiceAccount for Horizon pods
##
create: true
## @param serviceAccount.name Name of the created ServiceAccount
## If not set and create is true, a name is generated using the horizon.fullname template
##
name: ""
## @param serviceAccount.annotations Annotations for Horizon Service Account
##
annotations: {}
## @param serviceAccount.automountServiceAccountToken Automount service account token for the server service account
##
automountServiceAccountToken: true

## @param leases.enabled Whether leases should be used when launching multiple replicas of Stream pods. This requires the leases.akka.io CRD to be installed.
leases:
enabled: true
Expand Down Expand Up @@ -665,7 +683,6 @@ backup:
## @param envFrom [array] Extra env vars passed to the backup pods
envFrom: []


## @param extraObjects [array] Create a dynamic manifests via values:
extraObjects:
[]
Expand Down