<p>We want to get all the pods in the cluster so we are using something like following:</p>
<pre><code>pods, err := client.CoreV1().Pods(&quot;&quot;).List(context.Background(), metav1.ListOptions{})
</code></pre>
<p>This code will receive all the pods in the cluster.</p>
<p>My question is: If there is a code or lib which will bring all the pods with the <code>owner reference</code> .
i.e. if pods owns by <code>deployment</code> or <code>statfulset</code> etc you will get all the hierarchy ,the <code>trick</code> here is if I need to get additional level up like some recursion, for example <code>statefulset</code> which owns by controller which have custom kind</p>

<p>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.</p>
<p>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).</p>
<p>Most Kubernetes API resource types are objects: they represent a concrete instance of a concept on the cluster, like a pod or namespace.</p>
<p>Refer the document on <a href="https://kubernetes.io/docs/reference/using-api/api-concepts/#retrieving-large-results-sets-in-chunks" rel="nofollow noreferrer">kubernetes API</a> for more information</p>
