Get pod list for a node with specified condition (not state)?

9/11/2018

Is there is a way to get pod list for the specified namespace, application, node name and pod condition? Applying lablelSelector to the query string it is possible to specify the application name, using fieldSelector I can select node name (spec.nodeName==node) and even phase (status.phase==Running). But status.phase will return all pods that are in specified phase including those that are actually in CrashLoopBackOff or located on nodes that were lost.

After analyzing the respond JSON I found, that there is a 'status' section that actually has 'status.phase' field mentioned above and section called "conditions" that stores an array/list of records of several "types" describing current condition of corresponding parameters. Among them there is a subsection (dictionary on Python terms) that has "type" : "Ready" and "status" : <value> that is what I need.

Full section of respond looks like this:

   "status": {
    "phase": "Running",
    "conditions": [
      {
        "type": "Initialized",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2018-09-11T15:49:09Z"
      },
      {
        "type": "Ready",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2018-09-11T19:05:01Z"
      },
      {
        "type": "ContainersReady",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": null
      },
      {
        "type": "PodScheduled",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2018-09-11T15:49:09Z"
      }
    ]

It is obvious, that labelSelector and fieldSelector work using corresponding sections/fields of respond JSON. But I was not able to find the way to apply something like fieldSelector for "conditions" subsection. Like fieldSelector=conditions.type.Ready==True.

Sure, I can parse the respond in Python and select only pods heaving condition I need, but that does not look right to me.

Anybody have an idea how to specify pod condition in the API request?

Currently I'm using: /api/v1/namespaces/<namespace>/pods?labelSeletor=app%3D<appname>&fieldSelector=status.phase%3D%3DRunning,spec.nodeName%3D%3D<nodename>.

-- e-pirate
kubernetes

0 Answers