<p>I'm currently trying to wrap my head around learning Go, some details of the kubernetes API I haven't used before and the kubernetes api framework for Go at the same time, and would appreciate your help in understanding the grammar of that framework and why people use it anyways.</p>

<p>Honestly I'm not sure why to use a framework in the first place if it contains the same information as the REST endpoint. Wouldn't it make more sense to just call the API directly via a <code>http</code> library?</p>

<p>And here's one example (taken from <a href="https://github.com/coreos/etcd-operator/blob/master/cmd/operator/main.go#L171" rel="noreferrer">some real code</a>):</p>

<pre><code>pod, err := kubecli.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
</code></pre>

<p>What I feel bothersome is that I have to <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/" rel="noreferrer">look up everything in the API docs</a> and then I additionally need to figure out that <code>/v1/</code> translates to <code>CoreV1()</code>. And I'm not even sure where I could look that up. Also the whole block <code>metav1.GetOptions{}</code> seems completely unnecessary, or which part of a HTTP request is represented by it?</p>

<p>I hope I could make clear what the confusion is and hope for your help in clearing it up.</p>

<h2>Edit:</h2>

<p>Here's also an example, generated from the new operator-framework which sadly doesn't make it much better:</p>

<pre><code> return &amp;v1.Pod{
    TypeMeta: metav1.TypeMeta{
            Kind:       "Pod",
            APIVersion: "v1",
    },
    ObjectMeta: metav1.ObjectMeta{
            Name:      "busy-box",
            Namespace: cr.Namespace,
            OwnerReferences: []metav1.OwnerReference{
                    *metav1.NewControllerRef(cr, schema.GroupVersionKind{
                            Group:   v1alpha1.SchemeGroupVersion.Group,
                            Version: v1alpha1.SchemeGroupVersion.Version,
                            Kind:    "Memcached",
                    }),
            },
            Labels: labels,
    },
    Spec: v1.PodSpec{
            Containers: []v1.Container{
                    {
                            Name:    "busybox",
                            Image:   "busybox",
                            Command: []string{"sleep", "3600"},
                    },
            },
    },
 }
</code></pre>

<p>The <a href="https://v1-9.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#pod-v1-core" rel="noreferrer">API docs</a> don't know anything about this <code>TypeMeta</code> object. And the second element is called <code>ObjectMeta:</code> instead of <code>metadata</code>. I mean, I'm not a magician. How should I know this.</p>

<p>I'm a bit late, but here is my 2 cents.</p>

<h1>Why to use <code>client-go</code> instead of <code>http</code> library</h1>

<p>There are serval pros with <code>client-go</code>.</p>

<ol>
<li><p>Kubernetes resource is defined as <strong>strongly-typed class</strong>, means less misspelled debugging and easy to refactor.</p></li>
<li><p>When we manipulate some resources, It <strong>authenticates with cluster automatically</strong> (<a href="https://github.com/kubernetes/client-go/tree/master/examples" rel="nofollow noreferrer" title="docs">doc</a>), what it only needs is a valid config. And we need not to know how exactly the authentication is done.</p></li>
<li><p>It has multiple versions <strong>compatible</strong> with different Kubernetes version. It make our code align with specify kubernetes version much easier, without knowing every detail of API changes.</p></li>
</ol>

<h1>How do I know which class and method should be called</h1>

<p>In <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/" rel="nofollow noreferrer">API Reference</a>, each resource has the latest Group and Version tag. 
For example, <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#pod-v1-core" rel="nofollow noreferrer">Pod</a> is group <code>core</code>, version <code>v1</code>, kind <code>Pod</code> in v1.10. </p>

<p><a href="https://godoc.org/k8s.io/client-go/kubernetes" rel="nofollow noreferrer">GoDoc</a> listed all properties and links to detail explanation for every class like <a href="https://godoc.org/k8s.io/api/core/v1#Pod" rel="nofollow noreferrer">Pod</a>.</p>

<p>So the pod list can be found by calling <a href="https://godoc.org/k8s.io/client-go/kubernetes#Clientset.CoreV1" rel="nofollow noreferrer"><code>CoreV1()</code></a>, then <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/core/v1#PodsGetter" rel="nofollow noreferrer"><code>Pods(namespace string)</code></a>, then <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/core/v1#PodInterface" rel="nofollow noreferrer"><code>List(opts meta_v1.ListOptions)</code></a>.</p>
