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..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. @@ -1460,6 +1463,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..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 {