diff --git a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go index bede1a92d5e..bb0cea5aeed 100644 --- a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go +++ b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go @@ -292,6 +292,20 @@ 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: leader-election-role", + fmt.Sprintf("name: %s-leader-election-role", projectName), 1) + contentStr = strings.Replace(contentStr, + "name: leader-election-rolebinding", + fmt.Sprintf("name: %s-leader-election-rolebinding", projectName), 1) + + // The generated files do not include the namespace + if strings.Contains(contentStr, "leader-election-rolebinding") || + strings.Contains(contentStr, "leader-election") { + namespace := ` + namespace: {{ .Release.Namespace }}` + contentStr = strings.Replace(contentStr, "metadata:", "metadata:"+namespace, 1) + } } // Conditionally handle CRD patches and annotations for CRDs diff --git a/testdata/project-v4-multigroup/go.mod b/testdata/project-v4-multigroup/go.mod index b8fb2172720..d9211a54f34 100644 --- a/testdata/project-v4-multigroup/go.mod +++ b/testdata/project-v4-multigroup/go.mod @@ -3,7 +3,7 @@ module sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup go 1.22.0 require ( - github.com/cert-manager/cert-manager v1.16.1 + github.com/cert-manager/cert-manager v1.16.2 github.com/onsi/ginkgo/v2 v2.19.0 github.com/onsi/gomega v1.33.1 k8s.io/api v0.31.1 diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role.yaml index bae1f30d0a8..a6a6c59da92 100755 --- a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role.yaml @@ -5,7 +5,8 @@ kind: Role metadata: labels: {{- include "chart.labels" . | nindent 4 }} - name: leader-election-role + namespace: {{ .Release.Namespace }} + name: project-v4-with-plugins-leader-election-role rules: - apiGroups: - "" diff --git a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role_binding.yaml b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role_binding.yaml index 919673d8977..3b4c078280b 100755 --- a/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role_binding.yaml +++ b/testdata/project-v4-with-plugins/dist/chart/templates/rbac/leader_election_role_binding.yaml @@ -4,7 +4,8 @@ kind: RoleBinding metadata: labels: {{- include "chart.labels" . | nindent 4 }} - name: leader-election-rolebinding + namespace: {{ .Release.Namespace }} + name: project-v4-with-plugins-leader-election-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: Role diff --git a/testdata/project-v4/go.mod b/testdata/project-v4/go.mod index c8d5c363ec5..86a7d16eb8b 100644 --- a/testdata/project-v4/go.mod +++ b/testdata/project-v4/go.mod @@ -3,7 +3,7 @@ module sigs.k8s.io/kubebuilder/testdata/project-v4 go 1.22.0 require ( - github.com/cert-manager/cert-manager v1.16.1 + github.com/cert-manager/cert-manager v1.16.2 github.com/onsi/ginkgo/v2 v2.19.0 github.com/onsi/gomega v1.33.1 k8s.io/api v0.31.1