<p>I'm reading a lot of documentation about <a href="https://github.com/kubernetes/sample-controller" rel="nofollow noreferrer">CRD Controller</a></p>

<p>I've implemented one with my business logic, and sometimes I got this race condition:</p>

<ul>
<li>I create a Custom Object, let's call it <code>Foo</code> with name <code>bar</code></li>
<li>My business logic applies, let's says that it creates a <code>Deployment</code> with a <strong>generated</strong> name, and I save the name (as reference) it in the <code>Foo</code> object</li>
<li>I remove the Custom Object</li>
<li>I quickly recreate it with the same name, and sometimes I get this log:</li>
</ul>

<pre><code>error 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
</code></pre>

<p>The thing is because my <code>Deployment</code> has a generated name and maybe the save (Foo) has failed, I got two <code>Deployment</code> with two names.</p>

<p>I did not found a way to fix it for now, but it raises a question.</p>

<p><strong>How if I've multiple controllers running ?</strong> </p>

<p>I've started two controllers, and I got the same race condition by just creating a new object.</p>

<p>So, what is the best design to scale a CRD controller and avoid this kind of race conditions?</p>

<p>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.</p>
