-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
41 lines (34 loc) · 866 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
package main
import (
"context"
"fmt"
"os"
"github.com/jenkins-x/jx-kube-client/v3/pkg/kubeclient"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
func main() {
kcfg := os.Getenv("KUBECONFIG")
fmt.Printf("config: %s\n", kcfg)
f := kubeclient.NewFactory()
cfg, err := f.CreateKubeConfig()
if err != nil {
fmt.Printf("failed to create config: %s\n", err.Error())
return
}
client, err := kubernetes.NewForConfig(cfg)
if err != nil {
fmt.Printf("failed to create client: %s\n", err.Error())
return
}
ctx := context.TODO()
ns, err := client.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
fmt.Printf("failed to list namespaces: %s\n", err.Error())
return
}
fmt.Printf("has %d namespaces:\n", len(ns.Items))
for i := range ns.Items {
fmt.Printf(" %s\n", ns.Items[i].Name)
}
}