mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-11 01:49:42 +00:00
Refactor
This commit is contained in:
@@ -2,25 +2,27 @@ package client
|
||||
|
||||
import (
|
||||
"github.com/rancher/steve/pkg/attributes"
|
||||
"github.com/rancher/norman/pkg/types"
|
||||
"github.com/rancher/steve/pkg/schemaserver/types"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
type Factory struct {
|
||||
client dynamic.Interface
|
||||
Config *rest.Config
|
||||
}
|
||||
|
||||
func NewFactory(cfg *rest.Config) (*Factory, error) {
|
||||
newCfg := *cfg
|
||||
newCfg := rest.CopyConfig(cfg)
|
||||
newCfg.QPS = 10000
|
||||
newCfg.Burst = 100
|
||||
c, err := dynamic.NewForConfig(&newCfg)
|
||||
c, err := dynamic.NewForConfig(newCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Factory{
|
||||
client: c,
|
||||
Config: newCfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -28,11 +30,7 @@ func (p *Factory) DynamicClient() dynamic.Interface {
|
||||
return p.client
|
||||
}
|
||||
|
||||
func (p *Factory) Client(ctx *types.APIRequest, s *types.Schema) (dynamic.ResourceInterface, error) {
|
||||
func (p *Factory) Client(ctx *types.APIRequest, s *types.APISchema, namespace string) (dynamic.ResourceInterface, error) {
|
||||
gvr := attributes.GVR(s)
|
||||
if len(ctx.Namespaces) > 0 {
|
||||
return p.client.Resource(gvr).Namespace(ctx.Namespaces[0]), nil
|
||||
}
|
||||
|
||||
return p.client.Resource(gvr), nil
|
||||
return p.client.Resource(gvr).Namespace(namespace), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user