mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 00:31:00 +00:00
Merge pull request #82932 from ashish-billore/mybranch2
Corrected the pod reporting and messages
This commit is contained in:
commit
08f46e425b
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user