Skip to content

Commit 3d79fdc

Browse files
committed
fix(controller): guard handleResetRetries against non-terminal VM phases
1 parent 744c7f3 commit 3d79fdc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

internal/controller/restart.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ func (r *ImpVMReconciler) handleFailed(ctx context.Context, vm *impdevv1alpha1.I
169169
// It is invoked when the annotation imp/reset-retries: "true" is present on the VM.
170170
func (r *ImpVMReconciler) handleResetRetries(ctx context.Context, vm *impdevv1alpha1.ImpVM) (ctrl.Result, error) {
171171
log := logf.FromContext(ctx)
172+
173+
// Only reset when the VM is in a terminal phase — resetting a Running VM would
174+
// orphan the live Firecracker process on the node agent.
175+
switch vm.Status.Phase {
176+
case impdevv1alpha1.VMPhaseFailed, impdevv1alpha1.VMPhaseRetryExhausted:
177+
// allowed
178+
default:
179+
log.V(1).Info("ignoring reset-retries annotation on non-terminal VM", "vm", vm.Name, "phase", vm.Status.Phase)
180+
base := vm.DeepCopy()
181+
delete(vm.Annotations, AnnotationResetRetries)
182+
return ctrl.Result{}, r.Patch(ctx, vm, client.MergeFrom(base))
183+
}
184+
172185
log.Info("resetting retry counter via annotation", "vm", vm.Name)
173186

174187
// Remove annotation first

0 commit comments

Comments
 (0)