This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathmain.go
88 lines (75 loc) · 1.97 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
package main
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/rancher/lb-controller/controller"
"github.com/rancher/lb-controller/provider"
"github.com/urfave/cli"
"os"
"os/signal"
"syscall"
)
var (
lbControllerName string
lbProviderName string
metadataAddress string
lbc controller.LBController
lbp provider.LBProvider
)
func init() {
//logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(os.Stdout)
}
func main() {
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "controller",
Value: "kubernetes",
Usage: "Controller plugin name",
}, cli.StringFlag{
Name: "provider",
Value: "haproxy",
Usage: "Provider plugin name",
}, cli.StringFlag{
Name: "metadata-address",
Value: "rancher-metadata",
Usage: "Rancher metadata address",
},
}
app.Action = func(c *cli.Context) error {
logrus.Infof("Starting Rancher LB service")
lbControllerName = c.String("controller")
lbProviderName = c.String("provider")
metadataAddress = c.String("metadata-address")
lbc = controller.GetController(lbControllerName, fmt.Sprintf("http://%s/2015-12-19", metadataAddress))
if lbc == nil {
logrus.Fatalf("Unable to find controller by name %s", lbControllerName)
}
lbp = provider.GetProvider(lbProviderName)
if lbp == nil {
logrus.Fatalf("Unable to find provider by name %s", lbProviderName)
}
logrus.Infof("LB controller: %s", lbc.GetName())
logrus.Infof("LB provider: %s", lbp.GetName())
go handleSigterm(lbc, lbp)
go startHealthcheck()
lbc.Run(lbp)
return nil
}
app.Run(os.Args)
}
func handleSigterm(lbc controller.LBController, lbp provider.LBProvider) {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGTERM)
<-signalChan
logrus.Infof("Received SIGTERM, shutting down")
exitCode := 0
// stop the controller
if err := lbc.Stop(); err != nil {
logrus.Infof("Error during shutdown %v", err)
exitCode = 1
}
logrus.Infof("Exiting with %v", exitCode)
os.Exit(exitCode)
}