Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(vm): wrap KVMI ready reasons #565

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 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,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,
Expand Down
Loading