Skip to content

Commit

Permalink
update garbage collector
Browse files Browse the repository at this point in the history
  • Loading branch information
henderiw committed Nov 13, 2024
1 parent 1750d63 commit 092e2ca
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/rn/0.0.17.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

[ChangeLog](https://github.com/kform-dev/choreo/releases)

## fix config removal
## garbage collector

garbage collecor also takes into account deleteTimestamp to identify garbage resources.

## result command

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/apiserver/registry/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *storage) Delete(ctx context.Context, name string, opts ...rest.DeleteOp
}

u := &unstructured.Unstructured{Object: old.UnstructuredContent()}
log.Info("delete choreoapiserver", "apiVersion", u.GetAPIVersion(), "kind", u.GetKind(), "name", u.GetName())
log.Debug("delete choreoapiserver", "apiVersion", u.GetAPIVersion(), "kind", u.GetKind(), "name", u.GetName())

oldObjectMeta, err := meta.Accessor(old)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/server/choreo/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (r *run) once(ctx context.Context, bctx *BranchCtx) {

// loads upstream refs, apis, reconcilers, data and garbage collect
func (r *run) Load(ctx context.Context, branchCtx *BranchCtx) error {
log := log.FromContext(ctx)
// we only work with checkout branch
rootChoreoInstance := r.choreo.GetRootChoreoInstance()

Expand All @@ -284,7 +285,7 @@ func (r *run) Load(ctx context.Context, branchCtx *BranchCtx) error {
rootChoreoInstance.InitAPIs()
apis := rootChoreoInstance.GetAPIs()
if err := r.loadAPIs(ctx, branchCtx, rootChoreoInstance, apis); err != nil {
fmt.Println("apis", err)
log.Error("loading apis failed", "error", err)
return err
}

Expand Down Expand Up @@ -350,7 +351,7 @@ func (r *run) Load(ctx context.Context, branchCtx *BranchCtx) error {
u.SetName(ref.Name)
u.SetNamespace(ref.Namespace)

fmt.Println("delete garbage", u.GetAPIVersion(), u.GetKind(), u.GetName())
log.Info("delete garbage resource", "apiVersion", u.GetAPIVersion(), "kind", u.GetKind(), "name", u.GetName())

if err := r.choreo.GetClient().Delete(ctx, u, &resourceclient.DeleteOptions{
Branch: branchCtx.Branch,
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func (r Inventory) getRoots() []*treeNode {
func (r Inventory) CollectGarbage() sets.Set[corev1.ObjectReference] {
g := newGarbageCollector()
for _, node := range r {
if node.Resource == nil {
fmt.Println("CollectGarbage", node.Resource)
if node.Resource == nil || node.Resource.GetDeletionTimestamp() != nil {
//fmt.Println("CollectGarbage", node.Resource)
g.collect(node)
}
}
Expand Down

0 comments on commit 092e2ca

Please sign in to comment.