dtwncxs3547 2017-10-30 20:33
浏览 346

操作Kubernetes的客户端PodList

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 ?

  • 写回答

1条回答 默认 最新

  • doushen4719 2017-10-31 16:57
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据