<p>I want to list my deployments based on a key value pair found in the <code>.spec.selector.matchLabels</code> field.</p>
<p>Doing so using the plain <code>labels</code> is easy, but I could not find a way to match / fetch the deployment that satisfies the condition that a certain <code>key=value</code> is present in the following section</p>
<pre><code>spec:
  [...]
  selector:
    matchLabels:
      app: myapp
      process: web
      release: myrelease
</code></pre>
<p>Does not seem this can be done using the <a href="https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ListOptions" rel="noreferrer"><code>ListOptions</code></a></p>

<p>It is not supported:</p>
<ul>
<li><a href="https://github.com/kubernetes/client-go/issues/713#issuecomment-557540936" rel="nofollow noreferrer">https://github.com/kubernetes/client-go/issues/713#issuecomment-557540936</a></li>
<li>and <a href="https://github.com/kubernetes/kubernetes/issues/53459" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/53459</a></li>
</ul>
<p>You have to filter on the client side:</p>
<pre><code>    depl, err := clientset.AppsV1().Deployments(&quot;some_namespace&quot;).List(context.Background(), metav1.ListOptions{})
    if err != nil {
        panic(err.Error())
    }
    for _, item := range depl.Items {
        if item.Spec.Selector.MatchLabels[&quot;app&quot;] == &quot;myapp&quot; {
            fmt.Println(&quot;found it&quot;)
        }
    }
</code></pre>
