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.
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 http
library?
And here's one example (taken from some real code):
pod, err := kubecli.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
What I feel bothersome is that I have to look up everything in the API docs and then I additionally need to figure out that /v1/
translates to CoreV1()
. And I'm not even sure where I could look that up. Also the whole block metav1.GetOptions{}
seems completely unnecessary, or which part of a HTTP request is represented by it?
I hope I could make clear what the confusion is and hope for your help in clearing it up.
Edit:
Here's also an example, generated from the new operator-framework which sadly doesn't make it much better:
return &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"},
},
},
},
}
The API docs don't know anything about this TypeMeta
object. And the second element is called ObjectMeta:
instead of metadata
. I mean, I'm not a magician. How should I know this.