<p>Using the kubernetes go-client (<code>k8s.io/client-go/kubernetes</code>), I know how to get <code>pod.Status</code> and I find the <code>pod.Status.Phase</code> useful (<a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase" rel="noreferrer">docs</a>). For example, I can output the Pod Status Phase of all Pods using this:</p>

<pre class="lang-golang prettyprint-override"><code>    ...
    api := clientset.CoreV1()
    pods, err := api.Pods("").List(metav1.ListOptions{})
    for i, pod := range pods.Items {
        podstatusPhase := string(pod.Status.Phase)
        podCreationTime := pod.GetCreationTimestamp()
        age := time.Since(podCreationTime.Time).Round(time.Second)

        podInfo := fmt.Sprintf("[%d] Pod: %s, Phase: %s , Created: %s, Age: %s", i, pod.GetName(), podstatusPhase, podCreationTime, age.String())
        fmt.Println(podInfo)
    }
</code></pre>

<p>However, the <code>phase</code> is a little simplistic in that it only ever shows 5 values (<code>Pending</code>, <code>Running</code>, <code>Succeeded</code>, <code>Failed</code>, <code>Unknown</code>). I'd rather get the same info that <code>kubectl get pods</code> gives in the <em>Status</em> column, for example: </p>

<pre><code>$ kubectl get pods

NAME                                        READY   STATUS              RESTARTS   AGE     IP             NODE                           NOMINATED NODE   READINESS GATES
moby-dick-cron-scheduler-1564578660-bg4sb   0/2     ContainerCreating   0          178m    &lt;none&gt;         ip-10-30-13-151.ec2.internal   &lt;none&gt;           &lt;none&gt;
notifications-missed-calls-1564564740-js762 0/2     Init:0/1            0          6h49m   &lt;none&gt;         ip-10-30-13-6.ec2.internal     &lt;none&gt;           &lt;none&gt;
antivirus-scanner-cron-1564576740-sd6hh     0/2     Completed           0          3h30m   10.30.13.169   ip-10-30-13-151.ec2.internal   &lt;none&gt;           &lt;none&gt;
</code></pre>

<p>In particular, I'm interested in <code>Init:0/1</code> and <code>PodInitializing</code> statuses. The Pods in these statuses just show as "Pending" when using <code>pod.Status.Phase</code>.</p>

<ul>
<li><code>Init:0/1</code> means the Pod has 1 Init containers and 0 have completed successfully so far. <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="noreferrer">init containers</a> run before app containers are started.</li>
<li><code>PodInitializing</code> means the Pod has already finished executing Init Containers.</li>
</ul>

<p>Is there a way to get a Status such as <code>Init:0/1</code> using <code>k8s.io/client-go/kubernetes</code>? or is there no short-cut, and I'd need to re-calculate it the same way kubectl does? I guess it uses Pod Status <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions" rel="noreferrer">Conditions</a> and <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-and-container-status" rel="noreferrer">container statuses</a> to build the info. If I need to re-calculate it, maybe I can use <a href="https://github.com/kubernetes/kubernetes/tree/master/pkg/kubectl" rel="noreferrer">the kubectl sourcecode</a>? Does anyone know where I can find the relevant bit? (I have very limited golang experience)</p>

Tom
<p>The short answer is typically you don't have to calculate the 'Status' on the client since it's calculated at the server level.</p>
<p>To illustrate:</p>
<p>The standard way that you are trying to print with <code>kubectl get pods</code>, in the Kubernetes code base is called <a href="https://github.com/kubernetes/kubernetes/blob/20b01afecbba85c53b58711b07049e8c1b764b2d/staging/src/k8s.io/kubectl/pkg/cmd/get/humanreadable_flags.go" rel="nofollow noreferrer">Human Readable</a>. This method uses <a href="https://github.com/kubernetes/kubernetes/blob/20b01afecbba85c53b58711b07049e8c1b764b2d/staging/src/k8s.io/kubectl/pkg/cmd/get/get.go#L273" rel="nofollow noreferrer">ServerPrint</a>, which defaults to the <a href="https://github.com/kubernetes/kubernetes/blob/20b01afecbba85c53b58711b07049e8c1b764b2d/staging/src/k8s.io/kubectl/pkg/cmd/get/get.go#L274" rel="nofollow noreferrer">Kubernetes TablePrinter</a>. The <a href="https://github.com/kubernetes/kubernetes/blob/4477bf02f211093b32cf58f64aa42aff77daea61/staging/src/k8s.io/kubectl/pkg/cmd/get/table_printer.go#L34" rel="nofollow noreferrer">TablePrinter type is defined here</a>.</p>
<p>As you can see the <code>PrintObj</code> function for the TablePrinter gets delegated <a href="https://github.com/kubernetes/kubernetes/blob/20b01afecbba85c53b58711b07049e8c1b764b2d/staging/src/k8s.io/kubectl/pkg/cmd/get/table_printer.go#L41" rel="nofollow noreferrer">here</a>. It delegates to the appropriate <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/printers/interface.go#L35" rel="nofollow noreferrer">Kubernetes resource PrintObj</a>.  Also, that delegation comes together with the configured <a href="https://github.com/kubernetes/kubernetes/blob/20b01afecbba85c53b58711b07049e8c1b764b2d/staging/src/k8s.io/kubectl/pkg/cmd/get/get.go#L236" rel="nofollow noreferrer">HumanPrintFlags</a> and saving the original <a href="https://github.com/kubernetes/kubernetes/blob/20b01afecbba85c53b58711b07049e8c1b764b2d/staging/src/k8s.io/kubectl/pkg/cmd/get/get.go#L258" rel="nofollow noreferrer">printer</a>.</p>
<p>Also, you see that in <a href="https://github.com/kubernetes/kubernetes/blob/4477bf02f211093b32cf58f64aa42aff77daea61/staging/src/k8s.io/kubectl/pkg/cmd/get/humanreadable_flags.go" rel="nofollow noreferrer">humanreadable_glags.go</a> it's including <code>k8s.io/cli-runtime/pkg/printers</code>, and you see that it's instantiating a <a href="https://github.com/kubernetes/kubernetes/blob/9815cda4bf18ea1628a043fc3b78f99183bd1ee0/staging/src/k8s.io/kubectl/pkg/cmd/get/humanreadable_flags.go#L88" rel="nofollow noreferrer">printers.NewTablePrinter</a> which is defined in <code>k8s.io/kubernetes/pkg/printers</code>.</p>
<p>The actual function to print that gets called is this <a href="https://github.com/kubernetes/kubernetes/blob/4477bf02f211093b32cf58f64aa42aff77daea61/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter.go#L94" rel="nofollow noreferrer">PrintObj</a> and you can see that it handles 3 cases since in some cases the server returns a table and some not (looks like &lt; 1.16 cases).</p>
<p>You also see that in the above case none of the code in <a href="https://github.com/kubernetes/kubernetes/tree/4477bf02f211093b32cf58f64aa42aff77daea61/pkg/printers/internalversion" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/tree/4477bf02f211093b32cf58f64aa42aff77daea61/pkg/printers/internalversion</a> is used, so that <a href="https://github.com/kubernetes/kubernetes/blob/4477bf02f211093b32cf58f64aa42aff77daea61/pkg/printers/internalversion/printers.go#L444" rel="nofollow noreferrer">calculation</a> happens behind the kube-apiserver side.</p>
<p>Keep in mind that this is the Human Readable printer and there other types of printers defined here (depending on the options): <a href="https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/cli-runtime/pkg/printers" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/cli-runtime/pkg/printers</a></p>
