I tried using 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))
But I am unsure of the argument to give for name string (the second argument) and metav1.GetOptions{}. (third argument)
You should use the List
function rather than Get
: List
allows you to retrieve multiple endpoints matching certain criteria, Get
allows you to retrieve a specific endpoint (by name).
Thus:
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)
If you want all the endpoints in a namespace, you don’t need to specify any list options and passing an empty structure is fine.