-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
executable file
·78 lines (66 loc) · 1.83 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
//"context"
"flag"
"fmt"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"log"
"os"
"path/filepath"
)
const (
ResourceHealthy = "\xE2\x9C\x85"
ResourceUnhealthy = "\xE2\x9D\x8C"
)
var (
client dynamic.Interface
clientset *kubernetes.Clientset
clientConfig *rest.Config
kubeconfig, namespace *string
err error
)
func main() {
parseFlags()
prepKubernetesConnection()
serverVersion, _ := clientset.ServerVersion()
if serverVersion == nil {
log.Fatalf("Couldn't reach Kubernetes. Do you need to authenticate first? Maybe you use ADFS. Ensure `kubectl get nodes` works to ensure you can communicate with the cluster.")
}
fmt.Printf("Server Version %s\n", serverVersion)
HelmReleases()
}
// homeDir fetches the home directory based on OS.
func homeDir() string {
if h := os.Getenv("HOME"); h != "" {
return h
}
return os.Getenv("USERPROFILE") // windows
}
// parseFlags does what it says, it parses any flags passed to the program and sets any defaults.
func parseFlags() {
if home := homeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
namespace = flag.String("n", "", "specify the namespace to get the helm release data from")
flag.Parse()
}
// prepKubernetesConnection
func prepKubernetesConnection() {
clientConfig, err = clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err)
}
client, err = dynamic.NewForConfig(clientConfig)
if err != nil {
panic(err)
}
clientset, err = kubernetes.NewForConfig(clientConfig)
if err != nil {
panic(err)
}
}