<p>For some troubleshooting, I need to manually change the status of a running job from <code>active</code> to <code>successful</code> to make it completed. The job itself is an infinite loop that does not finish. The option to delete the job cannot be used because it puts the job in a failed state.</p>
<p>Update: The job actually does not fail, instead it gets stuck, and therefore I delete it which makes it go to the failed state. Also, it is not possible to change the code of the job (it is not a bash script).</p>
<p>Thanks</p>

imriss
<p>It looks to me that you are more interested in treating the symptoms of your problem than the actual reasons behind them.</p>
<blockquote>
<p>This is for quick troubleshooting where I do not want to stop the rest
to add a bypass for the status of this job.</p>
</blockquote>
<p>I think that quicker way would be to actually make sure that your other jobs are less dependable on this one instead of trying to force Kubernetes to mark this Job/Pod as successful.</p>
<p>The closest thing I could get to your goal was to <code>curl</code> api-server directly with <code>kube-proxy</code>. But that solution only works if the job is failed first and unfortunately it does not work with running pods.</p>
<p>For this example I used job that exits with status 1:</p>
<pre class="lang-yaml prettyprint-override"><code>      containers:
        - name: job
          image: busybox
          args:
            - /bin/sh
            - -c
            - date; echo sleeping....; sleep 5s; exit 1;
</code></pre>
<p>Then run <code>kubectl-proxy</code>:</p>
<pre class="lang-java prettyprint-override"><code>➜  ~ kubectl proxy --port=8080 &amp;
[1] 18372
➜  ~ Starting to serve on 127.0.0.1:8080
</code></pre>
<p>And post the status to api-server:</p>
<pre class="lang-sh prettyprint-override"><code>curl localhost:8080/apis/batch/v1/namespaces/default/jobs/job3/status -XPATCH  -H &quot;Accept: application/json&quot; -H &quot;Content-Type: application/strategic-merge-patch+json&quot; -d '{&quot;status&quot;: {&quot;succeeded&quot;: 1}}'
</code></pre>
<pre class="lang-java prettyprint-override"><code>    ],
    &quot;startTime&quot;: &quot;2021-01-28T14:02:31Z&quot;,
    &quot;succeeded&quot;: 1,
    &quot;failed&quot;: 1
  }
}%
</code></pre>
<p>If then check the job status I can see that it was marked as completed.</p>
<pre class="lang-java prettyprint-override"><code>➜  ~ k get jobs
NAME   COMPLETIONS   DURATION   AGE
job3   1/1           45s        45s
</code></pre>
<p>PS. I tried this way to set up the status to successful/completed for either the job or pod but that was not possible. The status changed for  moment and then <code>controller-manager</code> reverted the status to running. Perhaps this small <code>window</code> with status changed might be what you want and it will allow your other jobs to move on. I'm merely assuming this since I don't the details.</p>
<p>For more reading how to access API in that way please have a look at the <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#using-kubectl-proxy" rel="nofollow noreferrer">using kubectl</a> docs.</p>
