<p>How can I programatically determine if a <code>job</code> has failed for good and will not retry any more? I've seen the following on failed jobs:</p>

<pre><code>status:
  conditions:
  - lastProbeTime: 2018-04-25T22:38:34Z
    lastTransitionTime: 2018-04-25T22:38:34Z
    message: Job has reach the specified backoff limit
    reason: BackoffLimitExceeded
    status: "True"
    type: Failed
</code></pre>

<p>However, the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#job-patterns" rel="noreferrer">documentation</a> doesn't explain why <code>conditions</code> is a list. Can there be multiple conditions? If so, which one do I rely on? Is it a guarantee that there will only be one with <code>status: "True"</code>?</p>

<p><code>JobConditions</code> is similar as <code>PodConditions</code>. You may read about <code>PodConditions</code> in <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/" rel="nofollow noreferrer">official docs</a>.</p>

<p>Anyway, To determine a successful pod, I follow another way. Let's look at it.</p>

<hr>

<p><strong>There are two fields in Job Spec.</strong> </p>

<p>One is <a href="https://github.com/kubernetes/api/blob/master/batch/v1/types.go#L78" rel="nofollow noreferrer"><code>spec.completion</code></a> (default value 1), which says,</p>

<blockquote>
  <p>Specifies the desired number of successfully finished pods the
  job should be run with.</p>
</blockquote>

<p>Another is <a href="https://github.com/kubernetes/api/blob/master/batch/v1/types.go#L88" rel="nofollow noreferrer"><code>spec.backoffLimit</code></a> (default value 6), which says,</p>

<blockquote>
  <p>Specifies the number of retries before marking this job failed.</p>
</blockquote>

<hr>

<p><strong>Now In JobStatus</strong></p>

<p>There are two fields in JobStatus too. <a href="https://github.com/kubernetes/api/blob/master/batch/v1/types.go#L146" rel="nofollow noreferrer"><code>Succeeded</code></a> and <a href="https://github.com/kubernetes/api/blob/master/batch/v1/types.go#L150" rel="nofollow noreferrer"><code>Failed</code></a>. <code>Succeeded</code> means how many times the Pod completed successfully and <code>Failed</code> denotes, The number of pods which reached phase Failed. </p>

<ul>
<li>Once the <code>Success</code> is equal or bigger than the <code>spec.completion</code>, the job will become <code>completed</code>.</li>
<li>Once the <code>Failed</code> is equal or bigger than the <code>spec.backOffLimit</code>, the job will become <code>failed</code>.</li>
</ul>

<p>So, the logic will be here,</p>

<pre><code>if job.Status.Succeeded &gt;= *job.Spec.Completion {
    return "completed"
} else if job.Status.Failed &gt;= *job.Spec.BackoffLimit {
    return "failed"
}
</code></pre>
