Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry.lopatin <[email protected]>
  • Loading branch information
LopatinDmitr committed Dec 11, 2024
1 parent c7c091c commit 565da08
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/core/v1alpha2/vdcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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())
})
})
Expand Down

0 comments on commit 565da08

Please sign in to comment.