()
| 37 | ) |
| 38 | |
| 39 | func main() { |
| 40 | // creates the in-cluster config |
| 41 | config, err := rest.InClusterConfig() |
| 42 | if err != nil { |
| 43 | panic(err.Error()) |
| 44 | } |
| 45 | // creates the clientset |
| 46 | clientset, err := kubernetes.NewForConfig(config) |
| 47 | if err != nil { |
| 48 | panic(err.Error()) |
| 49 | } |
| 50 | for { |
| 51 | pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{}) |
| 52 | if err != nil { |
| 53 | panic(err.Error()) |
| 54 | } |
| 55 | fmt.Printf("There are %d pods in the cluster\n", len(pods.Items)) |
| 56 | |
| 57 | // Examples for error handling: |
| 58 | // - Use helper functions like e.g. errors.IsNotFound() |
| 59 | // - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message |
| 60 | _, err = clientset.CoreV1().Pods("default").Get("example-xxxxx", metav1.GetOptions{}) |
| 61 | if errors.IsNotFound(err) { |
| 62 | fmt.Printf("Pod not found\n") |
| 63 | } else if statusError, isStatus := err.(*errors.StatusError); isStatus { |
| 64 | fmt.Printf("Error getting pod %v\n", statusError.ErrStatus.Message) |
| 65 | } else if err != nil { |
| 66 | panic(err.Error()) |
| 67 | } else { |
| 68 | fmt.Printf("Found pod\n") |
| 69 | } |
| 70 | |
| 71 | time.Sleep(10 * time.Second) |
| 72 | } |
| 73 | } |
nothing calls this directly
no test coverage detected