Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(helm/v1-alpha) Nameprefix is missing in editor/viewer ClusterRoles after scaffolding #4566

Open
mkarlheim opened this issue Feb 14, 2025 · 1 comment · May be fixed by #4571
Open

(helm/v1-alpha) Nameprefix is missing in editor/viewer ClusterRoles after scaffolding #4566

mkarlheim opened this issue Feb 14, 2025 · 1 comment · May be fixed by #4571
Labels
kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Milestone

Comments

@mkarlheim
Copy link

What do you want to happen?

Hello,

I'm currently in the process moving the distribution of some Kubernetes operators from Kustomize to Helm. I used the plugin helm/v1-alpha for that and it worked really well so far.

The only thing I'm missing is the namePrefix for the ClusterRoles in the rbac subfolder.

In Kustomize I was able to define a namePrefix in "config/default/kustomization.yaml":

# Adds namespace to all resources.
namespace: my-operator-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: name-prefix-

# Labels to add to all resources and selectors.

This lead to generated ClusterRoles with a namePrefix. This was really handy because this helps to identify the ClusterRoles of the corresponding Kubernetes operator quickly.

There is already a special treatment for some of the roles here:

// Apply RBAC-specific replacements
	if subDir == "rbac" {
		contentStr = strings.Replace(contentStr,
			"name: controller-manager",
			"name: {{ .Values.controllerManager.serviceAccountName }}", -1)
		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, ".Values.controllerManager.serviceAccountName") &&
			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)
		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") ||
			strings.Contains(contentStr, "leader-election-role") {
			namespace := `
  namespace: {{ .Release.Namespace }}`
			contentStr = strings.Replace(contentStr, "metadata:", "metadata:"+namespace, 1)
		}
	}

So maybe there is a need for a more generic approach? What do you think?

KubeBuilder (CLI) Version

4.5.0

Extra Labels

No response

@mkarlheim mkarlheim added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 14, 2025
@camilamacedo86 camilamacedo86 added this to the helm milestone Feb 16, 2025
@camilamacedo86 camilamacedo86 added priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Feb 16, 2025
@camilamacedo86
Copy link
Member

Thank you for raising it.
If you would like to contributing with this one by pushing a PR to address this need please feel free
We need to read the kustomize and ensure that we will use it.

That make sense !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
2 participants