From 881d1c2d784fbeaf3f674083c2504993fbe62567 Mon Sep 17 00:00:00 2001 From: Valeriy Khorunzhin Date: Thu, 9 Apr 2026 18:47:42 +0300 Subject: [PATCH 1/3] t Signed-off-by: Valeriy Khorunzhin --- api/core/v1alpha2/virtual_machine.go | 3 +++ crds/virtualmachines.yaml | 5 +++++ .../pkg/controller/vm/internal/block_device_handler.go | 2 ++ 3 files changed, 10 insertions(+) diff --git a/api/core/v1alpha2/virtual_machine.go b/api/core/v1alpha2/virtual_machine.go index 62ba4393aa..550c40d385 100644 --- a/api/core/v1alpha2/virtual_machine.go +++ b/api/core/v1alpha2/virtual_machine.go @@ -49,6 +49,7 @@ const ( // +kubebuilder:printcolumn:name="Migratable",priority=1,type="string",JSONPath=".status.conditions[?(@.type=='Migratable')].status",description="Is it possible to migrate a virtual machine." // +kubebuilder:printcolumn:name="Node",type="string",JSONPath=".status.nodeName",description="The node where the virtual machine is running." // +kubebuilder:printcolumn:name="IPAddress",type="string",JSONPath=".status.ipAddress",description="The IP address of the virtual machine." +// +kubebuilder:printcolumn:name="BlockDevicesCount",priority=1,type="integer",JSONPath=".status.blockDevicesCount",description="The number of block devices attached to the virtual machine." // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time of creation resource." // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -298,6 +299,8 @@ type VirtualMachineStatus struct { Stats *VirtualMachineStats `json:"stats,omitempty"` // Migration info. MigrationState *VirtualMachineMigrationState `json:"migrationState,omitempty"` + // The number of block devices attached to the virtual machine. + BlockDevicesCount int `json:"blockDevicesCount,omitempty"` // Generating a resource that was last processed by the controller. ObservedGeneration int64 `json:"observedGeneration,omitempty"` diff --git a/crds/virtualmachines.yaml b/crds/virtualmachines.yaml index da6d232bdc..24a60fa258 100644 --- a/crds/virtualmachines.yaml +++ b/crds/virtualmachines.yaml @@ -1460,6 +1460,11 @@ spec: jsonPath: .status.ipAddress name: IPAddress type: string + - description: The number of block devices attached to the virtual machine. + jsonPath: .status.blockDevicesCount + name: BlockDevicesCount + priority: 1 + type: integer - description: Time of resource creation. jsonPath: .metadata.creationTimestamp name: Age diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go b/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go index de3166476d..7924616895 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go @@ -144,6 +144,8 @@ func (h *BlockDeviceHandler) Handle(ctx context.Context, s state.VirtualMachineS h.setConditionReady(s.VirtualMachine().Changed()) } + changed.Status.BlockDevicesCount = len(changed.Status.BlockDeviceRefs) + return reconcile.Result{}, nil } From e78bccd91a5dae10339d31cc5f6e01b0a59b8f38 Mon Sep 17 00:00:00 2001 From: Valeriy Khorunzhin Date: Thu, 9 Apr 2026 21:05:20 +0300 Subject: [PATCH 2/3] add to crd Signed-off-by: Valeriy Khorunzhin --- crds/virtualmachines.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crds/virtualmachines.yaml b/crds/virtualmachines.yaml index 24a60fa258..ae9bad6d91 100644 --- a/crds/virtualmachines.yaml +++ b/crds/virtualmachines.yaml @@ -1256,6 +1256,9 @@ spec: items: type: object x-kubernetes-preserve-unknown-fields: true + blockDevicesCount: + type: integer + description: Number of block devices attached to the virtual machine. observedGeneration: type: integer description: Resource generation last processed by the controller. From 6183ade4842c1af7af340a587f74c1fc9ce336e1 Mon Sep 17 00:00:00 2001 From: Valeriy Khorunzhin Date: Fri, 10 Apr 2026 10:43:41 +0300 Subject: [PATCH 3/3] fix Signed-off-by: Valeriy Khorunzhin --- .../pkg/controller/vm/internal/block_device_handler.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go b/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go index 7924616895..552e7daf09 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/block_device_handler.go @@ -111,6 +111,13 @@ func (h *BlockDeviceHandler) Handle(ctx context.Context, s state.VirtualMachineS if err != nil { return reconcile.Result{}, fmt.Errorf("failed to get block device status refs: %w", err) } + blockDeviceCount := 0 + for _, bd := range changed.Status.BlockDeviceRefs { + if bd.Attached { + blockDeviceCount++ + } + } + changed.Status.BlockDevicesCount = blockDeviceCount shouldStop, err = h.handleBlockDeviceConflicts(ctx, s, log) if err != nil { @@ -144,8 +151,6 @@ func (h *BlockDeviceHandler) Handle(ctx context.Context, s state.VirtualMachineS h.setConditionReady(s.VirtualMachine().Changed()) } - changed.Status.BlockDevicesCount = len(changed.Status.BlockDeviceRefs) - return reconcile.Result{}, nil }