Reputation: 669
I am poking around Kubernetes client-go and cannot get my mind around the proper way to manipulate the Pod struct...
I get a PodList pods like this:
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatal(err)
}
// Get Pods
pods, err := clientset.CoreV1().Pods("").List(meta_v1.ListOptions{})
if err != nil {
fmt.Println(err)
return
}
I can then get some of the values for each Pod using a loop like
for _, pod := range pods.Items {
fmt.Println(pod.GetName(), pod.Namespace)
}
But only from the ObjectMeta struct, which has some Getters (pod.GetName()), using .Value works too (pod.Namespace). I can't get my head around what's the proper way to access the data nested in Spec PodSpec and Status PodStatus.
Maybe I am lacking some core Golang concepts... Can anybody enlight me, point me into some direction or provide me a generic example of the proper way to do this ?
Upvotes: 0
Views: 1954
Reputation: 669
I found the solution, but instead of shamelessly remove this, I will provide an answer:
The Spec and Status struct I wanted to access are simply reachable using something like pod.Spec.NodeName
or pod.Status.StartTime
...
If somebody can provide a more elaborated answer to complement this, please do.
Upvotes: 2