File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
staging/src/k8s.io/client-go/examples/in-cluster-client-configuration Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -48,24 +48,26 @@ func main() {
48
48
panic (err .Error ())
49
49
}
50
50
for {
51
+ // get pods in all the namespaces by omitting namespace
52
+ // Or specify namespace to get pods in particular namespace
51
53
pods , err := clientset .CoreV1 ().Pods ("" ).List (metav1.ListOptions {})
52
54
if err != nil {
53
55
panic (err .Error ())
54
56
}
55
57
fmt .Printf ("There are %d pods in the cluster\n " , len (pods .Items ))
56
58
57
59
// Examples for error handling:
58
- // - Use helper functions like e.g. errors.IsNotFound()
60
+ // - Use helper functions e.g. errors.IsNotFound()
59
61
// - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message
60
62
_ , err = clientset .CoreV1 ().Pods ("default" ).Get ("example-xxxxx" , metav1.GetOptions {})
61
63
if errors .IsNotFound (err ) {
62
- fmt .Printf ("Pod not found\n " )
64
+ fmt .Printf ("Pod example-xxxxx not found in default namespace \n " )
63
65
} else if statusError , isStatus := err .(* errors.StatusError ); isStatus {
64
66
fmt .Printf ("Error getting pod %v\n " , statusError .ErrStatus .Message )
65
67
} else if err != nil {
66
68
panic (err .Error ())
67
69
} else {
68
- fmt .Printf ("Found pod\n " )
70
+ fmt .Printf ("Found example-xxxxx pod in default namespace \n " )
69
71
}
70
72
71
73
time .Sleep (10 * time .Second )
You can’t perform that action at this time.
0 commit comments