-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
58 lines (46 loc) · 1.06 KB
/
api.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
package api
import (
"flag"
"path/filepath"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
func int32Ptr(i int32) *int32 {
return &i
}
func int64Ptr(i int64) *int64 {
return &i
}
func strPtr(s string) *string {
return &s
}
var deploymentName string
func SetDeploymentName(name string) {
deploymentName = name
}
var replicas int32
func SetReplicas(rep int32) {
replicas = rep
}
func CreateClientSet() kubernetes.Interface {
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
// fmt.Println(home)
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
//fmt.Println(*kubeconfig)
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err)
}
var clientset kubernetes.Interface
clientset, err = kubernetes.NewForConfig(config)
if err != nil {
panic(err)
}
return clientset
}