37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 3.15 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-04-02 15:59 . Set timeout in clients
package main
import (
"context"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
"syscall"
"time"
"github.com/docker/docker/pkg/reexec"
"github.com/ehazlett/simplelog"
"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)
}
var config app.Config
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: "debug",
Usage: "Enable debug logs",
Destination: &config.Debug,
},
cli.StringFlag{
Name: "add-local",
Usage: "Add local cluster (true, false, auto)",
Value: "auto",
Destination: &config.AddLocal,
},
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 (embedded, external, auto)",
Value: "auto",
Destination: &config.K8sMode,
},
cli.StringFlag{
Name: "log-format",
Usage: "Log formatter used (json, text, simple)",
Value: "simple",
},
cli.StringSliceFlag{
Name: "acme-domain",
Usage: "Domain to register with LetsEncrypt",
},
}
app.Action = func(c *cli.Context) error {
// enable profiler
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
config.ACMEDomains = c.GlobalStringSlice("acme-domain")
initLogs(c, config)
return run(config)
}
app.ExitErrHandler = func(c *cli.Context, err error) {
logrus.Fatal(err)
}
app.Run(os.Args)
}
func initLogs(c *cli.Context, cfg app.Config) {
if cfg.Debug {
logrus.SetLevel(logrus.DebugLevel)
}
switch c.String("log-format") {
case "simple":
logrus.SetFormatter(&simplelog.StandardFormatter{})
case "text":
logrus.SetFormatter(&logrus.TextFormatter{})
case "json":
logrus.SetFormatter(&logrus.JSONFormatter{})
}
logrus.SetOutput(os.Stdout)
//server.StartServerWithDefaults()
}
func run(cfg app.Config) error {
dump.GoroutineDumpOn(syscall.SIGUSR1, syscall.SIGILL)
ctx := signal.SigTermCancelContext(context.Background())
embedded, ctx, kubeConfig, err := k8s.GetConfig(ctx, cfg.K8sMode, cfg.KubeConfig)
if err != nil {
return err
}
cfg.Embedded = embedded
os.Unsetenv("KUBECONFIG")
kubeConfig.Timeout = 30 * time.Second
return app.Run(ctx, *kubeConfig, &cfg)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha28

搜索帮助