<p>Is there a way to determine programatically if a pod is in crashloopbackoff?
I tried the following</p>
<pre><code>pods,err :=  client.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil { 
    return err
}
for _, item := range pods.Items {
   log.Printf(&quot;found pod %v with state %v  reason %v and phase %v that started at %v&quot;,
                item.Name, item.Status.Message, item.Status.Reason, item.Status.Phase, item.CreationTimestamp.Time)
}
</code></pre>
<p>However this just prints blank for state and reason, tough it prints the phase.</p>

NonoPa Naka
<p>To clarify I am posting a community wiki answer.</p>
<blockquote>
<p>It's hiding in  <a href="https://pkg.go.dev/k8s.io/api/core/v1#ContainerStateWaiting" rel="nofollow noreferrer"><code>ContainerStateWaiting.Reason</code></a>:</p>
</blockquote>
<pre><code>kubectl get po -o jsonpath='{.items[*].status.containerStatuses[*].state.waiting.reason}'
</code></pre>
<blockquote>
<p>although be aware that it only  <em>intermittently</em>  shows up there, since it is an intermittent state of the container; perhaps a more programmatic approach is to examine the  <code>restartCount</code>  and the  <code>Error</code>  state</p>
</blockquote>
<p>See also <a href="https://github.com/kubernetes-client/go/blob/master/kubernetes/docs/V1PodStatus.md" rel="nofollow noreferrer">this repository</a>.</p>
