Skip to content

Commit

Permalink
feat(vm): wrap VM ready reasons
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Antoshin <[email protected]>
  • Loading branch information
danilrwx committed Dec 10, 2024
1 parent fb2423c commit ed11356
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/core/v1alpha2/vmcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ const (

ReasonBlockDeviceCapacityAvailable Reason = "BlockDeviceCapacityAvailable"
ReasonBlockDeviceCapacityReached Reason = "BlockDeviceCapacityReached"

ReasonPodTerminatingReason Reason = "PodTerminating"
ReasonPodNotExistsReason Reason = "PodNotExists"
ReasonPodConditionMissingReason Reason = "PodConditionMissing"
ReasonGuestNotRunningReason Reason = "GuestNotRunning"
)
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,15 @@ func (h *LifeCycleHandler) syncRunning(vm *virtv2.VirtualMachine, kvvm *virtv1.V
}
for _, c := range kvvmi.Status.Conditions {
if c.Type == virtv1.VirtualMachineInstanceReady {
var reason conditions.Stringer
if r, ok := mapReasons[c.Reason]; ok {
reason = r
} else {
reason = conditions.DeprecatedWrappedString(c.Reason)
}

cb.Status(conditionStatus(string(c.Status))).
//nolint:staticcheck
Reason(conditions.DeprecatedWrappedString(c.Reason)).
Reason(reason).
Message(c.Message)
conditions.SetCondition(cb, &vm.Status.Conditions)
return
Expand Down
11 changes: 11 additions & 0 deletions images/virtualization-artifact/pkg/controller/vm/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ var mapPhases = map[virtv1.VirtualMachinePrintableStatus]virtv2.MachinePhase{

const kvvmEmptyPhase virtv1.VirtualMachinePrintableStatus = ""

var mapReasons = map[string]vmcondition.Reason{
// PodTerminatingReason indicates on the Ready condition on the VMI if the underlying pod is terminating
virtv1.PodTerminatingReason: vmcondition.ReasonPodTerminatingReason,
// PodNotExistsReason indicates on the Ready condition on the VMI if the underlying pod does not exist
virtv1.PodNotExistsReason: vmcondition.ReasonPodNotExistsReason,
// PodConditionMissingReason indicates on the Ready condition on the VMI if the underlying pod does not report a Ready condition
virtv1.PodConditionMissingReason: vmcondition.ReasonPodConditionMissingReason,
// GuestNotRunningReason indicates on the Ready condition on the VMI if the underlying guest VM is not running
virtv1.GuestNotRunningReason: vmcondition.ReasonGuestNotRunningReason,
}

func isPodStartedError(phase virtv1.VirtualMachinePrintableStatus) bool {
return slices.Contains([]virtv1.VirtualMachinePrintableStatus{
virtv1.VirtualMachineStatusErrImagePull,
Expand Down

0 comments on commit ed11356

Please sign in to comment.