-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
75 lines (63 loc) · 1.64 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
73
74
75
package main
import (
"flag"
"fmt"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
"k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/scheme"
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
)
const (
defaultNamespace = "default"
)
// manager of different kinds of generator
type GeneratorManager struct {
generators map[string]Generator
}
func (gm *GeneratorManager) register(generator Generator) {
if name := generator.Name(); name != "" {
gm.generators[name] = generator
}
}
func (gm *GeneratorManager) run() {
for {
// run forever
for name, generator := range gm.generators {
fmt.Printf("%s events generator started\n", name)
generator.Generate()
}
}
}
var generatorManager *GeneratorManager
func init() {
config, err := clientcmd.BuildConfigFromFlags("", "")
if err != nil {
panic(err)
}
clientSet, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err)
}
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(klog.Infof)
eventBroadcaster.StartRecordingToSink(
&typedcorev1.EventSinkImpl{
Interface: clientSet.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(
scheme.Scheme,
v1.EventSource{Component: kubernetesEventsGenerator})
generatorManager = &GeneratorManager{
generators: make(map[string]Generator),
}
generatorManager.register(NewDeploymentGenerator(clientSet, recorder, 0))
generatorManager.register(NewNodeGenerator(clientSet, recorder))
generatorManager.register(NewPodGenerator(clientSet, recorder, 0))
}
func main() {
// parse flag
flag.Parse()
generatorManager.run()
}