mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-04 08:35:10 +00:00
generated: run refactor
Kubernetes-commit: 3aa59f7f3077642592dc8a864fcef8ba98699894
This commit is contained in:
committed by
Kubernetes Publisher
parent
5be5d5753f
commit
60a0346672
@@ -18,6 +18,7 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -50,7 +51,7 @@ func main() {
|
||||
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{})
|
||||
pods, err := clientset.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
@@ -59,7 +60,7 @@ func main() {
|
||||
// Examples for error handling:
|
||||
// - 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{})
|
||||
_, err = clientset.CoreV1().Pods("default").Get(context.TODO(), "example-xxxxx", metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
fmt.Printf("Pod example-xxxxx not found in default namespace\n")
|
||||
} else if statusError, isStatus := err.(*errors.StatusError); isStatus {
|
||||
|
Reference in New Issue
Block a user