1
0
mirror of https://github.com/rancher/steve.git synced 2025-05-01 04:33:30 +00:00
steve/pkg/client/factory.go

37 lines
793 B
Go
Raw Normal View History

2019-08-04 17:41:32 +00:00
package client
import (
2019-09-11 21:05:00 +00:00
"github.com/rancher/steve/pkg/attributes"
2020-01-31 05:37:59 +00:00
"github.com/rancher/steve/pkg/schemaserver/types"
2019-08-04 17:41:32 +00:00
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
)
type Factory struct {
client dynamic.Interface
2020-01-31 05:37:59 +00:00
Config *rest.Config
2019-08-04 17:41:32 +00:00
}
func NewFactory(cfg *rest.Config) (*Factory, error) {
2020-01-31 05:37:59 +00:00
newCfg := rest.CopyConfig(cfg)
2019-08-04 17:41:32 +00:00
newCfg.QPS = 10000
newCfg.Burst = 100
2020-01-31 05:37:59 +00:00
c, err := dynamic.NewForConfig(newCfg)
2019-08-04 17:41:32 +00:00
if err != nil {
return nil, err
}
return &Factory{
client: c,
2020-01-31 05:37:59 +00:00
Config: newCfg,
2019-08-04 17:41:32 +00:00
}, nil
}
2019-09-09 21:28:55 +00:00
func (p *Factory) DynamicClient() dynamic.Interface {
return p.client
}
2020-01-31 05:37:59 +00:00
func (p *Factory) Client(ctx *types.APIRequest, s *types.APISchema, namespace string) (dynamic.ResourceInterface, error) {
2019-08-04 17:41:32 +00:00
gvr := attributes.GVR(s)
2020-01-31 05:37:59 +00:00
return p.client.Resource(gvr).Namespace(namespace), nil
2019-08-04 17:41:32 +00:00
}