This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
109 lines (91 loc) · 2.53 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/rancher/kubernetes-agent/config"
"github.com/rancher/kubernetes-agent/healthcheck"
"github.com/rancher/kubernetes-agent/hostwatch"
"github.com/rancher/kubernetes-agent/kubernetesclient"
"github.com/rancher/kubernetes-agent/rancherevents"
"github.com/rancher/kubernetes-agent/watchevents"
)
func main() {
app := cli.NewApp()
app.Name = "kubernetes-agent"
app.Usage = "Start the Rancher kubernetes agent"
app.Action = launch
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "kubernetes-url",
Value: "http://localhost:8080",
Usage: "URL for kubernetes API",
EnvVar: "KUBERNETES_URL",
},
cli.StringFlag{
Name: "cattle-url",
Usage: "URL for cattle API",
EnvVar: "CATTLE_URL",
},
cli.StringFlag{
Name: "cattle-access-key",
Usage: "Cattle API Access Key",
EnvVar: "CATTLE_ACCESS_KEY",
},
cli.StringFlag{
Name: "cattle-secret-key",
Usage: "Cattle API Secret Key",
EnvVar: "CATTLE_SECRET_KEY",
},
cli.IntFlag{
Name: "worker-count",
Value: 50,
Usage: "Number of workers for handling events",
EnvVar: "WORKER_COUNT",
},
cli.IntFlag{
Name: "health-check-port",
Value: 10240,
Usage: "Port to configure an HTTP health check listener on",
EnvVar: "HEALTH_CHECK_PORT",
},
cli.IntFlag{
Name: "host-update-interval",
Value: 5,
Usage: "The frequency at which host labels should be updated",
},
}
app.Run(os.Args)
}
func launch(c *cli.Context) {
conf := config.Conf(c)
resultChan := make(chan error)
rClient, err := config.GetRancherClient(conf)
if err != nil {
log.Fatal(err)
}
kClient := kubernetesclient.NewClient(conf.KubernetesURL)
svcHandler := watchevents.NewServiceHandler(rClient, kClient)
nsHandler := watchevents.NewNamespaceHandler(rClient, kClient)
svcHandler.Start()
defer svcHandler.Stop()
nsHandler.Start()
defer nsHandler.Stop()
go func(rc chan error) {
err := rancherevents.ConnectToEventStream(rClient, kClient, conf)
log.Errorf("Rancher stream listener exited with error: %s", err)
rc <- err
}(resultChan)
go func(rc chan error) {
err := healthcheck.StartHealthCheck(conf.HealthCheckPort)
log.Errorf("Rancher healthcheck exited with error: %s", err)
rc <- err
}(resultChan)
go func(rc chan error) {
err := hostwatch.StartHostSync(c.Int("host-update-interval"), kClient)
log.Errorf("Rancher host sync service exited with error: %s", err)
rc <- err
}(resultChan)
<-resultChan
log.Info("Exiting.")
}