1
0
mirror of https://github.com/rancher/steve.git synced 2025-08-12 03:31:35 +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() f.Type = sub.GetPath().String()
} }
case *proto.Arbitrary: case *proto.Arbitrary:
logrus.Debugf("arbitrary type: %v", schema)
f.Type = "json"
default: default:
logrus.Errorf("unknown type: %v", schema) logrus.Errorf("unknown type: %v", schema)
f.Type = "json" f.Type = "json"

View File

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

View File

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