Skip to content

Commit 2b7e0db

Browse files
committed
fix(kubernetes): let kubevirt-csi hot-unplug from an orphaned VMI
The driver falls back to the VMI-level removevolume subresource when a volume is still attached to the VMI but no longer in the VM spec. The -kcsi Role grants only the VM-level subresources, and nothing else bound to the service account covers the VMI one: kubevirt.io: default grants no subresource of it, and the kubevirt.io:edit and admin roles that do are aggregated only into the built-in edit and admin roles, which the tenant namespace never binds to this account. Every such call ends in 403, the unpublish retries until it fails, and the hot-plug pod keeps the infra volume attached. The call stays needed once the driver stops falling back for a VM-owned VMI (kubevirt/csi-driver#382), because it still makes it for a VMI no VM owns. Deleting a VM with orphan propagation leaves its VMI running, since the KubeVirt VM controller then drops its finalizer without stopping the VMI, so the tenant node stays up and its volumes stay attached until the driver detaches them. The grant adds no reach the account lacks: it can already remove a volume from any VM in the namespace, and virt-api refuses the VMI call on a VM-owned VMI once the HotplugVolumes gate is off. virtualmachineinstances/addvolume stays ungranted, as the driver only attaches through the VM. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent b314514 commit 2b7e0db

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎packages/apps/kubernetes/templates/csi/infra-cluster-service-account.yaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ rules:
2222
- apiGroups: ["kubevirt.io"]
2323
resources: ["virtualmachineinstances", "virtualmachines"]
2424
verbs: ["list", "get"]
25+
# virtualmachineinstances/removevolume: the driver's fallback for a volume
26+
# missing from the VM spec. Without the HotplugVolumes gate virt-api accepts
27+
# it only on a VMI no VM owns, e.g. after an orphan-propagation delete.
2528
- apiGroups: ["subresources.kubevirt.io"]
26-
resources: ["virtualmachines/addvolume", "virtualmachines/removevolume"]
29+
resources: ["virtualmachines/addvolume", "virtualmachines/removevolume", "virtualmachineinstances/removevolume"]
2730
verbs: ["update"]
2831
- apiGroups: ["snapshot.storage.k8s.io"]
2932
resources: ["volumesnapshots"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
suite: kubevirt-csi infra-cluster Role
2+
3+
templates:
4+
- templates/csi/infra-cluster-service-account.yaml
5+
6+
values:
7+
- values/common.yaml
8+
9+
release:
10+
name: kubernetes-test
11+
namespace: tenant-test
12+
13+
tests:
14+
- it: grants only the VM hotplug subresources and VMI-level removevolume
15+
documentSelector:
16+
path: kind
17+
value: Role
18+
asserts:
19+
- equal:
20+
path: rules[?(@.apiGroups[0] == "subresources.kubevirt.io")]
21+
value:
22+
apiGroups: ["subresources.kubevirt.io"]
23+
resources: ["virtualmachines/addvolume", "virtualmachines/removevolume", "virtualmachineinstances/removevolume"]
24+
verbs: ["update"]

0 commit comments

Comments
 (0)