-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (57 loc) · 1.84 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
package main
import (
"context"
"flag"
"fmt"
"time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
cli "github.com/ansalamdaniel/hadepl/pkg/client/clientset/versioned"
hinformer "github.com/ansalamdaniel/hadepl/pkg/client/informers/externalversions"
)
func main() {
kubeconfig := flag.String("kubeconfig", "/home/ansalam/.kube/config", "(optional) absolute path to the kubeconfig file")
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
fmt.Printf("error %s when loading the config file\n", err.Error())
config, err = rest.InClusterConfig()
if err != nil {
fmt.Printf("error %s when trying to load the cofig from cluster\n", err.Error())
}
}
clientset, err := cli.NewForConfig(config)
if err != nil {
fmt.Printf("error %s", err.Error())
}
fmt.Println(clientset)
had, err := clientset.AnsimattV1alpha1().HADeployments("default").List(context.Background(), v1.ListOptions{})
if err != nil {
fmt.Printf("getting error %s in had retrieval\n", err.Error())
}
fmt.Printf("length of HADeployments %d\n", len(had.Items))
inFactory := hinformer.NewSharedInformerFactory(clientset, 10*time.Minute)
if err != nil {
fmt.Println(err.Error())
}
hadinf := inFactory.Ansimatt().V1alpha1().HADeployments()
hadinf.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(new interface{}) {
fmt.Println("pod created")
},
UpdateFunc: func(old, new interface{}) {
fmt.Println("pod updated")
},
DeleteFunc: func(obj interface{}) {
fmt.Println("pod deleted")
},
})
inFactory.Start(wait.NeverStop)
inFactory.WaitForCacheSync(wait.NeverStop)
had1, _ := hadinf.Lister().HADeployments("default").Get("default")
fmt.Println(had1)
<-wait.NeverStop
}