-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
89 lines (76 loc) · 2.43 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
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run pkg/codegen/main.go
//go:generate /bin/bash scripts/generate-manifest
package main
import (
"context"
"os"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/leader"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"github.com/harvester/harvester-load-balancer/pkg/config"
"github.com/harvester/harvester-load-balancer/pkg/controller/ippool"
"github.com/harvester/harvester-load-balancer/pkg/controller/loadbalancer"
"github.com/harvester/harvester-load-balancer/pkg/controller/vmi"
"github.com/harvester/harvester-load-balancer/pkg/utils"
)
var threadiness int
var logLevel string
func main() {
flags := []cli.Flag{
cli.StringFlag{
Name: "loglevel",
Usage: "Specify log level",
EnvVar: "LOGLEVEL",
Value: "info",
Destination: &logLevel,
},
cli.IntFlag{
Name: "threadiness",
EnvVar: "THREADINESS",
Usage: "Specify controller threads",
Value: 2,
Destination: &threadiness,
},
}
cfg, err := kubeconfig.GetNonInteractiveClientConfig(os.Getenv("KUBECONFIG")).ClientConfig()
if err != nil {
logrus.Fatal(err)
}
ctx := signals.SetupSignalContext()
app := cli.NewApp()
app.Flags = flags
app.Action = func(c *cli.Context) {
utils.SetLogLevel(logLevel)
run(ctx, cfg)
}
if err := app.Run(os.Args); err != nil {
logrus.Fatalf("run harvester load balancer controller failed: %v", err)
}
}
func run(ctx context.Context, cfg *rest.Config) {
// Generated lb controller
management := config.SetupManagement(ctx, cfg)
client := kubernetes.NewForConfigOrDie(cfg)
leader.RunOrDie(ctx, "kube-system", "harvester-load-balancer", client, func(ctx context.Context) {
// register controllers of v1beta1 version
if err := ippool.Register(ctx, management); err != nil {
logrus.Fatalf("error register ip pool controller: %s", err.Error())
}
if err := loadbalancer.Register(ctx, management); err != nil {
logrus.Fatalf("error register loadBalancer controller: %s", err.Error())
}
if err := vmi.Register(ctx, management); err != nil {
logrus.Fatalf("error register vmi controller: %s", err.Error())
}
// Start all the controllers
if err := management.Start(threadiness); err != nil {
logrus.Fatalf("error starting: %s", err.Error())
}
})
<-ctx.Done()
}