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 #1292

Closed
TenSt opened this issue Apr 5, 2019 · 2 comments
Closed

Reconcile is triggered after status update #1292

TenSt opened this issue Apr 5, 2019 · 2 comments

Comments

@TenSt
Copy link

TenSt commented Apr 5, 2019

Type of question

How to update status of the custom CR without triggering Reconciler.

Question

What did you do?
I've updated Status of the CR and used client.Status().Update() func to update it.
Removed watcher on Pods, only one watcher left - for CRs.

What did you expect to see?
Reconciler did not triggered.

What did you see instead? Under which circumstances?
Reconciler triggered and started new reconcile loop when I've updated Status section of CR.

Environment

  • operator-sdk version: 0.6.0

https://github.com/operator-framework/operator-sdk/releases/tag/v0.6.0

  • Kubernetes version information:
    Client Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.9-dispatcher", GitCommit:"e3f5193e8f1091a162af7e17a781e6a3129bcfd0", GitTreeState:"clean", BuildDate:"2019-03-28T18:13:46Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.7-gke.12", GitCommit:"06f08e60069231bd21bdf673cf0595aac80b99f6", GitTreeState:"clean", BuildDate:"2019-02-25T20:37:10Z", GoVersion:"go1.10.8b4", Compiler:"gc", Platform:"linux/amd64"}

Also tested the same on 1.12.6 (GKE) and 1.13.4 (Typhoon) versions.

  • Kubernetes cluster kind:
    CRD, Pod.

Additional context
Here is my repo with basic generated API and Controller:
https://github.com/TenSt/app-operator
I did not changed initial generated structure of Spec and Status, only added on string Result to the Status struct.

This is how I'm setting CR status:
instance.Status.Result = "success"

This is how I'm calling client.Status().Update():
err := r.client.Status().Update(context.TODO(), instance)

Without calling client.Status().Update() reconciler loop doesn't start - I've verified it before adding status update.

Logs from Operator:
{"level":"info","ts":1554466255.514877,"logger":"cmd","msg":"Go Version: go1.12"}
{"level":"info","ts":1554466255.51493,"logger":"cmd","msg":"Go OS/Arch: linux/amd64"}
{"level":"info","ts":1554466255.5149407,"logger":"cmd","msg":"Version of operator-sdk: v0.6.0"}
{"level":"info","ts":1554466255.5152943,"logger":"leader","msg":"Trying to become the leader."}
{"level":"info","ts":1554466255.6518867,"logger":"leader","msg":"No pre-existing lock was found."}
{"level":"info","ts":1554466255.657651,"logger":"leader","msg":"Became the leader."}
{"level":"info","ts":1554466255.7356803,"logger":"cmd","msg":"Registering Components."}
{"level":"info","ts":1554466255.7363167,"logger":"kubebuilder.controller","msg":"Starting EventSource","controller":"appservice-controller","source":"kind source: /, Kind="}
{"level":"info","ts":1554466255.8228066,"logger":"metrics","msg":"Metrics Service object created","Service.Name":"app-operator","Service.Namespace":"default"}
{"level":"info","ts":1554466255.8228467,"logger":"cmd","msg":"Starting the Cmd."}
{"level":"info","ts":1554466255.9307475,"logger":"kubebuilder.controller","msg":"Starting Controller","controller":"appservice-controller"}
{"level":"info","ts":1554466256.0310385,"logger":"kubebuilder.controller","msg":"Starting workers","controller":"appservice-controller","worker count":1}
{"level":"info","ts":1554467617.0592692,"logger":"controller_appservice","msg":"Reconciling AppService","Request.Namespace":"default","Request.Name":"example-appservice"}
{"level":"info","ts":1554467617.1598823,"logger":"controller_appservice","msg":"Creating a new Pod","Request.Namespace":"default","Request.Name":"example-appservice","Pod.Namespace":"default","Pod.Name":"example-appservice-pod"}
{"level":"info","ts":1554467617.1952562,"logger":"controller_appservice","msg":"Successfully updated Status of the CR","Request.Namespace":"default","Request.Name":"example-appservice","instance.Namespace":"default","instance.Name":"example-appservice"}
{"level":"info","ts":1554467617.195742,"logger":"controller_appservice","msg":"Reconciling AppService","Request.Namespace":"default","Request.Name":"example-appservice"}
{"level":"info","ts":1554467617.1959531,"logger":"controller_appservice","msg":"Skip reconcile: Pod already exists","Request.Namespace":"default","Request.Name":"example-appservice","Pod.Namespace":"default","Pod.Name":"example-appservice-pod"}

Please advise if I'm doing something wrong or this is a bug.
Please let me know if you need any other information - will gladly provide it.

@joelanford
Copy link
Member

@TenSt This is expected behavior. If you change your CR, it will trigger another reconciliation. Once your CR has reached a steady state and your Reconcile function makes no further changes, you should stop seeing further immediate reconciliations.

@rufreakde
Copy link

rufreakde commented Dec 20, 2022

@joelanford is there any way to update a CR property without triggering an automated reconcile event:

For example a counter that can be used as a helper for very long reconciles backoffs for longer running reconciliation tasks?
In this case we want to control the timings more manually with

return ctrl.Result{
   		Requeue:      true,
   		RequeueAfter: GetSmartRequeTiming(crdInstance.Status.ReconcilesWithoutChangesCount),
   	}

EDIT:
I think I found a solution for this issue:
kubernetes-sigs/kubebuilder#980 (comment)

For anyone else encountering this.

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

No branches or pull requests

3 participants