-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
52 lines (45 loc) · 1.11 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
package main
import (
"context"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
klog "k8s.io/klog/v2"
"k8s.io/kubectl/pkg/util/logs"
)
func getK8sClient() *kubernetes.Clientset {
// creates the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
panic(err.Error())
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Fatal(err)
}
return clientset
}
func main() {
logs.InitLogs()
defer logs.FlushLogs()
bctx := context.Background()
ctx, cancel := context.WithCancel(bctx)
defer cancel()
clientset := getK8sClient()
factory := informers.NewSharedInformerFactory(clientset, time.Hour*24)
controller := NewEventExporterController(factory)
err := controller.Run(ctx.Done())
if err != nil {
klog.Fatal(err)
}
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
startServer(":8090", mux, cancel)
}