How to UpdateStatus and requeue "Reconcile" events until a desired state is reached? #551
-
I have a CRD which defines a resource (say X). CRUD operations on X are handled by a different service which returns a "requestId" when a resource creation is requested. Following are the sequence of operations I am currently doing in my controller: When a custom-resource is created, I am calling the service to create the resource. Am I doing something of an anti-pattern here? Some due diligence (incase it might help anyone looking in anyway): dotnet-operator-sdk/src/KubeOps/Operator/Controller/EventQueue.cs Lines 44 to 55 in 3f42bbc |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hey @Karthik2893 In theory, you should be able to check your resource (the state of it), and then either return a requeue request or null. If null is returned, the resource does not get reconciled right now (only when the watcher terminates the connection). The code you mention groups all events by resource id. The "ProcessDelay" method returns a new observable with a delayed start (if any) and the switch changes to that observable instead. This should not impact your usecase. It is not an anti-pattern (IMO). You create an instance of a CRD, which then creates some external resource. This is totally fine. sequenceDiagram
actor u as User
participant a as API
participant o as Operator
participant e as External
u ->> a: Create CRD instance
a ->> o: Instance Created
o ->> e: Create
loop Check Status
o ->> e: Status?
alt Successful
o ->> o: Resolve reconcile with "null"
else
o ->> o: Resolve reconcile with re-queue
end
end
Is this diagram showing your use-case or did I get something wrong? If yes, this should be possible. |
Beta Was this translation helpful? Give feedback.
-
Thanks @buehler for taking the time out and responding to my question. The use-case I intended to describe above is a little different. Following is the updated picture that reflects my use-case: In the outer loop, everytime I retrieve the Status from the external service, I am doing the following:
Following are my observations:
I am assuming that the "Status" on the CRD instance can be updated to reflect the current state of the resource and we should have the provision to resolve reconcile with "Requeue" as long as the resource is not in one of the desired terminal states. Is this an anti pattern? I linked the below snippet because I suspected that the "Switch" might be causing this behavior. Going strictly by the definition, "Switch" produces values only from the most recent observable sequence. So, I was thinking the "Requeue" events are being ignored whenever the "StatusModified" events are posted. (I have never used Rx before, so my understanding is very theoretical, please ignore if I got this wrong ). dotnet-operator-sdk/src/KubeOps/Operator/Controller/EventQueue.cs Lines 44 to 55 in 3f42bbc Thank you. |
Beta Was this translation helpful? Give feedback.
-
Hi @buehler , just a gentle reminder to check out my above response from last week regarding. It would help us get some clarity on our implementation and I'd really appreciate your input. Let me know if you have any questions. |
Beta Was this translation helpful? Give feedback.
Alright, I understand the use-case and no, it is not an anti-pattern. This behavior can be seen in many operators. This is a bug.
Since the status update does trigger and the reconcile doesn't, the switch/merge magic you point out may be the issue. The switch is there to prevent duplicate events, in case of status only updates however, they should fire.