Skip to content

Commit

Permalink
Stop appworkload reconciliation when DeletionTimestamp is set
Browse files Browse the repository at this point in the history
If we do not do this the appworkload controller keeps re-creating the
same statefulSet over and over again while it is being deleted by the
recursive foreground delete operation incurred by deletig the org (the
same happens on app deletion for similar reasons). This persistent
re-creation of the statefulset results in a significant slowdown of the
convergence of the delete operation

With this chage the reconciler stops creating statefulSets once it sees
that DeletionTimestamp is set, this speeding up the deletion convergence

fixes #36867
  • Loading branch information
georgethebeatle committed Jan 21, 2025
1 parent 5d6eb14 commit bf29c1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions statefulset-runner/controllers/appworkload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (r *AppWorkloadReconciler) ReconcileResource(ctx context.Context, appWorklo
appWorkload.Status.ObservedGeneration = appWorkload.Generation
log.V(1).Info("set observed generation", "generation", appWorkload.Status.ObservedGeneration)

if !appWorkload.GetDeletionTimestamp().IsZero() {
return ctrl.Result{}, nil
}

statefulSet, err := r.workloadsToStSet.Convert(appWorkload)
// Not clear what errors this would produce, but we may use it later
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions statefulset-runner/controllers/appworkload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers_test
import (
"context"
"errors"
"time"

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/statefulset-runner/controllers"
Expand Down Expand Up @@ -173,6 +174,22 @@ var _ = Describe("AppWorkload Reconcile", func() {
})
})

When("the appworkload is being deleted gracefully", func() {
BeforeEach(func() {
appWorkload.DeletionTimestamp = &metav1.Time{Time: time.Now()}
})

It("returns an empty result and does not return error", func() {
Expect(reconcileResult).To(Equal(ctrl.Result{}))
Expect(reconcileErr).NotTo(HaveOccurred())
})

It("creates no statefulset", func() {
Expect(fakeWorkloadToStSet.ConvertCallCount()).To(Equal(0))
Expect(fakeClient.CreateCallCount()).To(Equal(0))
})
})

When("the appworkload is being updated", func() {
BeforeEach(func() {
getStatefulSetError = nil
Expand Down

0 comments on commit bf29c1e

Please sign in to comment.