-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics-watcher.go
44 lines (35 loc) · 888 Bytes
/
metrics-watcher.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
package main
import (
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
metricsv "k8s.io/metrics/pkg/client/clientset/versioned"
"os"
"time"
)
func main() {
configPath := os.Getenv("KUBECONFIG")
var (
config *rest.Config
)
if configPath != "" {
c, err := clientcmd.BuildConfigFromFlags("", configPath)
if err != nil {
panic(err)
}
config = c
} else {
c, err := rest.InClusterConfig()
if err != nil {
panic(err)
}
config = c
}
clientSet := kubernetes.NewForConfigOrDie(config)
metricsClientSet := metricsv.NewForConfigOrDie(config)
sharedInformers := informers.NewSharedInformerFactory(clientSet, 2*time.Minute)
limitController := NewLimitController(clientSet, metricsClientSet, sharedInformers.Core().V1().Pods())
sharedInformers.Start(nil)
limitController.Run(nil)
}