diff --git a/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/main.go b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/main.go index fd107844642..c93d40413e7 100644 --- a/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/main.go +++ b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/main.go @@ -48,6 +48,8 @@ func main() { panic(err.Error()) } for { + // get pods in all the namespaces by omitting namespace + // Or specify namespace to get pods in particular namespace pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{}) if err != nil { panic(err.Error()) @@ -55,17 +57,17 @@ func main() { fmt.Printf("There are %d pods in the cluster\n", len(pods.Items)) // Examples for error handling: - // - Use helper functions like e.g. errors.IsNotFound() + // - Use helper functions e.g. errors.IsNotFound() // - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message _, err = clientset.CoreV1().Pods("default").Get("example-xxxxx", metav1.GetOptions{}) if errors.IsNotFound(err) { - fmt.Printf("Pod not found\n") + fmt.Printf("Pod example-xxxxx not found in default namespace\n") } else if statusError, isStatus := err.(*errors.StatusError); isStatus { fmt.Printf("Error getting pod %v\n", statusError.ErrStatus.Message) } else if err != nil { panic(err.Error()) } else { - fmt.Printf("Found pod\n") + fmt.Printf("Found example-xxxxx pod in default namespace\n") } time.Sleep(10 * time.Second)