kubernetes-sigs / controller-runtime

Repo for the controller-runtime subproject of kubebuilder (sig-apimachinery)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow modifying context per `Reconcile(ctx context.Context, req ctrl.Request)`

programmer04 opened this issue · comments

There is BaseContextFunc that can be configured to provide Context values to Runnables managed by the Manager. When not specified Runnables will receive a new Background Context instead.

Let's imagine that some additional data has to be available in each Reconcile(ctx context.Context, req ctrl.Request) method. Passing it via context can be a solution. Implementation of the method can get it from ctx and make use of it. But BaseContextFunc is evaluated only once after a start, hence it can't be used for values that should be evaluated per Reconcile call and preserve its value during the whole single Reconcile execution.

The proposition is to introduce ReconcileContextFunc which will be similar to already existing BaseContextFunc, but it will be evaluated before every calling of Reconcile(ctx context.Context, req ctrl.Request) by a manager.

Such a feature will allow a static value (just evaluated before) available in the context of the whole Reconcile call. Such a thing resolves a consistency problem. Let's imagine that such value can change at any moment it is needed multiple times in Reconcile, by having evaluated it in context before the call it won't change. Actual use case for this feature (currently achieved by workaround).

You can achieve this by wrapping your reconciler, there is no need for a change in controller-runtime

/kind support
/close

@vincepri: Closing this issue.

In response to this:

/kind support
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.