Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/controller/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,11 @@ func MaintainInstallationFinalizer(
log.Error(err, "An error occurred when querying the Installation resource")
return finalizerSet, err
}
patchFrom := client.MergeFrom(installation.DeepCopy())
// Use optimistic locking so that concurrent finalizer patches from different controllers
// (e.g., whisker and goldmane) produce a conflict error instead of silently overwriting
// each other. JSON merge patch replaces the entire finalizers array, so without the lock
// the second writer wins and the first controller's finalizer is lost until re-reconciliation.
patchFrom := client.MergeFromWithOptions(installation.DeepCopy(), client.MergeFromWithOptimisticLock{})

// Determine the correct finalizers to apply to the Installation.
if mainResource != nil {
Expand Down
13 changes: 10 additions & 3 deletions test/whisker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,16 @@ var _ = Describe("Tests for Whisker installation", func() {

By("Verifying that the whisker and goldmane finalizer is created in the installation CR")
install := &operator.Installation{ObjectMeta: metav1.ObjectMeta{Name: "default"}}
Expect(GetResource(c, install)).To(BeNil())
Expect(install.ObjectMeta.Finalizers).To(ContainElement(render.WhiskerFinalizer))
Expect(install.ObjectMeta.Finalizers).To(ContainElement(render.GoldmaneFinalizer))
Eventually(func() error {
Expect(GetResource(c, install)).To(BeNil())
if !slices.Contains(install.ObjectMeta.Finalizers, render.WhiskerFinalizer) {
return fmt.Errorf("expected whisker finalizer to be present, but found: %v", install.ObjectMeta.Finalizers)
}
if !slices.Contains(install.ObjectMeta.Finalizers, render.GoldmaneFinalizer) {
return fmt.Errorf("expected goldmane finalizer to be present, but found: %v", install.ObjectMeta.Finalizers)
}
return nil
}, 1*time.Minute, 1*time.Second).Should(BeNil())

By("Verifying that the whisker finalizer is removed in the installation CR")
Expect(c.Delete(context.Background(), whiskerCR)).To(BeNil())
Expand Down
Loading