1
0
mirror of https://github.com/rancher/steve.git synced 2025-04-28 11:14:43 +00:00

Add default api-server option

This commit is contained in:
Guangbo Chen 2021-01-08 17:28:24 +08:00
parent 21c7add15f
commit 0edf9c780f
2 changed files with 10 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import (
"net/http"
"github.com/rancher/apiserver/pkg/server"
apiserver "github.com/rancher/apiserver/pkg/server"
"github.com/rancher/apiserver/pkg/types"
"github.com/rancher/apiserver/pkg/urlbuilder"
"github.com/rancher/steve/pkg/accesscontrol"
@ -16,7 +17,8 @@ import (
"k8s.io/client-go/rest"
)
func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, next http.Handler, routerFunc router.RouterFunc) (http.Handler, error) {
func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, next http.Handler,
routerFunc router.RouterFunc) (*apiserver.Server, http.Handler, error) {
var (
proxy http.Handler
err error
@ -31,7 +33,7 @@ func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, ne
if authMiddleware == nil {
proxy, err = k8sproxy.Handler("/", cfg)
if err != nil {
return nil, err
return a.server, nil, err
}
authMiddleware = auth.ToMiddleware(auth.AuthenticatorFunc(auth.AlwaysAdmin))
} else {
@ -46,9 +48,9 @@ func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, ne
APIRoot: w(a.apiHandler(apiRoot)),
}
if routerFunc == nil {
return router.Routes(handlers), nil
return a.server, router.Routes(handlers), nil
}
return routerFunc(handlers), nil
return a.server, routerFunc(handlers), nil
}
type apiServer struct {

View File

@ -5,6 +5,7 @@ import (
"errors"
"net/http"
apiserver "github.com/rancher/apiserver/pkg/server"
"github.com/rancher/apiserver/pkg/types"
"github.com/rancher/dynamiclistener/server"
"github.com/rancher/steve/pkg/accesscontrol"
@ -33,6 +34,7 @@ type Server struct {
RESTConfig *rest.Config
BaseSchemas *types.APISchemas
AccessSetLookup accesscontrol.AccessSetLookup
APIServer *apiserver.Server
authMiddleware auth.Middleware
controllers *Controllers
@ -150,11 +152,12 @@ func setup(ctx context.Context, server *Server) error {
ccache,
sf)
handler, err := handler.New(server.RESTConfig, sf, server.authMiddleware, server.next, server.router)
apiServer, handler, err := handler.New(server.RESTConfig, sf, server.authMiddleware, server.next, server.router)
if err != nil {
return err
}
server.APIServer = apiServer
server.Handler = handler
server.SchemaFactory = sf
return nil