Add dashboard to steve

This commit is contained in:
Darren Shepherd
2020-02-21 22:18:58 -07:00
parent c069f32bbe
commit 82c7877ba3
11 changed files with 478 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import (
authcli "github.com/rancher/steve/pkg/auth/cli"
"github.com/rancher/steve/pkg/server"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/ratelimit"
"github.com/urfave/cli"
)
@@ -11,6 +12,7 @@ type Config struct {
KubeConfig string
HTTPSListenPort int
HTTPListenPort int
DashboardURL string
WebhookConfig authcli.WebhookConfig
}
@@ -28,6 +30,7 @@ func (c *Config) ToServer() (*server.Server, error) {
if err != nil {
return nil, err
}
restConfig.RateLimiter = ratelimit.None
auth, err := c.WebhookConfig.WebhookMiddleware()
if err != nil {
@@ -37,6 +40,9 @@ func (c *Config) ToServer() (*server.Server, error) {
return &server.Server{
RestConfig: restConfig,
AuthMiddleware: auth,
DashboardURL: func() string {
return c.DashboardURL
},
}, nil
}
@@ -57,6 +63,11 @@ func Flags(config *Config) []cli.Flag {
Value: 8080,
Destination: &config.HTTPListenPort,
},
cli.StringFlag{
Name: "dashboard-url",
Value: "https://releases.rancher.com/dashboard/latest/index.html",
Destination: &config.DashboardURL,
},
}
return append(flags, authcli.Flags(&config.WebhookConfig)...)

View File

@@ -37,6 +37,7 @@ type Server struct {
Router router.RouterFunc
PostStartHooks []func() error
StartHooks []StartHook
DashboardURL func() string
}
type Controllers struct {

View File

@@ -33,6 +33,7 @@ func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, ne
if err != nil {
return nil, err
}
authMiddleware = auth.ToMiddleware(auth.AuthenticatorFunc(auth.AlwaysAdmin))
} else {
proxy = k8sproxy.ImpersonatingHandler("/", cfg)
}

View File

@@ -10,6 +10,7 @@ import (
"github.com/rancher/steve/pkg/client"
"github.com/rancher/steve/pkg/clustercache"
schemacontroller "github.com/rancher/steve/pkg/controllers/schema"
"github.com/rancher/steve/pkg/dashboard"
"github.com/rancher/steve/pkg/schema"
"github.com/rancher/steve/pkg/schemaserver/types"
"github.com/rancher/steve/pkg/server/handler"
@@ -87,6 +88,10 @@ func setup(ctx context.Context, server *Server) (http.Handler, *schema.Collectio
return sync()
})
if server.DashboardURL != nil && server.DashboardURL() != "" {
handler = dashboard.Route(handler, server.DashboardURL)
}
return handler, sf, nil
}