Skip to content

Commit

Permalink
chore: Refactor manifest reconciler (#1967)
Browse files Browse the repository at this point in the history
- remove preDelete and PostRun hook
- extract code related to manifest.status to new package
  • Loading branch information
ruanxin authored Oct 18, 2024
1 parent f0ac9bb commit b8f15be
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 366 deletions.
3 changes: 2 additions & 1 deletion internal/controller/kyma/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/kyma-project/lifecycle-manager/internal/manifest/parser"
"github.com/kyma-project/lifecycle-manager/internal/pkg/metrics"
"github.com/kyma-project/lifecycle-manager/internal/remote"
"github.com/kyma-project/lifecycle-manager/pkg/common"
"github.com/kyma-project/lifecycle-manager/pkg/log"
"github.com/kyma-project/lifecycle-manager/pkg/module/sync"
"github.com/kyma-project/lifecycle-manager/pkg/queue"
Expand Down Expand Up @@ -111,7 +112,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu

if r.SyncKymaEnabled(kyma) {
err := r.SkrContextFactory.Init(ctx, kyma.GetNamespacedName())
if !kyma.DeletionTimestamp.IsZero() && errors.Is(err, remote.ErrAccessSecretNotFound) {
if !kyma.DeletionTimestamp.IsZero() && errors.Is(err, common.ErrAccessSecretNotFound) {
return r.handleDeletedSkr(ctx, kyma)
}

Expand Down
2 changes: 0 additions & 2 deletions internal/controller/manifest/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@ func NewReconciler(mgr manager.Manager,
declarativev2.WithCustomStateCheck(statecheck.NewManagerStateCheck(statefulChecker, deploymentChecker)),
declarativev2.WithRemoteTargetCluster(lookup.ConfigResolver),
manifest.WithClientCacheKey(),
declarativev2.WithPostRun{manifest.PostRunCreateCR},
declarativev2.WithPreDelete{manifest.PreDeleteDeleteCR},
)
}
33 changes: 0 additions & 33 deletions internal/declarative/v2/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ type Options struct {
CustomStateCheck StateCheck

PostRenderTransforms []ObjectTransform

PostRuns []PostRun
PreDeletes []PreDelete
}

type Option interface {
Expand Down Expand Up @@ -112,36 +109,6 @@ func (o PostRenderTransformOption) Apply(options *Options) {
options.PostRenderTransforms = append(options.PostRenderTransforms, o.ObjectTransforms...)
}

// Hook defines a Hook into the declarative reconciliation
// skr is the runtime cluster
// kcp is the control-plane cluster
// obj is guaranteed to be the reconciled object and also to always preside in kcp.
type Hook func(ctx context.Context, skr Client, kcp client.Client, obj Object) error

// WARNING: DO NOT USE THESE HOOKS IF YOU DO NOT KNOW THE RECONCILIATION LIFECYCLE OF THE DECLARATIVE API.
// IT CAN BREAK YOUR RECONCILIATION AND IF YOU ADJUST THE OBJECT, ALSO LEAD TO
// INVALID STATES.
type (
// PostRun is executed after every successful render+reconciliation of the manifest.
PostRun Hook
// PreDelete is executed before any deletion of resources calculated from the status.
PreDelete Hook
)

// WithPostRun applies PostRun.
type WithPostRun []PostRun

func (o WithPostRun) Apply(options *Options) {
options.PostRuns = append(options.PostRuns, o...)
}

// WithPreDelete applies PreDelete.
type WithPreDelete []PreDelete

func (o WithPreDelete) Apply(options *Options) {
options.PreDeletes = append(options.PreDeletes, o...)
}

type WithSingletonClientCacheOption struct {
ClientCache
}
Expand Down
Loading

0 comments on commit b8f15be

Please sign in to comment.