Skip to content

Commit

Permalink
Add default controller leader election setting values
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Marcantonio <jmarcant@redhat.com>

Add controller leader election settings configurability

Signed-off-by: Jonathan Marcantonio <jmarcant@redhat.com>

Add leader-election-lease-duration

Signed-off-by: Jonathan Marcantonio <jmarcant@redhat.com>
  • Loading branch information
lennysgarage committed Aug 23, 2022
1 parent fd29e04 commit 8152465
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 11 deletions.
7 changes: 7 additions & 0 deletions cmd/appsubsummary/exec/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package exec
import (
"fmt"
"os"
"time"

"k8s.io/client-go/rest"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -62,13 +63,19 @@ func RunManager() {
}
}

leaderElectionLeaseDuration := time.Duration(options.LeaderElectionLeaseDurationSeconds) * time.Second
renewDeadline := time.Duration(options.RenewDeadlineSeconds) * time.Second
retryPeriod := time.Duration(options.RetryPeriodSeconds) * time.Second
// Create a new Cmd to provide shared dependencies and start components
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Port: operatorMetricsPort,
LeaderElection: enableLeaderElection,
LeaderElectionID: "multicloud-operators-appsubsummary-leader.open-cluster-management.io",
LeaderElectionNamespace: "kube-system",
LeaseDuration: &leaderElectionLeaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
})
if err != nil {
klog.Error(err, "")
Expand Down
48 changes: 42 additions & 6 deletions cmd/appsubsummary/exec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ import (

// AppSubStatusCMDOptions for command line flag parsing.
type AppSubStatusCMDOptions struct {
MetricsAddr string
KubeConfig string
SyncInterval int
MetricsAddr string
KubeConfig string
SyncInterval int
LeaseDurationSeconds int
LeaderElectionLeaseDurationSeconds int
RenewDeadlineSeconds int
RetryPeriodSeconds int
}

var options = AppSubStatusCMDOptions{
MetricsAddr: "",
KubeConfig: "",
SyncInterval: 15,
MetricsAddr: "",
KubeConfig: "",
SyncInterval: 15,
LeaseDurationSeconds: 60,
LeaderElectionLeaseDurationSeconds: 137,
RenewDeadlineSeconds: 107,
RetryPeriodSeconds: 26,
}

// ProcessFlags parses command line parameters into options.
Expand All @@ -55,4 +63,32 @@ func ProcessFlags() {
options.KubeConfig,
"The kube config that points to a external api server.",
)

flag.IntVar(
&options.LeaseDurationSeconds,
"lease-duration",
options.LeaseDurationSeconds,
"The lease duration in seconds.",
)

flag.IntVar(
&options.LeaderElectionLeaseDurationSeconds,
"leader-election-lease-duration",
options.LeaderElectionLeaseDurationSeconds,
"The leader election lease duration in seconds.",
)

flag.IntVar(
&options.RenewDeadlineSeconds,
"renew-deadline",
options.RenewDeadlineSeconds,
"The renew deadline in seconds.",
)

flag.IntVar(
&options.RetryPeriodSeconds,
"retry-period",
options.RetryPeriodSeconds,
"The retry period in seconds.",
)
}
6 changes: 6 additions & 0 deletions cmd/manager/exec/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,19 @@ func RunManager() {
cfg.QPS = 100.0
cfg.Burst = 200

leaseDuration := time.Duration(Options.LeaseDurationSeconds) * time.Second
renewDeadline := time.Duration(Options.RenewDeadlineSeconds) * time.Second
retryPeriod := time.Duration(Options.RetryPeriodSeconds) * time.Second
// Create a new Cmd to provide shared dependencies and start components
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Port: operatorMetricsPort,
LeaderElection: enableLeaderElection,
LeaderElectionID: leaderElectionID,
LeaderElectionNamespace: "kube-system",
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
})

if err != nil {
Expand Down
20 changes: 19 additions & 1 deletion cmd/manager/exec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type SubscriptionCMDOptions struct {
Standalone bool
AgentImage string
LeaseDurationSeconds int
RenewDeadlineSeconds int
RetryPeriodSeconds int
Debug bool
AgentInstallAll bool
}
Expand All @@ -39,7 +41,9 @@ var Options = SubscriptionCMDOptions{
MetricsAddr: "",
KubeConfig: "",
SyncInterval: 60,
LeaseDurationSeconds: 60,
LeaseDurationSeconds: 137,
RenewDeadlineSeconds: 107,
RetryPeriodSeconds: 26,
Standalone: false,
AgentImage: "quay.io/open-cluster-management/multicloud-operators-subscription:latest",
Debug: false,
Expand Down Expand Up @@ -91,6 +95,20 @@ func ProcessFlags() {
"The lease duration in seconds.",
)

flag.IntVar(
&Options.RenewDeadlineSeconds,
"renew-deadline",
Options.RenewDeadlineSeconds,
"The renew deadline in seconds.",
)

flag.IntVar(
&Options.RetryPeriodSeconds,
"retry-period",
Options.RetryPeriodSeconds,
"The retry period in seconds.",
)

flag.BoolVar(
&Options.Standalone,
"standalone",
Expand Down
7 changes: 7 additions & 0 deletions cmd/placementrule/exec/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package exec
import (
"fmt"
"os"
"time"

"open-cluster-management.io/multicloud-operators-subscription/pkg/apis"
"open-cluster-management.io/multicloud-operators-subscription/pkg/placementrule/controller"
Expand Down Expand Up @@ -67,12 +68,18 @@ func RunManager() {
cfg.QPS = 30.0
cfg.Burst = 60

leaseDuration := time.Duration(options.LeaseDurationSeconds) * time.Second
renewDeadline := time.Duration(options.RenewDeadlineSeconds) * time.Second
retryPeriod := time.Duration(options.RetryPeriodSeconds) * time.Second
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Port: operatorMetricsPort,
LeaderElection: enableLeaderElection,
LeaderElectionID: "multicloud-operators-placementrule-leader.open-cluster-management.io",
LeaderElectionNamespace: "kube-system",
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
})

if err != nil {
Expand Down
35 changes: 31 additions & 4 deletions cmd/placementrule/exec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ import (

// PlacementRuleCMDOptions for command line flag parsing
type PlacementRuleCMDOptions struct {
MetricsAddr string
KubeConfig string
MetricsAddr string
KubeConfig string
LeaseDurationSeconds int
RenewDeadlineSeconds int
RetryPeriodSeconds int
}

var options = PlacementRuleCMDOptions{
MetricsAddr: "",
KubeConfig: "",
MetricsAddr: "",
KubeConfig: "",
LeaseDurationSeconds: 137,
RenewDeadlineSeconds: 107,
RetryPeriodSeconds: 26,
}

// ProcessFlags parses command line parameters into options
Expand All @@ -46,4 +52,25 @@ func ProcessFlags() {
options.KubeConfig,
"The kube config that points to a external api server.",
)

flag.IntVar(
&options.LeaseDurationSeconds,
"lease-duration",
options.LeaseDurationSeconds,
"The lease duration in seconds.",
)

flag.IntVar(
&options.RenewDeadlineSeconds,
"renew-deadline",
options.RenewDeadlineSeconds,
"The renew deadline in seconds.",
)

flag.IntVar(
&options.RetryPeriodSeconds,
"retry-period",
options.RetryPeriodSeconds,
"The retry period in seconds.",
)
}

0 comments on commit 8152465

Please sign in to comment.