<p>I have tried to list pods based on labels</p>
<pre><code>    // Kubernetes client - package kubernetes
    clientset := kubernetes.NewForConfigOrDie(config)

    // create a temp list for storage 
    var podslice []string

    // Get pods -- package metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    pods, _ := clientset.CoreV1().Pods(&quot;&quot;).List(metav1.ListOptions{})
    for _, p := range pods.Items {
        fmt.Println(p.GetName())
    }
</code></pre>
<p>this is equivalent of</p>
<pre><code>kubectl get po 
</code></pre>
<p>is there a way to get in golang</p>
<pre><code>kubectl get po -l app=foo
</code></pre>
<p>thanks in advance</p>

Pradeep Padmanaban C
<p>You may just be able to set using the <code>ListOptions</code> parameter.</p>
<pre><code>listOptions := metav1.ListOptions{
        LabelSelector: &quot;app=foo&quot;,
    }
pods, _ := clientset.CoreV1().Pods(&quot;&quot;).List(listOptions)
</code></pre>
<p>If you have multiple labels, you may be able to perform this via the <code>labels</code> library, like below untested code:</p>
<pre><code>import &quot;k8s.io/apimachinery/pkg/labels&quot;

labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{&quot;app&quot;: &quot;foo&quot;}}
listOptions := metav1.ListOptions{
    LabelSelector: labels.Set(labelSelector.MatchLabels).String(),
}
pods, _ := clientset.CoreV1().Pods(&quot;&quot;).List(listOptions)
</code></pre>
