mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-06 01:07:03 +00:00
disable leader election for grpc server (#1468)
Signed-off-by: Wei Liu <liuweixa@redhat.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package hub
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/openshift/library-go/pkg/controller/controllercmd"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/utils/clock"
|
||||
|
||||
@@ -14,7 +15,11 @@ import (
|
||||
func NewGRPCServerCommand() *cobra.Command {
|
||||
opts := commonoptions.NewOptions()
|
||||
grpcServerOpts := grpc.NewGRPCServerOptions()
|
||||
cmdConfig := opts.NewControllerCommandConfig("grpc-server", version.Get(), grpcServerOpts.Run, clock.RealClock{})
|
||||
|
||||
// Disable leader election to allow multiple gRPC server instances to run concurrently.
|
||||
cmdConfig := controllercmd.NewControllerCommandConfig("grpc-server", version.Get(), opts.StartWithQPS(grpcServerOpts.Run), clock.RealClock{})
|
||||
cmdConfig.DisableLeaderElection = true
|
||||
|
||||
cmd := cmdConfig.NewCommandWithContext(context.TODO())
|
||||
cmd.Use = "grpc"
|
||||
cmd.Short = "Start the gRPC Server"
|
||||
|
||||
@@ -35,11 +35,11 @@ func NewOptions() *Options {
|
||||
|
||||
func (o *Options) NewControllerCommandConfig(
|
||||
componentName string, version version.Info, startFunc controllercmd.StartFunc, clock clock.Clock) *controllercmd.ControllerCommandConfig {
|
||||
o.CmdConfig = controllercmd.NewControllerCommandConfig(componentName, version, o.startWithQPS(startFunc), clock)
|
||||
o.CmdConfig = controllercmd.NewControllerCommandConfig(componentName, version, o.StartWithQPS(startFunc), clock)
|
||||
return o.CmdConfig
|
||||
}
|
||||
|
||||
func (o *Options) startWithQPS(startFunc controllercmd.StartFunc) controllercmd.StartFunc {
|
||||
func (o *Options) StartWithQPS(startFunc controllercmd.StartFunc) controllercmd.StartFunc {
|
||||
return func(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
|
||||
controllerContext.KubeConfig.QPS = o.QPS
|
||||
controllerContext.KubeConfig.Burst = o.Burst
|
||||
|
||||
Reference in New Issue
Block a user