<p>With the following code, I'm able to fetch all the Pods running in a cluster. How can I find the Pod Controller (Deployment/DaemonSet) using the Kubernetes go-client library?</p>
<pre class="lang-golang prettyprint-override"><code>var kubeconfig *string
if home := homedir.HomeDir(); home != &quot;&quot; {
    kubeconfig = flag.String(&quot;kubeconfig&quot;, filepath.Join(home, &quot;.kube&quot;, &quot;config&quot;), &quot;(optional) absolute path to the kubeconfig file&quot;)
} else {
    kubeconfig = flag.String(&quot;kubeconfig&quot;, &quot;&quot;, &quot;absolute path to the kubeconfig file&quot;)
}
flag.Parse()
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, *kubeconfig)
if err != nil {
    panic(err.Error())
}

// create the kubeClient
kubeClient, err := kubernetes.NewForConfig(config)
metricsClient, err := metricsv.NewForConfig(config)

if err != nil {
    panic(err.Error())
}

pods, err := kubeClient.CoreV1().Pods(&quot;&quot;).List(context.TODO(), metav1.ListOptions{})

if err != nil {
    panic(err.Error())
}

for _, pod := range pods.Items {
    fmt.Println(pod.Name)
    // how can I get the Pod controller? (Deployment/DaemonSet)
    // e.g. fmt.Println(pod.Controller.Name)
}
</code></pre>

<p>By following @Jonas suggestion I was able to get Pod's manager. Here's a fully working sample:</p>
<pre class="lang-golang prettyprint-override"><code>package main

import (
    &quot;context&quot;
    &quot;flag&quot;
    &quot;fmt&quot;
    metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    &quot;k8s.io/client-go/kubernetes&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
    &quot;k8s.io/client-go/util/homedir&quot;
    &quot;path/filepath&quot;
)

func main() {
    var kubeconfig *string
    if home := homedir.HomeDir(); home != &quot;&quot; {
        kubeconfig = flag.String(&quot;kubeconfig&quot;, filepath.Join(home, &quot;.kube&quot;, &quot;config&quot;), &quot;(optional) absolute path to the kubeconfig file&quot;)
    } else {
        kubeconfig = flag.String(&quot;kubeconfig&quot;, &quot;&quot;, &quot;absolute path to the kubeconfig file&quot;)
    }
    flag.Parse()
    // use the current context in kubeconfig
    config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, *kubeconfig)
    if err != nil {
        panic(err.Error())
    }

    // create the kubeClient
    kubeClient, err := kubernetes.NewForConfig(config)

    if err != nil {
        panic(err.Error())
    }

    pods, err := kubeClient.CoreV1().Pods(&quot;&quot;).List(context.TODO(), metav1.ListOptions{})

    if err != nil {
        panic(err.Error())
    }

    for _, pod := range pods.Items {
        if len(pod.OwnerReferences) == 0 {
            fmt.Printf(&quot;Pod %s has no owner&quot;, pod.Name)
            continue
        }

        var ownerName, ownerKind string

        switch pod.OwnerReferences[0].Kind {
        case &quot;ReplicaSet&quot;:
            replica, repErr := kubeClient.AppsV1().ReplicaSets(pod.Namespace).Get(context.TODO(), pod.OwnerReferences[0].Name, metav1.GetOptions{})
            if repErr != nil {
                panic(repErr.Error())
            }

            ownerName = replica.OwnerReferences[0].Name
            ownerKind = &quot;Deployment&quot;
        case &quot;DaemonSet&quot;, &quot;StatefulSet&quot;:
            ownerName = pod.OwnerReferences[0].Name
            ownerKind = pod.OwnerReferences[0].Kind
        default:
            fmt.Printf(&quot;Could not find resource manager for type %s\n&quot;, pod.OwnerReferences[0].Kind)
            continue
        }

        fmt.Printf(&quot;POD %s is managed by %s %s\n&quot;, pod.Name, ownerName, ownerKind)
    }
}
</code></pre>
