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

Use controller-runtime's ObjectReconciler to simplify code in reconcilers #46

Open
pmalek opened this issue Mar 21, 2024 · 1 comment
Open
Labels
good first issue Good for newcomers

Comments

@pmalek
Copy link
Member

pmalek commented Mar 21, 2024

Problem Statement

Recent versions of controller-runtime include https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.17.2/pkg/reconcile#ObjectReconciler which allows to get rid of the ubiquitous:

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	o := new(MyType)
	if err := r.Client.Get(ctx, req.NamespacedName, o); err != nil {
		if k8serrors.IsNotFound(err) {
			return ctrl.Result{}, nil
		}
		return ctrl.Result{}, err
	}
	log.Trace(logger, "reconciling resource", o)

in favor of simpler:

func (r *Reconciler) Reconcile(ctx context.Context, o *MyType) (ctrl.Result, error) {
	log.Trace(logger, "reconciling resource", o)

Related PR: kubernetes-sigs/controller-runtime#2592

@pmalek pmalek added the good first issue Good for newcomers label Mar 21, 2024
@pmalek pmalek changed the title Use controller-runtime's ObjectReconciler to simplify code in reconcilers' code Use controller-runtime's ObjectReconciler to simplify code in reconcilers Mar 21, 2024
@Chever-John
Copy link

Sounds like a nice first issue, I'll give it a try over this night:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants