From 565da083cc5250282337c10dcf05e27a949200a2 Mon Sep 17 00:00:00 2001 From: "dmitry.lopatin" Date: Wed, 11 Dec 2024 23:41:09 +0300 Subject: [PATCH] ++ Signed-off-by: dmitry.lopatin --- api/core/v1alpha2/vdcondition/condition.go | 2 +- .../pkg/controller/vd/internal/inuse.go | 3 +-- .../pkg/controller/vm/internal/block_device.go | 4 ++-- .../controller/vm/internal/block_devices_test.go | 14 +++++++------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/api/core/v1alpha2/vdcondition/condition.go b/api/core/v1alpha2/vdcondition/condition.go index d17e6ab0d..d51db6978 100644 --- a/api/core/v1alpha2/vdcondition/condition.go +++ b/api/core/v1alpha2/vdcondition/condition.go @@ -34,7 +34,7 @@ const ( SnapshottingType Type = "Snapshotting" // StorageClassReadyType indicates whether the storage class is ready. StorageClassReadyType Type = "StorageClassReady" - // InUseType indicates whether the VirtualDisk is attached to a running VirtualMachine or is being used in a process of a VirtualImage creation. + // InUseType indicates whether the VirtualDisk is attached to a running VirtualMachine or is being used in a process of an image creation. InUseType Type = "InUse" ) diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go index 050895c3c..09bb6eb15 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go @@ -22,7 +22,6 @@ import ( "slices" corev1 "k8s.io/api/core/v1" - k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -92,7 +91,7 @@ func (h InUseHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (recon Namespace: vm.GetNamespace(), LabelSelector: labels.SelectorFromSet(map[string]string{virtv1.VirtualMachineNameLabel: vm.GetName()}), }) - if err != nil && !k8serrors.IsNotFound(err) { + if err != nil { return reconcile.Result{}, fmt.Errorf("unable to list virt-launcher Pod for VM %q: %w", vm.GetName(), err) } 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 700c618fa..087f77929 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/block_device.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/block_device.go @@ -169,7 +169,7 @@ func (h *BlockDeviceHandler) Handle(ctx context.Context, s state.VirtualMachineS return reconcile.Result{}, err } - if !h.checkAllowVirtualDisks(vds) { + if !h.areVirtualDisksAllowedToUse(vds) { mgr.Update(cb.Status(metav1.ConditionFalse). Reason(vmcondition.ReasonBlockDevicesNotReady). Message("virtual disks are not allowed for use in the virtual machine, it may be used to create an images").Condition()) @@ -184,7 +184,7 @@ func (h *BlockDeviceHandler) Handle(ctx context.Context, s state.VirtualMachineS return reconcile.Result{}, nil } -func (h *BlockDeviceHandler) checkAllowVirtualDisks(vds map[string]*virtv2.VirtualDisk) bool { +func (h *BlockDeviceHandler) areVirtualDisksAllowedToUse(vds map[string]*virtv2.VirtualDisk) bool { for _, vd := range vds { inUseCondition, _ := conditions.GetCondition(vdcondition.InUseType, vd.Status.Conditions) if inUseCondition.Status != metav1.ConditionTrue || inUseCondition.Reason != vdcondition.AllowedForVirtualMachineUsage.String() { diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go b/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go index f8144d245..328551a8e 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go @@ -135,7 +135,7 @@ var _ = Describe("BlockDeviceHandler", func() { }) Context("BlockDevices are not ready, because VirtualDisk is not allowed", func() { - It("return false", func() { + It("returns false", func() { anyVd := &virtv2.VirtualDisk{ ObjectMeta: metav1.ObjectMeta{Name: "anyVd"}, Status: virtv2.VirtualDiskStatus{ @@ -162,13 +162,13 @@ var _ = Describe("BlockDeviceHandler", func() { anyVd.Name: anyVd, } - allowed := h.checkAllowVirtualDisks(vds) + allowed := h.areVirtualDisksAllowedToUse(vds) Expect(allowed).To(BeFalse()) }) }) - Context("BlockDevices are not ready, because VirtualDisk using for create image", func() { - It("return false", func() { + Context("BlockDevices are not ready, because VirtualDisk is used to create image", func() { + It("returns false", func() { anyVd := &virtv2.VirtualDisk{ ObjectMeta: metav1.ObjectMeta{Name: "anyVd"}, Status: virtv2.VirtualDiskStatus{ @@ -195,19 +195,19 @@ var _ = Describe("BlockDeviceHandler", func() { anyVd.Name: anyVd, } - allowed := h.checkAllowVirtualDisks(vds) + allowed := h.areVirtualDisksAllowedToUse(vds) Expect(allowed).To(BeFalse()) }) }) Context("BlockDevices are ready, because VirtualDisk is allowed", func() { - It("return false", func() { + It("returns true", func() { vds := map[string]*virtv2.VirtualDisk{ vdFoo.Name: vdFoo, vdBar.Name: vdBar, } - allowed := h.checkAllowVirtualDisks(vds) + allowed := h.areVirtualDisksAllowedToUse(vds) Expect(allowed).To(BeTrue()) }) })