-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
48 lines (40 loc) · 912 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func runClient() error {
kubeConfigPath := flag.String("kubeconfig", filepath.Join(os.Getenv("HOME"), ".kube", "config"), "kube config path")
flag.Parse()
// CREATE CLIENT OMIT
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath) // HL1
if err != nil {
return err
}
clientset, err := kubernetes.NewForConfig(config) // HL2
if err != nil {
return err
}
// CREATE CLIENT OMIT
// LIST PODS OMIT
pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{}) // HL
if err != nil {
return err
}
// LIST PODS OMIT
for _, p := range pods.Items {
fmt.Printf("Namespace: %v\tPod: %v\n", p.Namespace, p.Name)
}
return nil
}
func main() {
err := runClient()
if err != nil {
panic(err)
}
}