From ed11356e2b60c8907151e2e1707597556e5daca5 Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Tue, 10 Dec 2024 15:54:33 +0200 Subject: [PATCH] feat(vm): wrap VM ready reasons Signed-off-by: Daniil Antoshin --- api/core/v1alpha2/vmcondition/condition.go | 5 +++++ .../pkg/controller/vm/internal/lifecycle.go | 10 ++++++++-- .../pkg/controller/vm/internal/util.go | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) 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/vm/internal/lifecycle.go b/images/virtualization-artifact/pkg/controller/vm/internal/lifecycle.go index ad7b2a95c..5a8978f69 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/lifecycle.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/lifecycle.go @@ -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 diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/util.go b/images/virtualization-artifact/pkg/controller/vm/internal/util.go index b4edf4afa..17d7d9a67 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/util.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/util.go @@ -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,