go - 如何捕获 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
函数而不是Get
:List
允许您检索匹配特定条件的多个端点,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)
如果你想要一个命名空间中的所有端点,你不需要指定任何列表选项并且传递一个空结构就可以了。
推荐阅读
- python - 你如何防止 Flask 记录特定的路由?
- automation - 将日语支持添加到 OCR | RPA
- symfony - 无法解析“xx”、UserPasswordEncoderInterface、Symfony 4.* 的参数 $encoder
- javascript - Vue setTimeout 过滤器问题
- node.js - sequelize-cli db:migrate "hangs" 向新添加的列添加检查约束
- node.js - 如何更改 _nuxt 文件夹的名称?
- javascript - styled-jsx/webpack 和自定义 webpack.config.js 的问题
- python - Selenium:selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:
- c# - 剪贴板标签复制所选内容仅问题
- asp.net-mvc - 模态创建日志而不更改页面