-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
How to force NOT to call Reconcile func again after updating the status subresource? #618
Comments
you can check status value and skip the update if the value is already in the correct state. This will help you avoid the infinity loop. But yes reconcile after subresource update is frustrating. |
https://book.kubebuilder.io/basics/status_subresource.html does not exist anymore, use https://book-v1.book.kubebuilder.io/basics/status_subresource.html instead. |
I see this issue too. Is there a way to skip the I'm following these links: https://book-v1.book.kubebuilder.io/basics/status_subresource.html https://book.kubebuilder.io/cronjob-tutorial/controller-implementation.html Comments below for the reconciled object in
Comments below for the
Returning reconciler's
|
You can use predicate functions to decide when to skip Reconcile:
and use this "p" object in Watch function.
I used the following command to generate api: Best Regards, |
Thanks @angrosz, will try predicate functions and keep you posted. |
the above answer is ok, except that it prevents you from "correcting" changes to status is something else changes status. This is why we generally recommend making controllers idempotent. |
I was able to use the https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource says the following about the
The above code skips the I see k8s' deployments use the
|
Just as a note. You don't necessarily need custom predicate functions. There are a couple in controller-runtime's
This seems like the best advice. One thing that I have found helpful to prevent hotlooping, without using a predicate, is to only update the status once per Reconcile. |
For further reading, using KubeBuilder v2 I managed to use predicates for not reconcile after updating as shown below. func (r *RedisReconciler) SetupWithManager(mgr ctrl.Manager) error {
pred := predicate.GenerationChangedPredicate{}
return ctrl.NewControllerManagedBy(mgr).For(&redisv1beta1.Redis{}).WithEventFilter(pred).Complete(r)
} All the examples I found were using kubebuilder v1, and the add Add and Watch functions. WithEventFilter is the method you should use to pass the predicate to your controller on the new version. |
Updating status subresource from operator reque the recocile request again which cause the recocile twice for the same request. Fix the issue using predicate. reference: kubernetes-sigs/kubebuilder#618 (comment) Signed-off-by: Nitin Goyal <nigoyal@redhat.com>
Updating status subresource from operator reque the recocile request again which cause the recocile twice for the same request. Fix the issue using predicate. reference: kubernetes-sigs/kubebuilder#618 (comment) Signed-off-by: Nitin Goyal <nigoyal@redhat.com>
Updating status subresource from operator reque the recocile request again which cause the recocile twice for the same request. Fix the issue using predicate. reference: kubernetes-sigs/kubebuilder#618 (comment) Signed-off-by: Nitin Goyal <nigoyal@redhat.com>
Does these filters also apply to owend objects? return ctrl.NewControllerManagedBy(mgr).
For(&dfv1.Step{}).
WithEventFilter(predicate.GenerationChangedPredicate{}).
Owns(&corev1.Pod{}).
Owns(&corev1.Service{}).
Complete(r) I care about the pod and service status, but not the step status. |
Fixes: aws-controllers-k8s/community#886 The reconciler will indefinitely requeue even when there have been no changes made to the `spec` or `status`. This is happening in both the adoption and resource reconciler types. The root cause comes from `controller-runtime` requeue-ing the resource when we patch the `status` subresource - see [this issue](kubernetes-sigs/kubebuilder#618) for details. This bug was introduced for the resource reconciler as part of #39 , since we now call `patchResourceStatus` on every reconcile loop. This fix adds an event filter to each manager, with a predicate that the resource must have changed generation. The generation is not changed unless there has been a modification to the `spec`.
Took me a while to figure this out, but if you want to only filter a subset of objects, you can pass a predicate to your builder calls. In your example @alexec, to filter status for return ctrl.NewControllerManagedBy(mgr).
For(&dfv1.Step{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&corev1.Pod{}).
Owns(&corev1.Service{}).
Complete(r) |
Hello,
I'm getting and updating status in my Reconciler code as it is stated on https://book.kubebuilder.io/basics/status_subresource.html page. I noticed that r.Status().Update(context.Background(), instance) triggers new call of Reconcile func. Is it possible NOT to call Reconcile func again after the status subresource is successfully finished?
I need to update the status to READY and finish Reconcile func. Calling again Reconcile func creates the infinitive loop in my code (for PATCH).
Best Regards,
Ania
The text was updated successfully, but these errors were encountered: