1
0
mirror of https://github.com/rancher/steve.git synced 2025-08-01 06:46:03 +00:00

Merge pull request #14 from guangbochen/harvester-v0.2

Add default api server and fix invalid open-api arbitrary type
This commit is contained in:
Darren Shepherd 2021-02-19 09:21:18 -08:00 committed by GitHub
commit 2cf9f857b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -107,6 +107,8 @@ func toField(schema proto.Schema) schemas.Field {
f.Type = sub.GetPath().String()
}
case *proto.Arbitrary:
logrus.Debugf("arbitrary type: %v", schema)
f.Type = "json"
default:
logrus.Errorf("unknown type: %v", schema)
f.Type = "json"

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