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

Reconcile is triggered after status update #2831

Open
beatrausch opened this issue May 15, 2024 · 4 comments
Open

Reconcile is triggered after status update #2831

beatrausch opened this issue May 15, 2024 · 4 comments
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@beatrausch
Copy link

Hi all,

we observed an interesting behavior that after an status update without any change leads to an reschedule of the resource, which triggers the reconcile loop again.

Code that is executed in the reconcile loop:

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	logger := logging.FromContext(ctx)

	resource := r.newResource()
	if err := r.client.Get(ctx, req.NamespacedName, resource); err != nil {
		return ctrl.Result{}, client.IgnoreNotFound(err)
	}

	logger.Infof("Reconcile ....")
	return ctrl.Result{RequeueAfter: time.Minute}, r.client.Status().Update(ctx, resource)
}

Output after the resoruce creation:

2024-05-15T15:18:43+02:00 INFO Reconcile .... {"controller": "stream", "reconcileID": "fad5bca2-9729-4799-b05c-80a2e9d929a8"}
2024-05-15T15:18:43+02:00 INFO Reconcile .... {"controller": "stream", "reconcileID": "521a821c-49fb-42fc-a07e-78f977a6f109"}

Why does it not trigger more than two times after object creation? If an update on the status leads to a new reconciling, we would expect an infinite loop without sleeping/delay.

How could we ensure that the object is just once reconciled?

Used controller-runtime version:
sigs.k8s.io/controller-runtime v0.16.3

Thx, Regards

@alvaroaleman
Copy link
Member

This is expected. The only way to avoid this is to have the status subresource enabled and use the GenerationChangedPredicate.

/kind support

@k8s-ci-robot k8s-ci-robot added the kind/support Categorizes issue or PR as a support question. label May 15, 2024
@beatrausch
Copy link
Author

Hi,

thx for the fast feedback.
Can you explain why it stops after the second reconciliation? What is the circuit breaker?

Regards

@beatrausch
Copy link
Author

beatrausch commented May 16, 2024

After some investigation it seems that the resource version does not change after the second reconciliation. which then stops to send updates to the controller. Detection of Resource Changes

Can you confirm?

@sbueringer
Copy link
Member

You get update events as long as your object changes. If it stops changing you won't get them anymore
(same for spec & status)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

4 participants