Amol Deodhar
Amol Deodhar

Reputation: 71

kubernetes: multiple reconcile instances updating the same non-kubernetes object

I have a kubernetes reconciler written in GO. The MaxConcurrentReconciles set to be greater than one.

Every time the target kubernetes object gets deleted, I need to update a list(remove the id of the target object) with an API.

My issue is that if I have three objects getting deleted, 3 instances of the reconciler run and each tries to update the list.

Initial List: [id1, id2, id3]

Reconciler instance 1 updates this to [id2, id3], instance 2 then updates this to [id1, id3], and so on. (The order will differ and depend upon what instance is executing the API call first)

How can apply something like a mutex lock (sync.RWMutex) so that only one instance modifies the list comes back and the second instance can then use it, so that

Initial List: [id1, id2, id3]
Lock and run instance 1: [id2, id3] ---> operation complete
Lock and run instance 2: [id3] ---> operation complete
Lock and run instance 3: [] ---> operation complete

Upvotes: 1

Views: 36

Answers (0)

Related Questions