fix(kubernetes): include the namespace in the kubevirt-csi ClusterRole name

The ClusterRole that lets the kubevirt-csi controller get
PersistentVolumes, and its ClusterRoleBinding, were named after the
release only. They are cluster-scoped, and a release is named after the
cluster, so two tenants with a cluster of the same name render the same
pair. Installing the second one does not fail: the existing objects are
patched and adopted. Deleting either cluster then deletes the pair, and
the other cluster's CSI controller fails every ControllerExpandVolume
with "persistentvolumes ... is forbidden" until its own release is
upgraded again, so a PVC resize stays in Resizing.

Name both objects after the namespace and the release, the way the
kccm ClusterRole already is. On upgrade Helm creates the new pair before
it deletes the old one, so the driver keeps its access.

Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
Assisted-by: LLM
(cherry picked from commit aaedcef7d9)
Signed-off-by: cozystack-ci[bot] <274107086+cozystack-ci[bot]@users.noreply.github.com>
This commit is contained in:
Yan Bondarenko authored and cozystack-ci[bot] committed 2026-11-26 15:42:14 +00:00
1 parent fad3e6e211
commit d803d8d516
2 files changed
+74 -3

No files matched your search

@@ -51,10 +51,15 @@ subjects:
- kind: ServiceAccount
name: {{ .Release.Name }}-kcsi
---
# Cluster-scoped, so the name carries the namespace, as kccm's does. The
# release name alone repeats across tenants: two clusters named "test" in two
# tenants would share one ClusterRole and binding, and uninstalling either
# cluster deletes them from under the other, whose CSI driver can then no
# longer get its PersistentVolumes and volume expansion fails.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Release.Name }}-kcsi
name: {{ .Release.Namespace }}-{{ .Release.Name }}-kcsi
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
@@ -63,10 +68,10 @@ rules:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Release.Name }}-kcsi-binding
name: {{ .Release.Namespace }}-{{ .Release.Name }}-kcsi-binding
roleRef:
kind: ClusterRole
name: {{ .Release.Name }}-kcsi
name: {{ .Release.Namespace }}-{{ .Release.Name }}-kcsi
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
@@ -22,3 +22,69 @@ tests:
apiGroups: ["subresources.kubevirt.io"]
resources: ["virtualmachines/addvolume", "virtualmachines/removevolume", "virtualmachineinstances/removevolume"]
verbs: ["update"]
- it: names the PersistentVolume ClusterRole after the namespace and the release
documentSelector:
path: kind
value: ClusterRole
asserts:
- equal:
path: metadata.name
value: tenant-test-kubernetes-test-kcsi
- equal:
path: rules
value:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get"]
- it: binds that ClusterRole to the release's own ServiceAccount
documentSelector:
path: kind
value: ClusterRoleBinding
asserts:
- equal:
path: metadata.name
value: tenant-test-kubernetes-test-kcsi-binding
- equal:
path: roleRef.name
value: tenant-test-kubernetes-test-kcsi
- equal:
path: subjects
value:
- kind: ServiceAccount
name: kubernetes-test-kcsi
namespace: tenant-test
- it: gives a same-named cluster in another tenant its own ClusterRole and binding
release:
name: kubernetes-test
namespace: tenant-other
asserts:
- equal:
path: metadata.name
value: tenant-other-kubernetes-test-kcsi
documentSelector:
path: kind
value: ClusterRole
- equal:
path: metadata.name
value: tenant-other-kubernetes-test-kcsi-binding
documentSelector:
path: kind
value: ClusterRoleBinding
- equal:
path: roleRef.name
value: tenant-other-kubernetes-test-kcsi
documentSelector:
path: kind
value: ClusterRoleBinding
- equal:
path: subjects
value:
- kind: ServiceAccount
name: kubernetes-test-kcsi
namespace: tenant-other
documentSelector:
path: kind
value: ClusterRoleBinding