5

I'm using the client-go API in Go to access the list of Pods under a given controller (Deployment). While querying the list of pods belonging to it using the selector labels, you get an array of PodConditions - https://pkg.go.dev/k8s.io/api/core/v1?tab=doc#PodCondition.

This is well aligned with the official documentation of pod conditions - https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions. But the documentation isn't clear how to access this array of entries. Is it sorted by most recent entry first? For e.g. if I want to access only the most recent status of the Pod, how should it be done? From one of the trials I did in my local cluster, I got updates (Pod Conditions array) for one of the controller's Pods as below

{Initialized True 0001-01-01 00:00:00 +0000 UTC 2020-07-29 08:01:15 +0000 UTC  } 
{Ready True 0001-01-01 00:00:00 +0000 UTC 2020-07-29 08:01:22 +0000 UTC  } 
{ContainersReady True 0001-01-01 00:00:00 +0000 UTC 2020-07-29 08:01:22 +0000 UTC  } 
{PodScheduled True 0001-01-01 00:00:00 +0000 UTC 2020-07-29 08:01:15 +0000 UTC  }

As you can see that the given Pod has transitioned from ContainersReady to Ready just about at the same time 08:01:22 +0000 UTC. But neither of them are in the first or last index.

So TLDR, the question is how to infer the latest Pod condition type and status, from this array of values?

Inian
  • 80,270
  • 14
  • 142
  • 161

1 Answers1

2

The Pod didn't transition from ContainersReady to Ready, the ConditionStatus of those PodConditionTypes change from False to True.
The PodCondition array holds the details about each ConditionType, but they are not correlated, and you shouldn't rely on the order of the PodCondition updates.
Instead, you can monitor the details of each PodCondition that interests you.

If you just want to know if the pod is running or not, take a look at PodPhase. It's also part of the PodStatus struct.

hilsenrat
  • 1,390
  • 2
  • 8
  • 21