We want to get all the pods in the cluster so we are using something like following:
pods, err := client.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{})
This code will receive all the pods in the cluster.
My question is: If there is a code or lib which will bring all the pods with the owner reference
.
i.e. if pods owns by deployment
or statfulset
etc you will get all the hierarchy ,the trick
here is if I need to get additional level up like some recursion, for example statefulset
which owns by controller which have custom kind
CodePudding user response:
As @CoolNetworking suggested,there is a single lib or code that will get you all the pods with their owner reference, but you can use k8s API to retrieve the owner references for each pod. You can then use the k8s API to retrieve the owner object for each owner reference. This will allow you to create a hierarchical structure of all the pods in the cluster.
The Kubernetes API is a resource-based (RESTful) programmatic interface provided via HTTP. It supports retrieving, creating, updating, and deleting primary resources via the standard HTTP verbs (POST, PUT, PATCH, DELETE, GET).
Most Kubernetes API resource types are objects: they represent a concrete instance of a concept on the cluster, like a pod or namespace.
Refer the document on kubernetes API for more information