-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
120 lines (103 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"syscall"
"github.com/docker/docker/pkg/reexec"
"github.com/rancher/norman/pkg/dump"
"github.com/rancher/norman/signal"
"github.com/rancher/rancher/app"
"github.com/rancher/rancher/k8s"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var (
VERSION = "dev"
)
func main() {
if reexec.Init() {
return
}
os.Unsetenv("SSH_AUTH_SOCK")
os.Unsetenv("SSH_AGENT_PID")
if dir, err := os.Getwd(); err == nil {
dmPath := filepath.Join(dir, "management-state", "bin")
os.MkdirAll(dmPath, 0700)
newPath := fmt.Sprintf("%s%s%s", dmPath, string(os.PathListSeparator), os.Getenv("PATH"))
os.Setenv("PATH", newPath)
}
config := app.Config{
InteralListenPort: 8081,
}
app := cli.NewApp()
app.Version = VERSION
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "kubeconfig",
Usage: "Kube config for accessing k8s cluster",
EnvVar: "KUBECONFIG",
Destination: &config.KubeConfig,
},
cli.BoolFlag{
Name: "add-local",
Usage: "Add local cluster to management server",
Destination: &config.AddLocal,
},
cli.BoolFlag{
Name: "debug",
Usage: "Enable debug logs",
Destination: &config.Debug,
},
cli.IntFlag{
Name: "http-listen-port",
Usage: "HTTP listen port",
Value: 8080,
Destination: &config.HTTPListenPort,
},
cli.IntFlag{
Name: "https-listen-port",
Usage: "HTTPS listen port",
Value: 8443,
Destination: &config.HTTPSListenPort,
},
cli.StringFlag{
Name: "k8s-mode",
Usage: "Mode to run or access k8s API server for management API (internal, exec)",
Value: "internal",
Destination: &config.K8sMode,
},
cli.StringSliceFlag{
Name: "acme-domain",
Usage: "Domain to register with LetsEncrypt",
},
cli.BoolFlag{
Name: "http-only",
Usage: "Disable HTTPS",
Destination: &config.HTTPOnly,
},
}
app.Action = func(c *cli.Context) error {
config.ACMEDomains = c.GlobalStringSlice("acme-domain")
return run(config)
}
app.ExitErrHandler = func(c *cli.Context, err error) {
logrus.Fatal(err)
}
app.Run(os.Args)
}
func run(cfg app.Config) error {
if cfg.Debug {
logrus.SetLevel(logrus.DebugLevel)
}
dump.GoroutineDumpOn(syscall.SIGUSR1, syscall.SIGILL)
ctx := signal.SigTermCancelContext(context.Background())
os.Args = []string{os.Args[0]}
kubeConfig, local, err := k8s.GetConfig(ctx, cfg.K8sMode, cfg.AddLocal, cfg.KubeConfig, cfg.InteralListenPort)
if err != nil {
return err
}
cfg.AddLocal = local
return app.Run(ctx, *kubeConfig, &cfg)
}