From 6e638c49f56b9d139a64e1e9c9a01f99d3a3daa5 Mon Sep 17 00:00:00 2001 From: Renato Monteiro <45536168+monteiro-renato@users.noreply.github.com> Date: Sun, 24 Nov 2024 13:23:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20(helm/v1alpha1):=20Allow=20?= =?UTF-8?q?ServiceAccount=20annotations=20to=20be=20configurable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/plugins/optional/helm/v1alpha/scaffolds/init.go | 13 +++++++++++++ .../dist/chart/templates/rbac/service_account.yaml | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go index 386db89e26f..36361ee1783 100644 --- a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go +++ b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go @@ -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) diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/service_account.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/service_account.yaml index 147bfef8cae..8f5bcce80dc 100755 --- a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/service_account.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/service_account.yaml @@ -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 -}}