Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Scope finalizer do not add finalizer to Kyma being deleted #986

Merged
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
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
Loading