Skip to content

Commit

Permalink
fix: Scope finalizer do not add finalizer to Kyma being deleted (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos77 authored Jan 27, 2025
1 parent e485aad commit 47d71a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/composed/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ package composed
import (
"context"
"errors"
"github.com/go-logr/logr"
ctrl "sigs.k8s.io/controller-runtime"
)

func HandleWithoutLogging(err error, ctx context.Context) (ctrl.Result, error) {
logger := logr.Discard()
ctx = LoggerIntoCtx(ctx, logger)
return Handle(err, ctx)
}

func Handle(err error, ctx context.Context) (ctrl.Result, error) {
logger := LoggerFromCtx(ctx)
if errors.Is(err, context.DeadlineExceeded) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/kcp/scope/addKymaFinalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ func addKymaFinalizer(ctx context.Context, st composed.State) (error, context.Co

if !state.ObjAsScope().DeletionTimestamp.IsZero() {
// Scope is being deleted
return nil, nil
return nil, ctx
}

if !state.kyma.GetDeletionTimestamp().IsZero() {
// kyma is being deleted - it has deletionTimestamp and finalizer can not be added in that state
return nil, ctx
}

added, err := composed.PatchObjAddFinalizer(ctx, cloudcontrolv1beta1.FinalizerName, state.kyma, state.Cluster().K8sClient())
Expand Down
8 changes: 7 additions & 1 deletion pkg/kcp/scope/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ func (r *scopeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
state := r.newState(req)
action := r.newAction()

return composed.Handle(action(ctx, state))
// Scope reconciler is triggered very often due to KLM constant changes on watched Kyma
// HandleWithoutLogging should be used, so no reconciliation outcome is logged since it most cases
// the reconciler will do nothing since no change regarding CloudManager was done on Kyma
// so it will just produce an unnecessary log entry "Reconciliation finished without control error - doing stop and forget"
// To accommodate this non-functional requirement to keep logs tidy and prevent excessive and not so usable log entries
// in cases when Scope actually did something we have to accept the discomfort of not having this log entry
return composed.HandleWithoutLogging(action(ctx, state))
}

func (r *scopeReconciler) newState(req ctrl.Request) *State {
Expand Down

0 comments on commit 47d71a0

Please sign in to comment.