0

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)

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Vasanth Raghavan
  • 162
  • 2
  • 12

1 Answers1

1

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.

Stephen Kitt
  • 2,786
  • 22
  • 32
  • Thanks so much for writing back. In the list options how do I specifically specify the options " -o yaml kubernetes "? – Vasanth Raghavan May 12 '21 at 18:31
  • I got the right struct values , one small change i this statement : fmt.Printf("GetPodList there are %v endpoints in the cluster\n", len(endpoints.Endpoints) ...endpoints.Endpoints does not work, it has to be endpoints.Items , I then convert that to a string – Vasanth Raghavan May 13 '21 at 07:39
  • 1
    Ah yes, sorry, `.Items` indeed. – Stephen Kitt May 13 '21 at 08:40