<p>I created some Go code to list all resources in all namespaces.</p>
<pre><code>package main

import (
    &quot;context&quot;
    &quot;fmt&quot;

    metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    &quot;k8s.io/apimachinery/pkg/apis/meta/v1/unstructured&quot;
    &quot;k8s.io/apimachinery/pkg/runtime/schema&quot;
    &quot;k8s.io/client-go/dynamic&quot;
    &quot;k8s.io/client-go/kubernetes&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
)

func main() {
    loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
    configOverrides := &amp;clientcmd.ConfigOverrides{}
    kubeconfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)

    config, err := kubeconfig.ClientConfig()
    if err != nil {
        panic(err.Error())
    }

    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }

    dynClient, err := dynamic.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }

    discoveryClient := clientset.Discovery()

    // Get the list of all API resources available
    serverResources, err := discoveryClient.ServerPreferredResources()
    if err != nil {
        panic(err.Error())
    }

    for _, group := range serverResources {
        for _, resource := range group.APIResources {
            // Skip subresources like pod/logs, pod/status
            if containsSlash(resource.Name) {
                continue
            }
            gvr := schema.GroupVersionResource{
                Group:    group.GroupVersion,
                Version:  resource.Version,
                Resource: resource.Name,
            }
            if gvr.Group == &quot;v1&quot; {
                gvr.Version = gvr.Group
                gvr.Group = &quot;&quot;
            }
            // if resource.Name != &quot;machines&quot; {
            //  continue
            // }
            var list *unstructured.UnstructuredList
            if resource.Namespaced {
                list, err = dynClient.Resource(gvr).List(context.TODO(), metav1.ListOptions{})

                if err != nil {
                    fmt.Printf(&quot;..Error listing %s: %v. group %q version %q resource %q\n&quot;, resource.Name, err,
                        gvr.Group, gvr.Version, gvr.Resource)
                    continue
                }
                printResources(list, resource.Name, gvr)

            } else {
                list, err = dynClient.Resource(gvr).List(context.TODO(), metav1.ListOptions{})
                if err != nil {
                    fmt.Printf(&quot;..Error listing %s: %v\n&quot;, resource.Name, err)
                    continue
                }
                printResources(list, resource.Name, gvr)
            }
        }
    }
}

func containsSlash(s string) bool {
    return len(s) &gt; 0 &amp;&amp; s[0] == '/'
}

func printResources(list *unstructured.UnstructuredList, resourceName string, gvr schema.GroupVersionResource) {
    fmt.Printf(&quot;Found %d resources of type %s. group %q version %q resource %q\n&quot;, len(list.Items), resourceName, gvr.Group, gvr.Version, gvr.Resource)
}

</code></pre>
<p>Unfortunately it takes more than 20 seconds in my small development cluster.</p>
<p>I guess I am doing something wrong.</p>
<p>Is there a way to reduce the number of API calls (or other ways to make it faster)?</p>

guettli
<p>you can use goroutines to asynchronsly call the apis and print them (not in order)  :</p>
<pre><code>var wg sync.WaitGroup
  for _, group := range serverResources {
      wg.Add(1)
   // goroutine for executing the seconde loop for
     go func() {
        defer wg.Done()
     for _, resource := range group.APIResources {
        // the code  seconde for here....
       }
       }()
}
wg.Wait()
</code></pre>
