Skip to content

Commit dcb6d97

Browse files
committed
Add serviceAccountTokenCreationRoles helm chart array value
The array allows users to supply KEDA with the names and namespaces of service accounts that they would like the keda-operator to request tokens from. These service account tokens are then used in turn for the boundServiceAccountToken trigger source. Signed-off-by: Max Cao <[email protected]>
1 parent 285f693 commit dcb6d97

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

keda/templates/manager/clusterrole.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,51 @@ rules:
210210
- list
211211
- watch
212212
{{- end -}}
213+
{{- if .Values.serviceAccountTokenCreationRoles }}
214+
{{- range $r := .Values.serviceAccountTokenCreationRoles }}
215+
---
216+
apiVersion: rbac.authorization.k8s.io/v1
217+
kind: Role
218+
metadata:
219+
{{- with $.Values.additionalAnnotations }}
220+
annotations:
221+
{{- toYaml . | nindent 4 }}
222+
{{- end }}
223+
labels:
224+
app.kubernetes.io/name: {{ $.Values.operator.name }}
225+
{{- include "keda.labels" $ | indent 4 }}
226+
name: {{ $.Values.operator.name }}-token-creator-{{ $r.namespace }}-{{ $r.name }}
227+
namespace: {{ $r.namespace }}
228+
rules:
229+
- apiGroups:
230+
- ""
231+
resources:
232+
- serviceaccounts/token
233+
verbs:
234+
- create
235+
resourceNames:
236+
- {{ $r.name }}
237+
---
238+
apiVersion: rbac.authorization.k8s.io/v1
239+
kind: RoleBinding
240+
metadata:
241+
{{- with $.Values.additionalAnnotations }}
242+
annotations:
243+
{{- toYaml . | nindent 4 }}
244+
{{- end }}
245+
labels:
246+
app.kubernetes.io/name: {{ $.Values.operator.name }}
247+
{{- include "keda.labels" $ | indent 4 }}
248+
name: {{ $.Values.operator.name }}-token-creator-{{ $r.namespace }}-{{ $r.name }}
249+
namespace: {{ $r.namespace }}
250+
roleRef:
251+
apiGroup: rbac.authorization.k8s.io
252+
kind: Role
253+
name: {{ $.Values.operator.name }}-token-creator-{{ $r.namespace }}-{{ $r.name }}
254+
subjects:
255+
- kind: ServiceAccount
256+
name: {{ $.Values.operator.name }}
257+
namespace: {{ $.Release.Namespace }}
258+
{{- end }}
259+
{{- end }}
213260
{{- end -}}

keda/values.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -867,3 +867,10 @@ customManagedBy: ""
867867
# -- Enable service links in pods. Although enabled, mirroring k8s default, it is highly recommended to disable,
868868
# due to its legacy status [Legacy container links](https://docs.docker.com/engine/network/links/)
869869
enableServiceLinks: true
870+
871+
# -- Creates roles and rolebindings which allow the KEDA operator to request service account tokens from
872+
# namespaced service accounts in the array for use with the boundServiceAccountToken trigger source
873+
# If the namespace does not exist, this will cause the helm chart installation to fail.
874+
serviceAccountTokenCreationRoles: []
875+
# - name: myServiceAccount
876+
# namespace: myServiceAccountNamespace

0 commit comments

Comments
 (0)