diff --git a/api/core/v1alpha2/vmcondition/condition.go b/api/core/v1alpha2/vmcondition/condition.go index e99b6416a..2a6807b7b 100644 --- a/api/core/v1alpha2/vmcondition/condition.go +++ b/api/core/v1alpha2/vmcondition/condition.go @@ -103,4 +103,9 @@ const ( ReasonBlockDeviceCapacityAvailable Reason = "BlockDeviceCapacityAvailable" ReasonBlockDeviceCapacityReached Reason = "BlockDeviceCapacityReached" + + ReasonPodTerminatingReason Reason = "PodTerminating" + ReasonPodNotExistsReason Reason = "PodNotExists" + ReasonPodConditionMissingReason Reason = "PodConditionMissing" + ReasonGuestNotRunningReason Reason = "GuestNotRunning" ) diff --git a/images/virtualization-artifact/pkg/controller/conditions/stringer.go b/images/virtualization-artifact/pkg/controller/conditions/stringer.go index c2e71525a..0c6b02b51 100644 --- a/images/virtualization-artifact/pkg/controller/conditions/stringer.go +++ b/images/virtualization-artifact/pkg/controller/conditions/stringer.go @@ -29,14 +29,3 @@ func (cr CommonReason) String() string { const ( ReasonUnknown CommonReason = "Unknown" ) - -// Deprecated: avoid using this wrapper. -// TODO: get rid of this wrapper. -type DeprecatedWrappedString string - -func (s DeprecatedWrappedString) String() string { - if s == "" { - return "Unknown" - } - return string(s) -} diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/lifecycle.go b/images/virtualization-artifact/pkg/controller/vm/internal/lifecycle.go index ad7b2a95c..bb16aab38 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/lifecycle.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/lifecycle.go @@ -266,8 +266,7 @@ func (h *LifeCycleHandler) syncRunning(vm *virtv2.VirtualMachine, kvvm *virtv1.V for _, c := range kvvmi.Status.Conditions { if c.Type == virtv1.VirtualMachineInstanceReady { cb.Status(conditionStatus(string(c.Status))). - //nolint:staticcheck - Reason(conditions.DeprecatedWrappedString(c.Reason)). + Reason(getKVMIReadyReason(c.Reason)). Message(c.Message) conditions.SetCondition(cb, &vm.Status.Conditions) return diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/util.go b/images/virtualization-artifact/pkg/controller/vm/internal/util.go index b4edf4afa..0b62a0ba4 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/util.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/util.go @@ -133,6 +133,29 @@ var mapPhases = map[virtv1.VirtualMachinePrintableStatus]virtv2.MachinePhase{ const kvvmEmptyPhase virtv1.VirtualMachinePrintableStatus = "" +func getKVMIReadyReason(kvmiReason string) conditions.Stringer { + if r, ok := mapReasons[kvmiReason]; ok { + return r + } + + if kvmiReason == "" { + return conditions.ReasonUnknown + } + + return conditions.CommonReason(kvmiReason) +} + +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,