Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry.lopatin <[email protected]>
  • Loading branch information
LopatinDmitr committed Oct 27, 2024
1 parent 90fc452 commit 0f11fd4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
15 changes: 4 additions & 11 deletions api/core/v1alpha2/vdcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 (
Expand Down Expand Up @@ -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"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0f11fd4

Please sign in to comment.