From 31e427b54c500f2e532ebeb1990eb7580bf86729 Mon Sep 17 00:00:00 2001 From: ashish-billore Date: Fri, 20 Sep 2019 19:18:17 +0900 Subject: [PATCH] Corrected the pod reporting and messages It is inconsistent and confusing to report pod count from all namespaces but report message for only default namespace. Added the namespace (default) reporting to clarify this. Updated comments for usage clarity. --- .../examples/in-cluster-client-configuration/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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)