<p>I'm using the native client-go API in Go to get the list of Pods managed by a Deployment type controller under a given namespace (&quot;default&quot;), but the returned list is not containing the list of Pods</p>
<pre class="lang-golang prettyprint-override"><code>labelSelector := labels.Set(obj.Spec.Selector.MatchLabels)
</code></pre>
<p>where <code>obj</code> is of type <code>*appsv1.Deployment</code> from <a href="https://pkg.go.dev/k8s.io/api/apps/v1?tab=doc#Deployment" rel="nofollow noreferrer">https://pkg.go.dev/k8s.io/api/apps/v1?tab=doc#Deployment</a></p>
<pre class="lang-golang prettyprint-override"><code>podsList, err := getPodList(string(labelSelector.AsSelector().String()), kubeClient, res.Namespace)
</code></pre>
<p>with the function definition being</p>
<pre class="lang-golang prettyprint-override"><code>func getPodList( labelSelector string, client kubernetes.Interface, ns string ) (*corev1.PodList, error) {     
     options := metav1.ListOptions{
         LabelSelector: labelSelector,
     }

     podList, err := client.CoreV1().Pods(ns).List(options)
     return podList, err
 }
</code></pre>
<p>The type returned - <a href="https://pkg.go.dev/k8s.io/api/core/v1?tab=doc#PodList" rel="nofollow noreferrer">https://pkg.go.dev/k8s.io/api/core/v1?tab=doc#PodList</a> should contain the <code>Items []Pod</code> slice which is not available in my returned information.</p>
<p>Using the following packages in the Go code</p>
<pre class="lang-golang prettyprint-override"><code>appsv1 &quot;k8s.io/api/apps/v1&quot;    
metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
&quot;k8s.io/apimachinery/pkg/labels&quot;
&quot;k8s.io/client-go/kubernetes&quot;
</code></pre>

Inian
<p>It seems I got it working all along, but just handled the return type of <code>CoreV1().Pods(ns).List(options)</code> incorrectly. It was returning a pointer to a slice of <code>PodList</code> - <a href="https://pkg.go.dev/k8s.io/api/core/v1?tab=doc#PodList" rel="nofollow noreferrer">https://pkg.go.dev/k8s.io/api/core/v1?tab=doc#PodList</a></p>
<p>Here is the minimal code, which I made work which could be useful for posterity</p>
<pre><code>package main

import (
        &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;os&quot;
        &quot;path/filepath&quot;
)

func main() {

        kubeconfig := filepath.Join(
                os.Getenv(&quot;HOME&quot;), &quot;.kube&quot;, &quot;config&quot;,
        )

        // Initialize kubernetes-client
        cfg, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, kubeconfig)
        if err != nil {
                fmt.Printf(&quot;Error building kubeconfig: %v\n&quot;, err)
                os.Exit(1)
        }

        // create new client with the given config
        // https://pkg.go.dev/k8s.io/client-go/kubernetes?tab=doc#NewForConfig
        kubeClient, err := kubernetes.NewForConfig(cfg)
        if err != nil {
                fmt.Printf(&quot;Error building kubernetes clientset: %v\n&quot;, err)
                os.Exit(2)
        }

        // use the app's label selector name. Remember this should match with 
        // the deployment selector's matchLabels. Replace &lt;APPNAME&gt; with the 
        // name of your choice
        options := metav1.ListOptions{
                LabelSelector: &quot;app=&lt;APPNAME&gt;&quot;,
        }

        // get the pod list
        // https://pkg.go.dev/k8s.io/client-go@v11.0.0+incompatible/kubernetes/typed/core/v1?tab=doc#PodInterface
        podList, _ := kubeClient.CoreV1().Pods(&quot;default&quot;).List(options)

        // List() returns a pointer to slice, derefernce it, before iterating
        for _, podInfo := range (*podList).Items {
                fmt.Printf(&quot;pods-name=%v\n&quot;, podInfo.Name)
                fmt.Printf(&quot;pods-status=%v\n&quot;, podInfo.Status.Phase)
                fmt.Printf(&quot;pods-condition=%v\n&quot;, podInfo.Status.Conditions)
        }
}
</code></pre>
