Skip to content

Commit 5bf6b9a

Browse files
committed
fix(agent): set TerminatedAt=Failed when source VM not found in snapshot reconciler
1 parent 2f34c98 commit 5bf6b9a

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

internal/agent/impvmsnapshot_reconciler.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ func (r *ImpVMSnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Reques
4444
Namespace: snap.Spec.SourceVMNamespace,
4545
Name: snap.Spec.SourceVMName,
4646
}, vm); err != nil {
47-
return ctrl.Result{}, client.IgnoreNotFound(err)
47+
if client.IgnoreNotFound(err) != nil {
48+
return ctrl.Result{}, err
49+
}
50+
// VM deleted — terminal failure, unblock next execution.
51+
now := metav1.Now()
52+
base := snap.DeepCopy()
53+
snap.Status.Phase = "Failed"
54+
snap.Status.TerminatedAt = &now
55+
return ctrl.Result{}, r.Status().Patch(ctx, snap, client.MergeFrom(base))
4856
}
4957
if vm.Spec.NodeName != r.NodeName {
5058
return ctrl.Result{}, nil

internal/agent/impvmsnapshot_reconciler_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,16 @@ func TestSnapshotReconciler_skipsAlreadyTerminated(t *testing.T) {
129129
t.Fatalf("unexpected error: %v", err)
130130
}
131131
_ = res // no-op
132+
133+
// Verify the snapshot was not mutated.
134+
fetched := &impdevv1alpha1.ImpVMSnapshot{}
135+
if err := c.Get(context.Background(), types.NamespacedName{Name: "snap-child", Namespace: "default"}, fetched); err != nil {
136+
t.Fatalf("get snap: %v", err)
137+
}
138+
if fetched.Status.Phase != "Succeeded" {
139+
t.Errorf("expected phase=Succeeded, got %q", fetched.Status.Phase)
140+
}
141+
if fetched.Status.TerminatedAt == nil {
142+
t.Error("expected TerminatedAt to remain set")
143+
}
132144
}

0 commit comments

Comments
 (0)