From cd5f6b1b3bbbee32dacea17909193bfb3ccdfb6c Mon Sep 17 00:00:00 2001 From: Renato Monteiro <45536168+monteiro-renato@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:41:38 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20(helm/v1alpha1):=20Add=20?= =?UTF-8?q?missing=20prefixes=20in=20various=20k8s=20resources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../optional/helm/v1alpha/scaffolds/init.go | 14 ++++++++++++++ .../templates/chart-templates/manager/manager.go | 3 ++- .../dist/chart/templates/manager/manager.yaml | 2 +- .../chart/templates/rbac/metrics_auth_role.yaml | 2 +- .../templates/rbac/metrics_auth_role_binding.yaml | 4 ++-- .../dist/chart/templates/rbac/role.yaml | 2 +- .../dist/chart/templates/rbac/role_binding.yaml | 4 ++-- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go index 3ef00bc0a52..8a23203b259 100644 --- a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go +++ b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go @@ -293,6 +293,14 @@ func copyFileWithHelmLogic(srcFile, destFile, subDir, projectName string) error contentStr = strings.Replace(contentStr, "name: metrics-reader", fmt.Sprintf("name: %s-metrics-reader", projectName), 1) + + contentStr = strings.Replace(contentStr, + "name: metrics-auth-role", + fmt.Sprintf("name: %s-metrics-auth-role", projectName), -1) + contentStr = strings.Replace(contentStr, + "name: metrics-auth-rolebinding", + fmt.Sprintf("name: %s-metrics-auth-rolebinding", projectName), 1) + if strings.Contains(contentStr, "-controller-manager") && strings.Contains(contentStr, "kind: ServiceAccount") && !strings.Contains(contentStr, "RoleBinding") { @@ -312,6 +320,12 @@ func copyFileWithHelmLogic(srcFile, destFile, subDir, projectName string) error contentStr = strings.Replace(contentStr, "name: leader-election-rolebinding", fmt.Sprintf("name: %s-leader-election-rolebinding", projectName), 1) + contentStr = strings.Replace(contentStr, + "name: manager-role", + fmt.Sprintf("name: %s-manager-role", projectName), -1) + contentStr = strings.Replace(contentStr, + "name: manager-rolebinding", + fmt.Sprintf("name: %s-manager-rolebinding", projectName), 1) // The generated files do not include the namespace if strings.Contains(contentStr, "leader-election-rolebinding") || diff --git a/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager/manager.go b/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager/manager.go index ae82473062f..de01d434230 100644 --- a/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager/manager.go +++ b/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager/manager.go @@ -27,6 +27,7 @@ var _ machinery.Template = &ManagerDeployment{} // ManagerDeployment scaffolds the manager Deployment for the Helm chart type ManagerDeployment struct { machinery.TemplateMixin + machinery.ProjectNameMixin // DeployImages if true will scaffold the env with the images DeployImages bool @@ -57,7 +58,7 @@ func (f *ManagerDeployment) SetTemplateDefaults() error { const managerDeploymentTemplate = `apiVersion: apps/v1 kind: Deployment metadata: - name: controller-manager + name: {{ .ProjectName }}-controller-manager namespace: {{ "{{ .Release.Namespace }}" }} labels: {{ "{{- include \"chart.labels\" . | nindent 4 }}" }} diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/manager/manager.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/manager/manager.yaml index 7641e1e4f13..f37cfc16711 100644 --- a/testdata/project-v4-with-plugins/dist/chart/templates/manager/manager.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/manager/manager.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: controller-manager + name: project-v4-with-plugins-controller-manager namespace: {{ .Release.Namespace }} labels: {{- include "chart.labels" . | nindent 4 }} diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role.yaml index 196ca1041f6..29b3f12404f 100755 --- a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role.yaml @@ -4,7 +4,7 @@ kind: ClusterRole metadata: labels: {{- include "chart.labels" . | nindent 4 }} - name: metrics-auth-role + name: project-v4-with-plugins-metrics-auth-role rules: - apiGroups: - authentication.k8s.io diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role_binding.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role_binding.yaml index b5f6aa9b101..ed589893059 100755 --- a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role_binding.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/metrics_auth_role_binding.yaml @@ -4,11 +4,11 @@ kind: ClusterRoleBinding metadata: labels: {{- include "chart.labels" . | nindent 4 }} - name: metrics-auth-rolebinding + name: project-v4-with-plugins-metrics-auth-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: metrics-auth-role + name: project-v4-with-plugins-metrics-auth-role subjects: - kind: ServiceAccount name: project-v4-with-plugins-controller-manager diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role.yaml index c139ee74b3b..ec0830f2178 100755 --- a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role.yaml @@ -5,7 +5,7 @@ kind: ClusterRole metadata: labels: {{- include "chart.labels" . | nindent 4 }} - name: manager-role + name: project-v4-with-plugins-manager-role rules: - apiGroups: - "" diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role_binding.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role_binding.yaml index 67e38e87109..181c7af15d4 100755 --- a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role_binding.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/role_binding.yaml @@ -4,11 +4,11 @@ kind: ClusterRoleBinding metadata: labels: {{- include "chart.labels" . | nindent 4 }} - name: manager-rolebinding + name: project-v4-with-plugins-manager-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: manager-role + name: project-v4-with-plugins-manager-role subjects: - kind: ServiceAccount name: project-v4-with-plugins-controller-manager