mirror of
https://github.com/rancher/steve.git
synced 2025-08-31 23:20:56 +00:00
Refactor
This commit is contained in:
58
main.go
58
main.go
@@ -2,19 +2,19 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/rancher/steve/pkg/server"
|
||||
"github.com/rancher/steve/pkg/debug"
|
||||
stevecli "github.com/rancher/steve/pkg/server/cli"
|
||||
"github.com/rancher/steve/pkg/version"
|
||||
"github.com/rancher/wrangler/pkg/signals"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
var (
|
||||
config server.Config
|
||||
config stevecli.Config
|
||||
debugconfig debug.Config
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -22,31 +22,9 @@ func main() {
|
||||
app.Name = "steve"
|
||||
app.Version = version.FriendlyVersion()
|
||||
app.Usage = ""
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "authentication",
|
||||
Destination: &config.Authentication,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "webhook-kubeconfig",
|
||||
EnvVar: "WEBHOOK_KUBECONFIG",
|
||||
Value: "webhook-kubeconfig.yaml",
|
||||
Destination: &config.WebhookKubeconfig,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "kubeconfig",
|
||||
EnvVar: "KUBECONFIG",
|
||||
Value: "",
|
||||
Destination: &config.Kubeconfig,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "listen-address",
|
||||
EnvVar: "LISTEN_ADDRESS",
|
||||
Value: ":8080",
|
||||
Destination: &config.ListenAddress,
|
||||
},
|
||||
cli.BoolFlag{Name: "debug"},
|
||||
}
|
||||
app.Flags = append(
|
||||
stevecli.Flags(&config),
|
||||
debug.Flags(&debugconfig)...)
|
||||
app.Action = run
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
@@ -54,23 +32,9 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
logging := flag.NewFlagSet("", flag.PanicOnError)
|
||||
klog.InitFlags(logging)
|
||||
if c.Bool("debug") {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
if err := logging.Parse([]string{
|
||||
"-v=7",
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := logging.Parse([]string{
|
||||
"-v=0",
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
func run(_ *cli.Context) error {
|
||||
ctx := signals.SetupSignalHandler(context.Background())
|
||||
return server.Run(ctx, config)
|
||||
debugconfig.MustSetupDebug()
|
||||
s := config.MustServerConfig().MustServer()
|
||||
return s.ListenAndServe(ctx, nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user