Frank
Frank

Reputation: 21

Best practice to trigger reconcile after updating K8S Operator

We have implemented an Operator for CRD in Kubernetes by Kubebuilder, and it is expected that the tasks this Operator needs to do in "reconcile" will be changed over time (more logic/handling will be appended). e.g.

First release @time t1 -> logic X

Second release @time t2 -> logic X + Y

Third release @time t3 -> logic X + Y + Z

AFAIK, the trigger for reconcile is the change happened on the CR. However, it is quite obvious that the reconcile should be also triggered in above case for all the managed CRs, but seems like this is not mentioned anywhere.

I wonder if there's any handy way to trigger the reconcile for all managed CRs, or if there's any best pratice for doing so.

----------- Update ------------

After adding log and deploy the Controller several times, I realized that this is by default done by the Controller already. It means every deployment will also trigger the reconcile of all the CRs it manages.

Upvotes: 2

Views: 1609

Answers (1)

user7610
user7610

Reputation: 28879

After adding log and deploy the Controller several times, I realized that this is by default done by the Controller already. It means every deployment will also trigger the reconcile of all the CRs it manages.

That's it!

The watch request always follows a list or get. So your controller is first fed the existing resources from the initial request, and only then it starts getting the changes from the watch.

The Kubernetes API allows clients to make an initial request for an object or a collection, and then to track changes since that initial request: a watch. Clients can send a list or a get and then make a follow-up watch request.

[...]

If a client watch is disconnected then that client can start a new watch from the last returned resourceVersion; the client could also perform a fresh get / list request and begin again. See Resource Version Semantics for more detail.

https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes

Upvotes: 0

Related Questions