Skip to content

Commit

Permalink
fix(vm): unsupported guest agent reason wrap (#541)
Browse files Browse the repository at this point in the history
fix(vm): unsupported guest agent reason wrap

Signed-off-by: Daniil Antoshin <[email protected]>
  • Loading branch information
danilrwx authored Nov 27, 2024
1 parent 59776bf commit 79b9828
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
4 changes: 4 additions & 0 deletions api/core/v1alpha2/vmcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ func (r Reason) String() string {
}

const (
ReasonAgentReady Reason = "AgentReady"
ReasonAgentNotReady Reason = "AgentNotReady"

ReasonAgentSupported Reason = "AgentVersionSupported"
ReasonAgentNotSupported Reason = "AgentVersionNotSupported"

ReasonClassReady Reason = "VirtualMachineClassReady"
ReasonClassNotReady Reason = "VirtualMachineClassNotReady"

Expand Down
26 changes: 11 additions & 15 deletions images/virtualization-artifact/pkg/controller/vm/internal/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ func (h *AgentHandler) syncAgentReady(vm *virtv2.VirtualMachine, kvvmi *virtv1.V
}

for _, c := range kvvmi.Status.Conditions {
// TODO: wrap kvvmi reasons
if c.Type == virtv1.VirtualMachineInstanceAgentConnected {
status := conditionStatus(string(c.Status))
//nolint:staticcheck
cb.Status(status).Reason(conditions.DeprecatedWrappedString(c.Reason))
if status != metav1.ConditionTrue {
cb.Message(c.Message)

switch status {
case metav1.ConditionTrue:
cb.Status(status).Reason(vmcondition.ReasonAgentReady).Message(c.Message)
case metav1.ConditionFalse:
cb.Status(status).Reason(vmcondition.ReasonAgentNotReady).Message(c.Message)
}

return
}
}
Expand All @@ -124,18 +126,12 @@ func (h *AgentHandler) syncAgentVersionNotSupport(vm *virtv2.VirtualMachine, kvv
}

for _, c := range kvvmi.Status.Conditions {
if c.Type == virtv1.VirtualMachineInstanceUnsupportedAgent {
status := conditionStatus(string(c.Status))
//nolint:staticcheck
cb.Status(status).Reason(conditions.DeprecatedWrappedString(c.Reason))
if status != metav1.ConditionTrue {
cb.Message(c.Message)
}
status := conditionStatus(string(c.Status))
if c.Type == virtv1.VirtualMachineInstanceUnsupportedAgent && status == metav1.ConditionTrue {
cb.Status(status).Reason(vmcondition.ReasonAgentNotSupported).Message(c.Reason)
return
}
}

cb.Status(metav1.ConditionFalse).
Reason(vmcondition.ReasonAgentNotReady).
Message("Failed to connect to VM Agent.")
cb.Status(metav1.ConditionFalse).Reason(vmcondition.ReasonAgentSupported)
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ func (h LifeCycleHandler) ensureVirtualDiskSnapshots(ctx context.Context, vmSnap
}
}

//nolint:staticcheck
vdSnapshotReady, _ := conditions.GetCondition(conditions.DeprecatedWrappedString(vdscondition.VirtualDiskSnapshotReadyType), vdSnapshot.Status.Conditions)
vdSnapshotReady, _ := conditions.GetCondition(vdscondition.VirtualDiskSnapshotReadyType, vdSnapshot.Status.Conditions)
if vdSnapshotReady.Reason == vdscondition.VirtualDiskSnapshotFailed.String() || vdSnapshot.Status.Phase == virtv2.VirtualDiskSnapshotPhaseFailed {
return nil, fmt.Errorf("the virtual disk snapshot %q is failed: %w. %s", vdSnapshot.Name, ErrCannotTakeSnapshot, vdSnapshotReady.Message)
}
Expand Down Expand Up @@ -449,14 +448,12 @@ func (h LifeCycleHandler) ensureBlockDeviceConsistency(ctx context.Context, vm *
return fmt.Errorf("%w: waiting for the virtual disk %q to be %s", ErrVirtualDiskNotReady, vd.Name, virtv2.DiskReady)
}

//nolint:staticcheck
ready, _ := conditions.GetCondition(conditions.DeprecatedWrappedString(vdcondition.ReadyType), vd.Status.Conditions)
ready, _ := conditions.GetCondition(vdcondition.ReadyType, vd.Status.Conditions)
if ready.Status != metav1.ConditionTrue {
return fmt.Errorf("%w: waiting for the Ready condition of the virtual disk %q to be True", ErrVirtualDiskResizing, vd.Name)
}

//nolint:staticcheck
resizingReady, _ := conditions.GetCondition(conditions.DeprecatedWrappedString(vdcondition.ResizedType), vd.Status.Conditions)
resizingReady, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
if resizingReady.Reason == vdcondition.InProgress.String() {
return fmt.Errorf("%w: waiting for the virtual disk %q to be resized", ErrVirtualDiskResizing, vd.Name)
}
Expand Down

0 comments on commit 79b9828

Please sign in to comment.