Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry.lopatin <[email protected]>
  • Loading branch information
LopatinDmitr committed Dec 9, 2024
1 parent 01d4cb6 commit 50e00fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions api/core/v1alpha2/vmcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
TypeAgentReady Type = "AgentReady"
TypeAgentVersionNotSupported Type = "AgentVersionNotSupported"
TypeConfigurationApplied Type = "ConfigurationApplied"
TypePowerConfigurationApplied Type = "PowerConfigurationApplied"
TypeAwaitingRestartToApplyConfiguration Type = "AwaitingRestartToApplyConfiguration"
TypeFilesystemReady Type = "FilesystemReady"
TypeSizingPolicyMatched Type = "SizingPolicyMatched"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ func (h *SyncPowerStateHandler) Handle(ctx context.Context, s state.VirtualMachi
current := s.VirtualMachine().Current()
changed := s.VirtualMachine().Changed()

cbConfApplied := conditions.NewConditionBuilder(vmcondition.TypeConfigurationApplied).
cbPowerConfApplied := conditions.NewConditionBuilder(vmcondition.TypePowerConfigurationApplied).
Generation(current.GetGeneration()).
Status(metav1.ConditionUnknown).
Reason(conditions.ReasonUnknown)

defer func() {
conditions.SetCondition(cbConfApplied, &changed.Status.Conditions)
conditions.SetCondition(cbPowerConfApplied, &changed.Status.Conditions)
}()

kvvm, err := s.KVVM(ctx)
if err != nil {
cbConfApplied.
cbPowerConfApplied.
Status(metav1.ConditionFalse).
Reason(vmcondition.ReasonConfigurationNotApplied).
Message(service.CapitalizeFirstLetter(err.Error()) + ".")
Expand All @@ -82,10 +82,15 @@ func (h *SyncPowerStateHandler) Handle(ctx context.Context, s state.VirtualMachi
if err != nil {
err = fmt.Errorf("failed to sync powerstate: %w", err)
h.recorder.Event(current, corev1.EventTypeWarning, virtv2.ReasonErrVmNotSynced, err.Error())
cbConfApplied.
cbPowerConfApplied.
Status(metav1.ConditionFalse).
Reason(vmcondition.ReasonConfigurationNotApplied).
Message(service.CapitalizeFirstLetter(err.Error()) + ".")
} else {
cbPowerConfApplied.
Status(metav1.ConditionTrue).
Reason(vmcondition.ReasonConfigurationApplied).
Message("")
}

return reconcile.Result{}, err
Expand Down Expand Up @@ -119,7 +124,6 @@ func (h *SyncPowerStateHandler) syncPowerState(ctx context.Context, s state.Virt
return fmt.Errorf("force AlwaysOff: delete KVVMI: %w", err)
}
}
err = h.ensureRunStrategy(ctx, kvvm, virtv1.RunStrategyHalted)
case virtv2.AlwaysOnPolicy:
strategy, _ := kvvm.RunStrategy()
if strategy == virtv1.RunStrategyAlways && kvvmi == nil {
Expand All @@ -145,8 +149,6 @@ func (h *SyncPowerStateHandler) syncPowerState(ctx context.Context, s state.Virt
}
}
}

err = h.ensureRunStrategy(ctx, kvvm, virtv1.RunStrategyManual)
case virtv2.AlwaysOnUnlessStoppedManually:
strategy, _ := kvvm.RunStrategy()
if strategy == virtv1.RunStrategyAlways && kvvmi == nil {
Expand Down Expand Up @@ -183,8 +185,6 @@ func (h *SyncPowerStateHandler) syncPowerState(ctx context.Context, s state.Virt
}
}
}

err = h.ensureRunStrategy(ctx, kvvm, virtv1.RunStrategyManual)
case virtv2.ManualPolicy:
// Manual policy requires to handle only guest-reset event.
// All types of shutdown are a final state.
Expand All @@ -207,10 +207,10 @@ func (h *SyncPowerStateHandler) syncPowerState(ctx context.Context, s state.Virt
}
}
}

err = h.ensureRunStrategy(ctx, kvvm, virtv1.RunStrategyManual)
}

err = h.ensureRunStrategy(ctx, kvvm, virtv1.RunStrategyManual)

if err != nil {
return fmt.Errorf("enforce runPolicy %s: %w", vmRunPolicy, err)
}
Expand Down

0 comments on commit 50e00fc

Please sign in to comment.