-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (52 loc) · 1.36 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
package main
import (
"log"
"os"
"time"
"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
)
func buildConfiguration() (*rest.Config, error) {
kubeconfig := os.Getenv("KUBECONFIG")
var clusterConfig *rest.Config
var err error
if kubeconfig != "" {
clusterConfig, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
} else {
clusterConfig, err = rest.InClusterConfig()
}
if err != nil {
return nil, err
}
return clusterConfig, nil
}
func main() {
clusterConfig, err := buildConfiguration()
if err != nil {
panic(err)
}
clusterClient, err := dynamic.NewForConfig(clusterConfig)
if err != nil {
log.Fatalln(err)
}
resource := v1alpha1.GroupVersion.WithResource("featureflagconfigurations")
factory := dynamicinformer.NewFilteredDynamicSharedInformerFactory(clusterClient,
time.Minute, "", nil)
informer := factory.ForResource(resource).Informer()
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
log.Println("AddFunc")
},
UpdateFunc: func(oldObj, newObj interface{}) {
log.Println("UpdateFunc")
},
DeleteFunc: func(obj interface{}) {
log.Println("DeleteFunc")
},
})
informer.Run(make(chan struct{}))
}