From 70fd271a5446701ad9dd2472da19a34d6040e4c4 Mon Sep 17 00:00:00 2001 From: "dmitry.lopatin" Date: Sun, 27 Oct 2024 22:38:28 +0300 Subject: [PATCH] fix Signed-off-by: dmitry.lopatin --- api/core/v1alpha2/vdcondition/condition.go | 15 ++++----------- .../vi/internal/source/object_ref_vd.go | 8 +++----- .../pkg/controller/vi/vi_reconciler.go | 4 ++-- .../pkg/controller/vm/internal/block_device.go | 6 +++--- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/api/core/v1alpha2/vdcondition/condition.go b/api/core/v1alpha2/vdcondition/condition.go index b1ec61927..16eda4404 100644 --- a/api/core/v1alpha2/vdcondition/condition.go +++ b/api/core/v1alpha2/vdcondition/condition.go @@ -28,8 +28,10 @@ const ( ResizedType Type = "Resized" // SnapshottingType indicates whether the disk snapshotting operation is in progress. SnapshottingType Type = "Snapshotting" - // InUseType indicates whether the VirtualDisk is attached to a running VirtualMachine or is being used in a process of a VirtualImage creation - InUseType Type = "InUse" + // InUseByVirtualImageType indicates whether the VirtualDisk is being used in a process of a VirtualImage creation + InUseByVirtualImageType Type = "InUseByVirtualImage" + // InUseByVirtualMachineType indicates whether the VirtualDisk is attached to a running VirtualMachine + InUseByVirtualMachineType Type = "InUseByVirtualMachine" ) type ( @@ -41,8 +43,6 @@ type ( ResizedReason = string // SnapshottingReason represents the various reasons for the Snapshotting condition type. SnapshottingReason = string - // InUseReason represents the various reasons for the InUse condition type. - InUseReason = string ) const ( @@ -87,11 +87,4 @@ const ( Snapshotting SnapshottingReason = "Snapshotting" // SnapshottingNotAvailable indicates that the snapshotting operation is not available for now. SnapshottingNotAvailable SnapshottingReason = "NotAvailable" - - // InUseInRunningVirtualMachine indicates that this `VirtualDisk` attached to running `VirtualMachine` - InUseInRunningVirtualMachine InUseReason = "InUseInRunningVirtualMachine" - // InUseForCreateImage indicates running a process to create a `VirtualImage` or `ClusterVirtualImage` from this `VirtualDisk` - InUseForCreateImage InUseReason = "InUseForCreateImage" - // NotInUse indicates that this `VirtualDisk` is available. - NotInUse InUseReason = "NotInUse" ) diff --git a/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref_vd.go b/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref_vd.go index 4150a68c2..17293ab24 100644 --- a/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref_vd.go +++ b/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref_vd.go @@ -345,11 +345,9 @@ func (ds ObjectRefVirtualDisk) Validate(ctx context.Context, vi *virtv2.VirtualI return NewVirtualDiskNotReadyError(vi.Spec.DataSource.ObjectRef.Name) } - inUseCondition, _ := service.GetCondition(vdcondition.InUseType, vd.Status.Conditions) - if inUseCondition.Status == metav1.ConditionTrue { - if inUseCondition.Reason != vdcondition.InUseForCreateImage { - return NewVirtualDiskInUseError(vd.Name) - } + inUseByVMCondition, _ := service.GetCondition(vdcondition.InUseByVirtualMachineType, vd.Status.Conditions) + if inUseByVMCondition.Status == metav1.ConditionTrue { + return NewVirtualDiskInUseError(vd.Name) } return nil diff --git a/images/virtualization-artifact/pkg/controller/vi/vi_reconciler.go b/images/virtualization-artifact/pkg/controller/vi/vi_reconciler.go index 0a5e2f6ba..38d36f9d9 100644 --- a/images/virtualization-artifact/pkg/controller/vi/vi_reconciler.go +++ b/images/virtualization-artifact/pkg/controller/vi/vi_reconciler.go @@ -220,8 +220,8 @@ func (r *Reconciler) SetupController(_ context.Context, mgr manager.Manager, ctr return false } - oldInUseCondition, _ := service.GetCondition(vdcondition.InUseType, oldVD.Status.Conditions) - newInUseCondition, _ := service.GetCondition(vdcondition.InUseType, newVD.Status.Conditions) + oldInUseCondition, _ := service.GetCondition(vdcondition.InUseByVirtualMachineType, oldVD.Status.Conditions) + newInUseCondition, _ := service.GetCondition(vdcondition.InUseByVirtualMachineType, newVD.Status.Conditions) if oldVD.Status.Phase != newVD.Status.Phase || len(oldVD.Status.AttachedToVirtualMachines) != len(newVD.Status.AttachedToVirtualMachines) || oldInUseCondition.Status != newInUseCondition.Status { return true diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/block_device.go b/images/virtualization-artifact/pkg/controller/vm/internal/block_device.go index 33fb97b90..1e9364d4b 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/block_device.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/block_device.go @@ -302,11 +302,11 @@ func (h *BlockDeviceHandler) countReadyBlockDevices(vm *virtv2.VirtualMachine, s } readyCondition, _ := service.GetCondition(vdcondition.ReadyType, vd.Status.Conditions) if readyCondition.Status == metav1.ConditionTrue { - inUseCondition, _ := service.GetCondition(vdcondition.InUseType, vd.Status.Conditions) - if inUseCondition.Status != metav1.ConditionTrue { + inUseByVICondition, _ := service.GetCondition(vdcondition.InUseByVirtualImageType, vd.Status.Conditions) + if inUseByVICondition.Status != metav1.ConditionTrue { ready++ } else { - msg := fmt.Sprintf("The virtual disk %s is being used to create a virtual image or a cluster virtual image.", vd.Name) + msg := fmt.Sprintf("The virtual disk %s is being used to create a virtual image.", vd.Name) warnings = append(warnings, msg) canStartKVVM = false }