Skip to content

Commit 2cbfbfc

Browse files
authored
feat(helm): allow to use an external serviceAccount (#12441)
1 parent 017fcce commit 2cbfbfc

File tree

8 files changed

+41
-9
lines changed

8 files changed

+41
-9
lines changed

helm/defectdojo/templates/_helpers.tpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ Create chart name and version as used by the chart label.
3131
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
3232
{{- end -}}
3333

34+
{{/*
35+
Create the name of the service account to use
36+
*/}}
37+
{{- define "defectdojo.serviceAccountName" -}}
38+
{{- if .Values.serviceAccount.create -}}
39+
{{ default (include "defectdojo.fullname" .) .Values.serviceAccount.name }}
40+
{{- else -}}
41+
{{ default "defectdojo" .Values.serviceAccount.name }}
42+
{{- end -}}
43+
{{- end -}}
3444

3545
{{/*
3646
Determine the hostname to use for PostgreSQL/Redis.

helm/defectdojo/templates/celery-beat-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ spec:
5353
checksum/esecret: {{ include (print $.Template.BasePath "/extra-secret.yaml") . | sha256sum }}
5454
{{- end }}
5555
spec:
56-
serviceAccountName: {{ $fullName }}
56+
serviceAccountName: {{ include "defectdojo.serviceAccountName" . }}
5757
{{- if .Values.imagePullSecrets }}
5858
imagePullSecrets:
5959
- name: {{ .Values.imagePullSecrets }}
@@ -131,7 +131,7 @@ spec:
131131
{{- if .Values.django.uwsgi.certificates.enabled }}
132132
- name: cert-mount
133133
mountPath: {{ .Values.django.uwsgi.certificates.certMountPath }}
134-
{{- end }}
134+
{{- end }}
135135
{{- range .Values.celery.extraVolumes }}
136136
- name: userconfig-{{ .name }}
137137
readOnly: true

helm/defectdojo/templates/celery-worker-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ spec:
5353
checksum/esecret: {{ include (print $.Template.BasePath "/extra-secret.yaml") . | sha256sum }}
5454
{{- end }}
5555
spec:
56-
serviceAccountName: {{ $fullName }}
56+
serviceAccountName: {{ include "defectdojo.serviceAccountName" . }}
5757
{{- if .Values.imagePullSecrets }}
5858
imagePullSecrets:
5959
- name: {{ .Values.imagePullSecrets }}
@@ -126,7 +126,7 @@ spec:
126126
{{- if .Values.django.uwsgi.certificates.enabled }}
127127
- name: cert-mount
128128
mountPath: {{ .Values.django.uwsgi.certificates.certMountPath }}
129-
{{- end }}
129+
{{- end }}
130130
{{- range .Values.celery.extraVolumes }}
131131
- name: userconfig-{{ .name }}
132132
readOnly: true

helm/defectdojo/templates/django-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spec:
6060
checksum/esecret: {{ include (print $.Template.BasePath "/extra-secret.yaml") . | sha256sum }}
6161
{{- end }}
6262
spec:
63-
serviceAccountName: {{ $fullName }}
63+
serviceAccountName: {{ include "defectdojo.serviceAccountName" . }}
6464
{{- if .Values.imagePullSecrets }}
6565
imagePullSecrets:
6666
- name: {{ .Values.imagePullSecrets }}

helm/defectdojo/templates/initializer-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ spec:
3838
{{- toYaml . | nindent 8 }}
3939
{{- end }}
4040
spec:
41-
serviceAccountName: {{ $fullName }}
41+
serviceAccountName: {{ include "defectdojo.serviceAccountName" . }}
4242
{{- if .Values.imagePullSecrets }}
4343
imagePullSecrets:
4444
- name: {{ .Values.imagePullSecrets }}

helm/defectdojo/templates/sa.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{{- $fullName := include "defectdojo.fullname" . -}}
1+
{{- if .Values.serviceAccount.create -}}
22
kind: ServiceAccount
33
apiVersion: v1
44
metadata:
5-
name: {{ $fullName }}
5+
name: {{ include "defectdojo.serviceAccountName" . }}
66
labels:
77
app.kubernetes.io/name: {{ include "defectdojo.name" . }}
88
app.kubernetes.io/instance: {{ .Release.Name }}
@@ -11,13 +11,20 @@ metadata:
1111
{{- with .Values.extraLabels }}
1212
{{- toYaml . | nindent 4 }}
1313
{{- end }}
14+
{{- with .Values.serviceAccount.labels }}
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
1417
annotations:
1518
helm.sh/resource-policy: keep
1619
helm.sh/hook: "pre-install"
1720
helm.sh/hook-delete-policy: "before-hook-creation"
1821
{{- with .Values.annotations }}
1922
{{ toYaml . | nindent 4 }}
2023
{{- end }}
24+
{{- with .Values.serviceAccount.annotations }}
25+
{{ toYaml . | nindent 4 }}
26+
{{- end }}
2127
{{- if ne .Values.gke.workloadIdentityEmail "" }}
2228
iam.gke.io/gcp-service-account: {{ .Values.gke.workloadIdentityEmail }}
2329
{{- end }}
30+
{{- end }}

helm/defectdojo/templates/tests/unit-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ metadata:
1111
annotations:
1212
helm.sh/hook: test-success
1313
spec:
14-
serviceAccountName: {{ $fullName }}
14+
serviceAccountName: {{ include "defectdojo.serviceAccountName" . }}
1515
{{- if .Values.imagePullSecrets }}
1616
imagePullSecrets:
1717
- name: {{ .Values.imagePullSecrets }}

helm/defectdojo/values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ securityContext:
8484
# nginx dockerfile sets USER=1001
8585
runAsUser: 1001
8686

87+
serviceAccount:
88+
# Specifies whether a service account should be created.
89+
create: true
90+
91+
# The name of the service account to use.
92+
# If not set and create is true, a name is generated using the fullname template
93+
# name: ""
94+
95+
# Optional additional annotations to add to the DefectDojo's Service Account.
96+
annotations: {}
97+
98+
# Optional additional labels to add to the DefectDojo's Service Account.
99+
labels: {}
100+
87101
dbMigrationChecker:
88102
enabled: true
89103
resources:
@@ -461,6 +475,7 @@ gke:
461475
# When using this option, be sure to set django.ingress.activateTLS to false
462476
useManagedCertificate: false
463477
# Workload Identity allows the K8s service account to assume the IAM access of a GCP service account to interact with other GCP services
478+
# Only works with serviceAccount.create = true
464479
workloadIdentityEmail: ""
465480

466481
# For more advance options check the bitnami chart documentation: https://github.com/bitnami/charts/tree/master/bitnami/redis

0 commit comments

Comments
 (0)