<p>I need to grab some pod information which will be used for some unit tests which will be run in-cluster. I need all the information which kubectl describe po  gives but from an in cluster api call. </p>

<p>I have some working code which makes an api call to apis/metrics.k8s.io/v1beta1/pods, and have installed the metrics-server on minikube for testing which is all working and gives me output like this: </p>

<pre><code>Namespace: kube-system
Pod name: heapster-rgnlj
SelfLink: /apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/heapster-rgnlj
CreationTimestamp: 2019-09-10 12:27:13 +0000 UTC
Window: 30s
Timestamp: 2019-09-10 12:26:23 +0000 UTC
Name: heapster
Cpu usage: 82166n
Mem usage: 19420Ki 
</code></pre>

<pre><code>...
func getMetrics(clientset *kubernetes.Clientset, pods *PodMetricsList) error {
    data, err := clientset.RESTClient().Get().AbsPath("apis/metrics.k8s.io/v1beta1/pods").DoRaw()
    if err != nil {
        return err
    }
    err = json.Unmarshal(data, &amp;pods)
    return err
}

func main() {

    config, err := rest.InClusterConfig()
    if err != nil {
        fmt.Println(err)
    }
    // creates the clientset
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        fmt.Println(err)
    }
    var pods PodMetricsList
    err = getMetrics(clientset, &amp;pods)
    if err != nil {
        fmt.Println(err)
    }

    for _, m := range pods.Items {

        fmt.Print("Namespace: ", m.Metadata.Namespace, "\n", "Pod name: ", m.Metadata.Name, "\n", )
        fmt.Print("SelfLink: ", m.Metadata.SelfLink, "\n", "CreationTimestamp: ", m.Metadata.CreationTimestamp, "\n", )
        fmt.Print("Window: ", m.Window, "\n", "Timestamp: ", m.Timestamp, "\n", )

        for _, c := range m.Containers {
            fmt.Println("Name:", c.Name)
            fmt.Println("Cpu usage:", c.Usage.CPU)
            fmt.Println("Mem usage:", c.Usage.Memory, "\n")
...
</code></pre>

<p>As I say, what i really need is what you'd get with a 'describe pods' type call. Having looked through the kubernetes source this NodeDescriber looks like the right type of function, but I'm slightly at a loss as to how to integrate / implement it to get the desired results. </p>

<p>kubernetes/pkg/printers/internalversion/describe.go</p>

<p>Line 2451 in 4f2d7b9</p>

<p>func (d *NodeDescriber) Describe(namespace, name string, describerSettings...etc)</p>

<p>I'm new to Go and not particularly familiar with kubernetes.
Any pointers as to how to go about it would be greatly appreciated.</p>

<p>Looking at the <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/versioned/describe.go#L668" rel="nofollow noreferrer">describePod</a> and <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L693" rel="nofollow noreferrer">Describe</a> funcs from staging/src/k8s.io/kubectl/pkg/describe/versioned/describe.go should give you a better picture of how to do this. And since <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L693" rel="nofollow noreferrer">Describe</a> and <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/versioned/describe.go#L628" rel="nofollow noreferrer">PodDescriber</a> are public, you can reuse these for your use case.</p>
<p>You could couple this with a <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/core/v1#CoreV1Client" rel="nofollow noreferrer">CoreV1Client</a> which has a <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/core/v1#CoreV1Client.Pods" rel="nofollow noreferrer">Pods</a> func, that returns a <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/core/v1#PodInterface" rel="nofollow noreferrer">PodInterface</a> that has a <a href="https://godoc.org/k8s.io/api/core/v1#PodList" rel="nofollow noreferrer">List</a> func which would return a list of <a href="https://godoc.org/k8s.io/api/core/v1#Pod" rel="nofollow noreferrer">Pod</a> objects for the given namespace.</p>
<p>Those pod objects will provide the Name needed for the <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L693" rel="nofollow noreferrer">Describe</a> func, the Namespace is already known, and the <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/interface.go#L49" rel="nofollow noreferrer">describe.DescriberSettings</a> is just a struct type that you could inline to enable showing events in the <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L693" rel="nofollow noreferrer">Describe</a> output.</p>
<p>Using the <a href="https://godoc.org/k8s.io/api/core/v1#PodList" rel="nofollow noreferrer">List</a> func will only list the pods that one time. If you're interested in having this list be updated regularly, you might want to look at the Reflector and Informer patterns; both of which are largely implemented in the <a href="https://godoc.org/k8s.io/client-go/tools/cache" rel="nofollow noreferrer">tools/cache</a> package, and the docs briefly explain this concept in the <a href="https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes" rel="nofollow noreferrer">Efficient detection of changes</a> section.</p>
<p>Hope this helps.</p>
