How to filter CRDs based on a status field

1/27/2020

I have several Custom Resource Definition (CRD) objects issued on k8s cluster and now I want to filter them based on their status field. When I do:

kubectl -n <namespace> describe <crd>

I can see that in the definition there is a status section:

Status:
  Job Status: Completed
  Node Name: ***
  Status History:
   <log_entries>
  Status Time: ***

I want to utilise the presence of such a state record in the CRD description by retrieving objects depending on their state and changing it afterwards. Can somebody please provide a sequence of CLI commands to achieve the goal, and potentially a simple example script using the Python client?

There are also labels on the CRDs so I can filter the ones I want by doing something like:

kubectl -n <namespace> get <crd> -l jobStatus=Completed

Obviously, to ask such a question I have some concepts which are not clear enough so feel free to educate me.

-- Konstantin Grigorov
bash
kubernetes
kubernetes-custom-resources
python

0 Answers