Skip to content

Commit

Permalink
handle deletion done
Browse files Browse the repository at this point in the history
  • Loading branch information
free6om committed Sep 30, 2024
1 parent d1d7aa3 commit 73c88af
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions controllers/view/deletion_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package view

import (
viewv1 "github.com/apecloud/kubeblocks/apis/view/v1"
"github.com/apecloud/kubeblocks/pkg/controller/kubebuilderx"
"github.com/apecloud/kubeblocks/pkg/controller/model"
)

type deletionHandler struct{}
type deletionHandler struct {
store ObjectRevisionStore
}

func (h *deletionHandler) PreCondition(tree *kubebuilderx.ObjectTree) *kubebuilderx.CheckResult {
if tree.GetRoot() == nil || !model.IsObjectDeleting(tree.GetRoot()) {
Expand All @@ -34,15 +37,23 @@ func (h *deletionHandler) PreCondition(tree *kubebuilderx.ObjectTree) *kubebuild
}

func (h *deletionHandler) Reconcile(tree *kubebuilderx.ObjectTree) (kubebuilderx.Result, error) {
// TODO(free6om)
// unwatch resources
view, _ := tree.GetRoot().(*viewv1.ReconciliationView)

// store cleanup
for _, change := range view.Status.CurrentState.Changes {
objectRef := objectReferenceToRef(&change.ObjectReference)
h.store.Delete(objectRef, view, change.Revision)
}
// TODO(free6om): events cleanup

// remove finalizer
tree.DeleteRoot()

return kubebuilderx.Commit, nil
}

func handleDeletion() kubebuilderx.Reconciler {
return &deletionHandler{}
func handleDeletion(store ObjectRevisionStore) kubebuilderx.Reconciler {
return &deletionHandler{store: store}
}

var _ kubebuilderx.Reconciler = &deletionHandler{}

0 comments on commit 73c88af

Please sign in to comment.