I'm reading a lot of documentation about CRD Controller
I've implemented one with my business logic, and sometimes I got this race condition:
Foo
with name bar
Deployment
with a generated name, and I save the name (as reference) it in the Foo
objecterror syncing 'default/bar': Operation cannot be fulfilled on Foo.k8s.io "bar":
the object has been modified; please apply your changes to the latest version
and try again, requeuing
The thing is because my Deployment
has a generated name and maybe the save (Foo) has failed, I got two Deployment
with two names.
I did not found a way to fix it for now, but it raises a question.
How if I've multiple controllers running ?
I've started two controllers, and I got the same race condition by just creating a new object.
So, what is the best design to scale a CRD controller and avoid this kind of race conditions?
Generally you only run one copy of a controller, or at least only one is active at any given time. As long as you were careful to write your code convergently then it shouldn't technically matter, but there really isn't much reason to run multiple.