<p>We are using client-go to talk to our kubernetes cluster (the api version: batchv1/appv1/corev1), and we mainly use three types of resources: Job, Deployment and Service.</p>
<p>My question is how do we judge when A Job or deployment is ready and is of running status?</p>
<p>For A Job, we found that when batchV1.Spec.Active &gt; 0, the pod controlled by this job may be in either of pending status or running status. So to check if one kubernetes Job's pods are all in running status, do we have to enumerate every pods of the Kubernetes Job and check they are all in running status, then the Job is ready and running?  Is there simple way to do that?</p>
<p>And how about the kubernetes Deployment and Service? Is there simple way to check deployment is ready?</p>

Wallace
<p>To check the deployment status you need to check the pod status  created by this deployment.
example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: myapp
  name: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - image: myimage
        name: myapp
        livenessProbe:
          # your desired liveness check
</code></pre>
<p>You can get the desired PodTemplate from deployments using client-go</p>
<p>For example:</p>
<pre class="lang-golang prettyprint-override"><code>clientset := kubernetes.NewForConfigOrDie(config)
deploymentClient := clientset.AppsV1().Deployments(&quot;mynamespace&quot;)
deployment, err := deploymentClient.Get(&quot;myapp&quot;, metav1.GetOptions{})

for _, container := range deployment.Spec.Template.Spec.Containers {
    container.LivenessProbe // add your logic
}
</code></pre>
<p><strong>Note:</strong> The Deployment only contains the desired PodTemplate, so to look at any status, you have to look at the created Pods.
Pods</p>
<p>You can list the Pods created from the deployment by using the same labels as in the selector of the Deployment.</p>
<p><strong>Example list of Pods:</strong></p>
<pre class="lang-golang prettyprint-override"><code>pods, err := clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{
    LabelSelector: &quot;app=myapp&quot;,
})

// check the status for the pods - to see Probe status
for _, pod := range pods.Items {
    pod.Status.Conditions // use your custom logic here

    for _, container := range pod.Status.ContainerStatuses {
        container.RestartCount // use this number in your logic
    }
}
</code></pre>
<p>The Status part of a Pod contain conditions: with some Probe-information and containerStatuses: with restartCount:, also illustrated in the Go example above. Use your custom logic to use this information.</p>
<p>A Pod is restarted whenever the livenessProbe fails.</p>
<p>Example of a Pod Status:</p>
<pre class="lang-yaml prettyprint-override"><code>status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: &quot;2020-09-15T07:17:25Z&quot;
    status: &quot;True&quot;
    type: Initialized
  containerStatuses:
  - containerID: docker://25b28170c8cec18ca3af0e9c792620a3edaf36aed02849d08c56b78610dec31b
    image: myimage
    imageID: docker-pullable://myimage@sha256:a432251b2674d24858f72b1392033e0d7a79786425555714d8e9a656505fa08c
    name: myapp
    restartCount: 0
</code></pre>
<p>I hope that can help you to resolve your issue .</p>
