Skip to content

Commit

Permalink
fix(vm): force the startup of a VM with an AlwaysOnUnlessStoppedManua…
Browse files Browse the repository at this point in the history
…lly policy when creating (#181)

Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat authored Jul 4, 2024
1 parent 8f7557b commit a86590b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ func (h *SyncKvvmHandler) syncKVVM(ctx context.Context, s state.VirtualMachineSt
lastAppliedSpec = &current.Spec
case changes != nil:
// Delay changes propagation to KVVM until user restarts VM.
var statusChanges []apiextensionsv1.JSON
statusChanges, err = changes.ConvertPendingChanges()
cb := conditions.NewConditionBuilder2(vmcondition.TypeAwaitingRestartToApplyConfiguration).
Generation(current.GetGeneration())

var statusChanges []apiextensionsv1.JSON
statusChanges, err = changes.ConvertPendingChanges()
if err != nil {
cb.Status(metav1.ConditionFalse).
Reason2(vmcondition.ReasonRestartAwaitingChangesNotExist).
Expand Down Expand Up @@ -537,6 +538,12 @@ func (h *SyncKvvmHandler) syncPowerState(ctx context.Context, kvvm *virtv1.Virtu
// kubevirt restarts VM via re-creation of KVVMI.
err = h.ensureRunStrategy(ctx, kvvm, virtv1.RunStrategyAlways)
case virtv2.AlwaysOnUnlessStoppedManually:
strategy, _ := kvvm.RunStrategy()
if strategy == virtv1.RunStrategyAlways && kvvmi == nil {
if err = powerstate.StartVM(ctx, h.client, kvvm); err != nil {
return fmt.Errorf("failed to start VM: %w", err)
}
}
if kvvmi != nil && kvvmi.DeletionTimestamp == nil {
if kvvmi.Status.Phase == virtv1.Succeeded {
if vmPodCompleted {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func compareRunPolicy(current, desired *v1alpha2.VirtualMachineSpec) []FieldChan

func compareVirtualMachineIPAddressClaim(current, desired *v1alpha2.VirtualMachineSpec) []FieldChange {
return compareStrings(
"virtualMachineIPAddressClaim",
"virtualMachineIPAddressClaimName",
current.VirtualMachineIPAddressClaim,
desired.VirtualMachineIPAddressClaim,
"",
Expand All @@ -65,7 +65,7 @@ func compareDisruptions(current, desired *v1alpha2.VirtualMachineSpec) []FieldCh

// Disruptions are not nils, compare approvalMode fields using "Manual" as default.
return compareStrings(
"disruptions.approvalMode",
"disruptions.restartApprovalMode",
string(current.Disruptions.RestartApprovalMode),
string(desired.Disruptions.RestartApprovalMode),
string(DefaultDisruptionsApprovalMode),
Expand Down Expand Up @@ -139,7 +139,7 @@ func compareCPU(current, desired *v1alpha2.VirtualMachineSpec) []FieldChange {
return fractionChanges
}

modelChanges := compareStrings("cpu.virtualMachineCPUModel", current.CPU.VirtualMachineCPUModel, desired.CPU.VirtualMachineCPUModel, DefaultCPUModelName, ActionRestart)
modelChanges := compareStrings("cpu.virtualMachineCPUModelName", current.CPU.VirtualMachineCPUModel, desired.CPU.VirtualMachineCPUModel, DefaultCPUModelName, ActionRestart)
if HasChanges(modelChanges) {
return modelChanges
}
Expand Down

0 comments on commit a86590b

Please sign in to comment.