Skip to content

Commit

Permalink
Update to use new opts struct from vmware-tanzu#4372
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nelson <minelson@vmware.com>
  • Loading branch information
absoludity committed Mar 2, 2022
1 parent 145903e commit 2a3f661
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
17 changes: 14 additions & 3 deletions cmd/kubeapps-apis/core/plugins/v1alpha1/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type GRPCPluginRegistrationOptions struct {
ConfigGetter core.KubernetesConfigGetter
ClustersConfig kube.ClustersConfig
PluginConfigPath string
// The QPS and Burst options that have been configured for any
// clients of the K8s API server created by plugins.
ClientQPS float32
ClientBurst int
}

// PluginWithServer keeps a record of a GRPC server and its plugin detail.
Expand Down Expand Up @@ -131,7 +135,7 @@ func (s *PluginsServer) registerPlugins(pluginPaths []string, grpcReg grpc.Servi
return err
}

if grpcServer, err := s.registerGRPC(p, pluginDetail, grpcReg, configGetter, serveOpts.PluginConfigPath); err != nil {
if grpcServer, err := s.registerGRPC(p, pluginDetail, grpcReg, configGetter, serveOpts); err != nil {
return err
} else {
pluginsWithServers = append(pluginsWithServers, PluginWithServer{
Expand All @@ -156,7 +160,7 @@ func (s *PluginsServer) registerPlugins(pluginPaths []string, grpcReg grpc.Servi

// registerGRPC finds and calls the required function for registering the plugin for the GRPC server.
func (s *PluginsServer) registerGRPC(p *plugin.Plugin, pluginDetail *plugins.Plugin, registrar grpc.ServiceRegistrar,
clientGetter core.KubernetesConfigGetter, pluginConfigPath string) (interface{}, error) {
configGetter core.KubernetesConfigGetter, serveOpts core.ServeOptions) (interface{}, error) {
grpcRegFn, err := p.Lookup(grpcRegisterFunction)
if err != nil {
return nil, fmt.Errorf("unable to lookup %q for %v: %w", grpcRegisterFunction, pluginDetail, err)
Expand All @@ -171,7 +175,14 @@ func (s *PluginsServer) registerGRPC(p *plugin.Plugin, pluginDetail *plugins.Plu
return nil, fmt.Errorf("unable to use %q in plugin %v due to mismatched signature.\nwant: %T\ngot: %T", grpcRegisterFunction, pluginDetail, stubFn, grpcRegFn)
}

server, err := grpcFn(GRPCPluginRegistrationOptions{registrar, clientGetter, s.clustersConfig, pluginConfigPath})
server, err := grpcFn(GRPCPluginRegistrationOptions{
Registrar: registrar,
ConfigGetter: configGetter,
ClustersConfig: s.clustersConfig,
PluginConfigPath: serveOpts.PluginConfigPath,
ClientQPS: serveOpts.QPS,
ClientBurst: serveOpts.Burst,
})
if err != nil {
return nil, fmt.Errorf("plug-in %q failed to register due to: %v", pluginDetail, err)
} else if server == nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubeapps-apis/plugins/resources/v1alpha1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
// RegisterWithGRPCServer enables a plugin to register with a gRPC server
// returning the server implementation.
func RegisterWithGRPCServer(opts pluginsv1alpha1.GRPCPluginRegistrationOptions) (interface{}, error) {
svr, err := NewServer(opts.ConfigGetter)
svr, err := NewServer(opts.ConfigGetter, opts.ClientQPS, opts.ClientBurst)
if err != nil {
return nil, err
}
Expand Down
15 changes: 5 additions & 10 deletions cmd/kubeapps-apis/plugins/resources/v1alpha1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ import (
"github.com/kubeapps/kubeapps/cmd/kubeapps-apis/plugins/pkg/statuserror"
)

const (
DISCOVERY_CLIENT_QPS = 50.0
DISCOVERY_CLIENT_BURST = 100
)

type clientGetter func(context.Context, string) (kubernetes.Interface, dynamic.Interface, error)

// Currently just a stub unimplemented server. More to come in following PRs.
Expand Down Expand Up @@ -65,7 +60,7 @@ type Server struct {
// createRESTMapper returns a rest mapper configured with the APIs of the
// local k8s API server. This is used to convert between the GroupVersionKinds
// of the resource references to the GroupVersionResource used by the API server.
func createRESTMapper() (meta.RESTMapper, error) {
func createRESTMapper(clientQPS float32, clientBurst int) (meta.RESTMapper, error) {
config, err := rest.InClusterConfig()
if err != nil {
return nil, err
Expand All @@ -79,8 +74,8 @@ func createRESTMapper() (meta.RESTMapper, error) {
// available APIs on the K8s api server. Note that this is only used for
// the discovery client below to return the rest mapper. The configured
// values for QPS and Burst are used for the client used for user requests.
config.QPS = DISCOVERY_CLIENT_QPS
config.Burst = DISCOVERY_CLIENT_BURST
config.QPS = clientQPS
config.Burst = clientBurst

client, err := rest.RESTClientFor(config)
if err != nil {
Expand All @@ -94,8 +89,8 @@ func createRESTMapper() (meta.RESTMapper, error) {
return restmapper.NewDiscoveryRESTMapper(groupResources), nil
}

func NewServer(configGetter core.KubernetesConfigGetter) (*Server, error) {
mapper, err := createRESTMapper()
func NewServer(configGetter core.KubernetesConfigGetter, clientQPS float32, clientBurst int) (*Server, error) {
mapper, err := createRESTMapper(clientQPS, clientBurst)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2a3f661

Please sign in to comment.