disable leader election for grpc server (#1468)

Signed-off-by: Wei Liu <liuweixa@redhat.com>
This commit is contained in:
Wei Liu
2026-04-02 16:25:46 +08:00
committed by GitHub
parent 19f46b6a44
commit 6117a3e553
2 changed files with 8 additions and 3 deletions

View File

@@ -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"

View File

@@ -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