From 4334762add602df8e02c0be272cc86054b28ef2f Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Tue, 18 Jan 2022 11:16:05 +0800 Subject: [PATCH] Add disable leader election flag (#109) Signed-off-by: Jian Qiu --- deploy/spoke/deployment.yaml | 1 + pkg/cmd/spoke/agent.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/deploy/spoke/deployment.yaml b/deploy/spoke/deployment.yaml index 50c2c14f8..2a3957b71 100644 --- a/deploy/spoke/deployment.yaml +++ b/deploy/spoke/deployment.yaml @@ -24,6 +24,7 @@ spec: - "agent" - "--spoke-cluster-name=cluster1" - "--hub-kubeconfig=/spoke/hub-kubeconfig/kubeconfig" + - "--disable-leader-election" securityContext: allowPrivilegeEscalation: false capabilities: diff --git a/pkg/cmd/spoke/agent.go b/pkg/cmd/spoke/agent.go index 1ea8a5b4e..f314382ed 100644 --- a/pkg/cmd/spoke/agent.go +++ b/pkg/cmd/spoke/agent.go @@ -12,12 +12,17 @@ import ( // NewWorkloadAgent generates a command to start workload agent func NewWorkloadAgent() *cobra.Command { o := spoke.NewWorkloadAgentOptions() - cmd := controllercmd. - NewControllerCommandConfig("work-agent", version.Get(), o.RunWorkloadAgent). - NewCommand() + cmdConfig := controllercmd. + NewControllerCommandConfig("work-agent", version.Get(), o.RunWorkloadAgent) + cmd := cmdConfig.NewCommand() cmd.Use = "agent" cmd.Short = "Start the Cluster Registration Agent" o.AddFlags(cmd) + + // add disable leader election flag + flags := cmd.Flags() + flags.BoolVar(&cmdConfig.DisableLeaderElection, "disable-leader-election", false, "Disable leader election for the agent.") + return cmd }