How can I run once in a reconcile loop? #2699
-
I am creating an operator by kubebuilder, which accesses external cloud services and create resource there. Is it possible to do that? If yes, how can I do that? I would appreciate any help. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
The controller’s reconciliation loop needs to be idempotent when developing operators. By following the Operator pattern, you will create Controllers which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster. That means the idea is to observe the resources on the cluster (watches feature) and then ensure that when anything that matters changes, the controllers will reconcile the Kinds and ensure the desired state. Maybe look at can be helpful: https://sdk.operatorframework.io/docs/best-practices/common-recommendation/ |
Beta Was this translation helpful? Give feedback.
-
The accepted answer is correct in that this is how you need to think about these operators. However, this doesn't stop you from accessing the API in a smart way. Kubebuilder (and its related projects) already do this for the k8s API itself:
All this happens transparently, so when you try to say There's nothing stopping you from doing something similar, or something different against the cloud API. The naïve approach is to access the cloud API as you describe, once per reconcile. There is nothing wrong with your reconcile loop implementing something like this:
If your cloud API supports watching events (like the k8s watch API), then you can reduce the amount of stale reconciles you will have. |
Beta Was this translation helpful? Give feedback.
-
Closing since it is answered. |
Beta Was this translation helpful? Give feedback.
The controller’s reconciliation loop needs to be idempotent when developing operators. By following the Operator pattern, you will create Controllers which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.
That means the idea is to observe the resources on the cluster (watches feature) and then ensure that when anything that matters changes, the controllers will reconcile the Kinds and ensure the desired state. Maybe look at can be helpful: https://sdk.operatorframework.io/docs/best-practices/common-recommendation/