Skip to content

Commit 69d4f1a

Browse files
authored
fix(vm): recreate unschedulable intvirtvmi's pod (#1512)
This workaround is required due to a bug in the KVVM workflow. When a KVVM is created with conflicting placement rules and cannot be scheduled, it remains unschedulable even if these rules are changed or removed. Signed-off-by: Roman Sysoev <[email protected]>
1 parent 6557959 commit 69d4f1a

File tree

1 file changed

+38
-0
lines changed
  • images/virtualization-artifact/pkg/controller/vm/internal

1 file changed

+38
-0
lines changed

images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ func (h *SyncKvvmHandler) syncKVVM(ctx context.Context, s state.VirtualMachineSt
279279
}
280280

281281
switch {
282+
// This workaround is required due to a bug in the KVVM workflow.
283+
// When a KVVM is created with conflicting placement rules and cannot be scheduled,
284+
// it remains unschedulable even if these rules are changed or removed.
285+
case h.isVMUnschedulable(s.VirtualMachine().Current(), kvvm) && h.isPlacementPolicyChanged(allChanges):
286+
err := h.updateKVVM(ctx, s)
287+
if err != nil {
288+
return false, fmt.Errorf("failed to update internal virtual machine: %w", err)
289+
}
290+
err = object.DeleteObject(ctx, h.client, pod)
291+
if err != nil {
292+
return false, fmt.Errorf("failed to delete the internal virtual machine instance's pod: %w", err)
293+
}
294+
return true, nil
282295
case h.isVMStopped(s.VirtualMachine().Current(), kvvm, pod):
283296
// KVVM must be updated when the VM is stopped because all its components,
284297
// like VirtualDisk and other resources,
@@ -659,3 +672,28 @@ func (h *SyncKvvmHandler) updateKVVMLastAppliedSpec(
659672

660673
return nil
661674
}
675+
676+
func (h *SyncKvvmHandler) isVMUnschedulable(
677+
vm *v1alpha2.VirtualMachine,
678+
kvvm *virtv1.VirtualMachine,
679+
) bool {
680+
if vm.Status.Phase == v1alpha2.MachinePending && kvvm.Status.PrintableStatus == virtv1.VirtualMachineStatusUnschedulable {
681+
return true
682+
}
683+
684+
return false
685+
}
686+
687+
// isPlacementPolicyChanged returns true if any of the Affinity, NodePlacement, or Toleration rules have changed.
688+
func (h *SyncKvvmHandler) isPlacementPolicyChanged(allChanges vmchange.SpecChanges) bool {
689+
for _, c := range allChanges.GetAll() {
690+
switch c.Path {
691+
case "affinity", "nodeSelector", "tolerations":
692+
if !equality.Semantic.DeepEqual(c.CurrentValue, c.DesiredValue) {
693+
return true
694+
}
695+
}
696+
}
697+
698+
return false
699+
}

0 commit comments

Comments
 (0)