Skip to content

Commit 8b48adc

Browse files
corioliskrafttuunit
authored andcommitted
test: cover a failed server delete during machine deletion
The delete path removes the finalizer only after the cloud reports the server as deleted or as already gone. The other exit had no spec: a deletion that answers with any other error must keep the object. The new spec injects a transient error into the server delete, then asserts that the reconcile returns that error, that the server is still there, and that the finalizer still holds the object, so the next attempt can find the instance ID.
1 parent d41dea3 commit 8b48adc

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎controller/stackitmachine_controller_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,33 @@ var _ = Describe("StackitMachine Controller", func() {
461461
}).Should(BeTrue())
462462
})
463463

464+
It("keeps the finalizer when the server deletion fails", func() {
465+
// The delete path removes the finalizer only after the cloud reports the
466+
// server as deleted or as already gone. Any other delete error leaves the
467+
// server running, so the object must stay and the reconcile must retry.
468+
// Without the object, nothing holds the instance ID and the VM keeps
469+
// running unnoticed.
470+
updateMachineBootstrapSecret(ctx, machineName, bootstrapName)
471+
createBootstrapSecret(ctx, bootstrapName)
472+
473+
_, err := reconciler.Reconcile(ctx, request)
474+
Expect(err).NotTo(HaveOccurred())
475+
Expect(fakeCloud.ServerCount()).To(Equal(1))
476+
477+
got := &infrav1.StackitMachine{}
478+
Expect(k8sClient.Get(ctx, stackitKey, got)).To(Succeed())
479+
fakeCloud.FailNextDeleteServer = fmt.Errorf("delete server: %w", cloud.ErrTransient)
480+
481+
Expect(k8sClient.Delete(ctx, got)).To(Succeed())
482+
_, err = reconciler.Reconcile(ctx, request)
483+
484+
Expect(err).To(MatchError(cloud.ErrTransient))
485+
Expect(fakeCloud.ServerCount()).To(Equal(1))
486+
stillThere := &infrav1.StackitMachine{}
487+
Expect(k8sClient.Get(ctx, stackitKey, stillThere)).To(Succeed())
488+
Expect(stillThere.Finalizers).To(ContainElement(infrav1.MachineFinalizer))
489+
})
490+
464491
It("maps owning Machine events to StackitMachine reconcile requests", func() {
465492
machine := &clusterv1.Machine{}
466493
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: machineName, Namespace: namespace}, machine)).To(Succeed())

0 commit comments

Comments
 (0)