-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
68 lines (50 loc) · 1.39 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
/*
k8s标签生成log收集配置文件
1. k8s标签->Pods
2. Pods->ContainerIds
3. ContainerIds->logHostPath
4. logHostPath->配置文件
*/
package main
import (
"k8s.io/klog"
"os"
"time"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
const (
moduleNameTag = "torrent/module_name"
logPathTag = "torrent/log_path"
inputTemplatePath = "/tpl/filebeat-input-log.tpl"
)
var (
dockerClientVersion string
)
func init() {
if os.Getenv("DOCKER_CLIENT_VERSION") == "" {
dockerClientVersion = "1.38"
} else {
dockerClientVersion = os.Getenv("DOCKER_CLIENT_VERSION")
}
}
func main() {
klog.InitFlags(nil)
stopCh := make(chan struct{})
// creates the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
klog.Fatalf("Error building kubeconfig: %s", err.Error())
}
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Fatalf("Error building kubernets clientset: %s", err.Error())
}
kubeInformerFactory := informers.NewSharedInformerFactory(kubeClient, time.Second*30)
controller := NewController(kubeClient, kubeInformerFactory.Core().V1().Pods())
kubeInformerFactory.Start(stopCh)
if err = controller.Run(1, stopCh); err != nil {
klog.Fatalf("Error running controller: %s", err.Error())
}
}