Skip to content

Commit

Permalink
✨ feat: (helm/v1alpha1): Allow ServiceAccount annotations to be confi…
Browse files Browse the repository at this point in the history
…gurable
  • Loading branch information
monteiro-renato committed Nov 24, 2024
1 parent 4d82257 commit 6e638c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/plugins/optional/helm/v1alpha/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ func copyFileWithHelmLogic(srcFile, destFile, subDir, projectName string) error
contentStr = strings.Replace(contentStr,
"name: metrics-reader",
fmt.Sprintf("name: %s-metrics-reader", projectName), 1)
if strings.Contains(contentStr, "-controller-manager") &&
strings.Contains(contentStr, "kind: ServiceAccount") &&
!strings.Contains(contentStr, "RoleBinding") {
// The generated Service Account does not have the annotations field so we must add it.
contentStr = strings.Replace(contentStr,
"metadata:", `metadata:
{{- if and .Values.controllerManager.serviceAccount .Values.controllerManager.serviceAccount.annotations }}
annotations:
{{- range $key, $value := .Values.controllerManager.serviceAccount.annotations }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}`, 1)
}
contentStr = strings.Replace(contentStr,
"name: leader-election-role",
fmt.Sprintf("name: %s-leader-election-role", projectName), -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ kind: ServiceAccount
metadata:
labels:
{{- include "chart.labels" . | nindent 4 }}
{{- if and .Values.controllerManager.serviceAccount .Values.controllerManager.serviceAccount.annotations }}
annotations:
{{- range $key, $value := .Values.controllerManager.serviceAccount.annotations }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
name: project-v4-with-plugins-controller-manager
namespace: {{ .Release.Namespace }}
{{- end -}}

0 comments on commit 6e638c4

Please sign in to comment.