mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-06 13:52:46 +00:00
examples: Make messages more informative
by including pod name and namespace Kubernetes-commit: f344f50fca28e79ac67e25527b1add9bf418f957
This commit is contained in:
parent
99b02d3434
commit
f17d6594e8
@ -62,15 +62,18 @@ func main() {
|
|||||||
// Examples for error handling:
|
// Examples for error handling:
|
||||||
// - Use helper functions like e.g. errors.IsNotFound()
|
// - Use helper functions like e.g. errors.IsNotFound()
|
||||||
// - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message
|
// - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message
|
||||||
_, err = clientset.CoreV1().Pods("default").Get("example-xxxxx", metav1.GetOptions{})
|
namespace := "default"
|
||||||
|
pod := "example-xxxxx"
|
||||||
|
_, err = clientset.CoreV1().Pods(namespace).Get(pod, metav1.GetOptions{})
|
||||||
if errors.IsNotFound(err) {
|
if errors.IsNotFound(err) {
|
||||||
fmt.Printf("Pod not found\n")
|
fmt.Printf("Pod %s in namespace %s not found\n", pod, namespace)
|
||||||
} else if statusError, isStatus := err.(*errors.StatusError); isStatus {
|
} else if statusError, isStatus := err.(*errors.StatusError); isStatus {
|
||||||
fmt.Printf("Error getting pod %v\n", statusError.ErrStatus.Message)
|
fmt.Printf("Error getting pod %s in namespace %s: %v\n",
|
||||||
|
pod, namespace, statusError.ErrStatus.Message)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Found pod\n")
|
fmt.Printf("Found pod %s in namespace %s\n", pod, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
Loading…
Reference in New Issue
Block a user