<p>I need to get all resources based on <strong>label</strong>, I used the following code <strong>which works</strong>, However, it takes <strong>too much time</strong> ( ~20sec) to get the response, even which I restrict it to only one namespace (vrf), any idea what im doing wrong here?</p>
<pre><code>resource.NewBuilder(flags).
   Unstructured().
   ResourceTypes(res...).
   NamespaceParam(&quot;vrf&quot;).AllNamespaces(false).
   LabelSelectorParam(&quot;a=b&quot;).SelectAllParam(selector == &quot;&quot;).
   Flatten().
   Latest().Do().Object()
</code></pre>
<p><a href="https://pkg.go.dev/k8s.io/cli-runtime@v0.26.1/pkg/resource#Builder" rel="nofollow noreferrer">https://pkg.go.dev/k8s.io/cli-runtime@v0.26.1/pkg/resource#Builder</a></p>
<p>As I already using <code>label</code> and <code>ns</code>, not sure what should else I do in this case.</p>
<p>Ive checked the cluster connection and it seems that everything is ok, running regular <code>kubectl</code> are getting <strong>very fast</strong> response, just this query took much time.</p>

<p>The search may be heavy due to the sheer size of the resources the query has to search into. Have you looked into this possibility and further reduce the size using one more label or filter on top of current.</p>
<p>Also check the performance of you Kubernetes api server when the operation is being performed and optimize it.</p>
