forked from harvester/harvester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (85 loc) · 2.61 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
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate /bin/rm -rf pkg/generated
//go:generate go run pkg/codegen/main.go
//go:generate /bin/bash scripts/generate-manifest
//go:generate /bin/bash scripts/generate-openapi
package main
import (
"fmt"
_ "net/http/pprof"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/harvester/harvester/pkg/cmd"
"github.com/harvester/harvester/pkg/config"
"github.com/harvester/harvester/pkg/server"
)
func main() {
var options config.Options
flags := []cli.Flag{
cli.IntFlag{
Name: "threadiness",
EnvVar: "THREADINESS",
Usage: "Specify controller threads",
Value: 10,
Destination: &options.Threadiness,
},
cli.IntFlag{
Name: "http-port",
EnvVar: "HARVESTER_SERVER_HTTP_PORT",
Usage: "HTTP listen port",
Value: 8080,
Destination: &options.HTTPListenPort,
},
cli.IntFlag{
Name: "https-port",
EnvVar: "HARVESTER_SERVER_HTTPS_PORT",
Usage: "HTTPS listen port",
Value: 8443,
Destination: &options.HTTPSListenPort,
},
cli.StringFlag{
Name: "namespace",
EnvVar: "NAMESPACE",
Destination: &options.Namespace,
Usage: "The default namespace to store management resources",
Required: true,
},
cli.BoolFlag{
Name: "hci-mode",
EnvVar: "HCI_MODE",
Usage: "Enable HCI mode. Additional controllers are registered in HCI mode",
Destination: &options.HCIMode,
},
cli.BoolFlag{
Name: "rancher-embedded",
EnvVar: "RANCHER_EMBEDDED",
Usage: "Specify whether the Harvester is running with embedded Rancher mode, default to false",
Destination: &options.RancherEmbedded,
},
cli.StringFlag{
Name: "rancher-server-url",
EnvVar: "RANCHER_SERVER_URL",
Usage: "Specify the URL to connect to the Rancher server",
Destination: &options.RancherURL,
Hidden: true,
},
}
app := cmd.NewApp("Harvester API Server", "", flags, func(commonOptions *config.CommonOptions) error {
return run(commonOptions, options)
})
app.Run()
}
func run(commonOptions *config.CommonOptions, options config.Options) error {
logrus.Info("Starting controller")
ctx := signals.SetupSignalContext()
kubeConfig, err := server.GetConfig(commonOptions.KubeConfig)
if err != nil {
return fmt.Errorf("failed to find kubeconfig: %v", err)
}
harv, err := server.New(ctx, kubeConfig, options)
if err != nil {
return fmt.Errorf("failed to create harvester server: %v", err)
}
return harv.ListenAndServe(nil, options)
}