Go 如何在redhat ocp容器中捕获oc命令的输出:oc get endpoints-n default-o yaml kubernetes
我尝试使用clientset.CoreV1().Endpoints(namespace.Get)(context.TODO(),name string,metav1.GetOptions{})Go 如何在redhat ocp容器中捕获oc命令的输出:oc get endpoints-n default-o yaml kubernetes,go,openshift,redhat-containers,Go,Openshift,Redhat Containers,我尝试使用clientset.CoreV1().Endpoints(namespace.Get)(context.TODO(),name string,metav1.GetOptions{}) 但是我不确定name string(第二个参数)和metav1.GetOptions{}的参数。(第三个参数)您应该使用List函数,而不是Get:List允许您检索多个符合特定条件的端点,Get允许您检索特定端点(按名称) 因此: endpoints,err:=clientset.CoreV1().en
但是我不确定name string(第二个参数)和metav1.GetOptions{}的参数。(第三个参数)您应该使用
List
函数,而不是Get
:List
允许您检索多个符合特定条件的端点,Get
允许您检索特定端点(按名称)
因此:
endpoints,err:=clientset.CoreV1().endpoints(namespace2).List(context.TODO(),metav1.ListOptions{})
// ...
fmt.Printf(“GetPodList群集中有%v个端点\n”),len(endpoints.Items)
如果希望名称空间中的所有端点,则无需指定任何列表选项,传递空结构也可以。非常感谢您的回复。在列表选项中,我如何具体指定选项“-o yaml kubernetes”?我得到了正确的结构值,这条语句中的一个小改动是:fmt.Printf(“GetPodList群集中有%v个端点\n”,len(endpoints.endpoints)…endpoints.endpoints不起作用,它必须是endpoints.Items,然后我将其转换为stringAh是的,对不起,
。Items
确实如此。
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))