<p>This is a follow-up from my last question - <a href="https://stackoverflow.com/q/64881584/5291015">How to programmatically modify a running k8s pod status conditions?</a> after which I realized, you can only patch the container spec from the deployment manifest to seamlessly let the controller apply the patch changes to the pods through the ReplicaSet it created.</p>
<p>Now my question is how to apply patch to make the Pod phase to go to <code>Succeeded</code> or <code>Failed</code>. I know for e.g. for pod phase to go to <code>Succeeded</code>, all the containers need to terminate successfully and shouldn't be restarted. My intention is to not modify the original command and arguments from the container image, but apply a patch to introduce a custom command which will override the one from the container image.</p>
<p>So I attempted to do below to run <code>exit 0</code> as below</p>
<pre class="lang-sh prettyprint-override"><code>kubectl -n foo-ns patch deployment foo-manager -p '
{
  &quot;spec&quot;: {
    &quot;template&quot;: {
      &quot;spec&quot;: {
        &quot;containers&quot;: [
          {
            &quot;name&quot;: &quot;container1&quot;,
            &quot;command&quot;: [
              &quot;exit&quot;,
              &quot;0&quot;
            ]
          },
          {
            &quot;name&quot;: &quot;container2&quot;,
            &quot;command&quot;: [
              &quot;exit&quot;,
              &quot;0&quot;
            ]
          }
        ]
      }
    }
  }
}'
</code></pre>
<p>But since my container file system layers are built from <code>FROM scratch</code>, there aren't any native commands available other than the original executable supposed to run i.e. <code>exit</code> as a built-in is not even available.</p>
<p>What's the best way to do this? by patching the pod to make it transition to either of those Pod phases.</p>

Inian
<blockquote>
<p>how to apply patch to make the Pod phase to go to Succeeded or Failed</p>
</blockquote>
<p>Pods are intended to be <strong>immutable</strong> - don't try to change them - instead, replace them with new Pods. You can create <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/" rel="nofollow noreferrer">ReplicaSet</a> directly, but mostly, you want to work with <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deployment</a> that is replacing the current ReplicaSet for every change on the Pod-template.</p>
<blockquote>
<p>Basically I'm testing one of my custom controllers can catch a pod's phase (and act on it) when it is stuck in a certain state e.g. Pending</p>
</blockquote>
<p>All Pods goes through those states. For testing, you can create <a href="https://kubernetes.io/docs/concepts/workloads/pods/" rel="nofollow noreferrer">Pods</a> directly, with different binaries or arguments.</p>
<p>To test Pod phase <code>Pending</code> you could, log the <em>phase</em> in your controller when watching a Pod? Or you can mock the pod - so that it is in phase Pending?</p>
<p>I don't know <em>kubernetes-python-client</em> but <code>client-go</code> does have <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/core/v1/fake" rel="nofollow noreferrer">Fake-clients</a> that can work with Pods, including <code>UpdateStatus</code>.</p>
<pre><code>func (c *FakePods) UpdateStatus(ctx context.Context, pod *corev1.Pod, opts v1.UpdateOptions) (*corev1.Pod, error)
</code></pre>
<p>Now, looking at the Python client, it does seem to lack this feature: <a href="https://github.com/kubernetes-client/python/issues/524" rel="nofollow noreferrer">Issue #524 fake client for unit testing</a></p>
