微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何捕获 oc 命令的输出: oc get endpoints -n default -o yaml kubernetes inside a redhat ocp container

如何解决如何捕获 oc 命令的输出: oc get endpoints -n default -o yaml kubernetes inside a redhat ocp container

我尝试使用 clientset.CoreV1().Endpoints(namespace).Get(context.Todo(),name string,Metav1.Getoptions{})

endpoints,err2 := clientset.CoreV1().Endpoints(namespace2).Get(context.Todo(),namespace2,Metav1.Getoptions{})
    if err2 != nil {
            log.Println(err2.Error())
    }

    fmt.Printf("GetPodList There are %v endpoints in the cluster\n",(endpoints))

但我不确定为名称字符串(第二个参数)和 Metav1.Getoptions{} 提供的参数。 (第三个参数)

解决方法

您应该使用 List 函数而不是 GetList 允许您检索符合特定条件的多个端点,Get 允许您检索特定端点(通过姓名)。

因此:

endpoints,err := clientset.CoreV1().Endpoints(namespace2).List(context.TODO(),metav1.ListOptions{})
// ...
fmt.Printf("GetPodList there are %v endpoints in the cluster\n",len(endpoints.Items)

如果你想要一个命名空间中的所有端点,你不需要指定任何列表选项并且传递一个空结构就可以了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。