<p>When I get the kubernetes resources from api with client-go, but I can't found the apiversion and kind in the response, the apiversion and kind is empty. How can I get the apiversion and kind of the resource?</p>
<p>below is my code:</p>
<pre><code>package main

import (
    &quot;flag&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
    &quot;log&quot;
    &quot;k8s.io/client-go/kubernetes&quot;
    metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    &quot;fmt&quot;
)

var clientset *kubernetes.Clientset

func main()  {
    k8sconfig := flag.String(&quot;k8sconfig&quot;,&quot;./k8sconfig&quot;,&quot;kubernetes config file path&quot;)
    flag.Parse()
    config , err := clientcmd.BuildConfigFromFlags(&quot;&quot;,*k8sconfig)
    if err != nil {
        log.Println(err)
    }
    clientset , err = kubernetes.NewForConfig(config)
    if err != nil {
        log.Fatalln(err)
    } else {
        fmt.Println(&quot;connect k8s success&quot;)
    }
    pods,err := clientset.CoreV1().Pods(&quot;&quot;).List(metav1.ListOptions{})
    if err != nil {
        log.Println(err.Error())
    }
    for _, pod := range pods.Items{
        fmt.Println(&quot;apiversion: &quot;, pod.APIVersion, &quot;kind: &quot;, pod.Kind)
    }   
}

The output:
apiversion:   kind:  
apiversion:   kind:  
apiversion:   kind:  
apiversion:   kind:  
apiversion:   kind:  
apiversion:   kind:  
apiversion:   kind:  
apiversion:   kind:
......
......
</code></pre>

yzhengwei
<p>I think the issue is that you are getting the list of pods using the <code>List()</code> API so it is not a pod as you expect and doesn't have a <code>Kind</code> field.</p>
<p>You need to iterate over the list of pods to access individual pods:</p>
<pre><code>for _, pod := range pods.Items {
    fmt.Printf(&quot;%s %s\n&quot;, pod.GetName(), pod.GetCreationTimestamp())
}
</code></pre>
<p>The <code>Kind</code> field is present as part of <a href="https://pkg.go.dev/k8s.io/api/core/v1#Pod" rel="nofollow noreferrer">Pod's</a> <a href="https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#TypeMeta" rel="nofollow noreferrer"><code>Metadata</code></a> and can be accessed using <code>pod.ObjectMeta.Kind</code>.</p>
