Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default controller leader election setting values #242

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
}
}

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: "multicloud-operators-appsubsummary-leader.open-cluster-management.io",
LeaderElectionNamespace: "kube-system",
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
})
if err != nil {
klog.Error(err, "")
Expand Down
39 changes: 33 additions & 6 deletions cmd/appsubsummary/exec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ import (

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

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

// ProcessFlags parses command line parameters into options.
Expand All @@ -55,4 +61,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.",
)
}
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

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: leaderElectionID,
LeaderElectionNamespace: "kube-system",
LeaseDuration: &leaderElectionLeaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
})

if err != nil {
Expand Down
67 changes: 47 additions & 20 deletions cmd/manager/exec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,35 @@ import (

// SubscriptionCMDOptions for command line flag parsing
type SubscriptionCMDOptions struct {
MetricsAddr string
KubeConfig string
ClusterName string
HubConfigFilePathName string
TLSKeyFilePathName string
TLSCrtFilePathName string
SyncInterval int
DisableTLS bool
Standalone bool
AgentImage string
LeaseDurationSeconds int
Debug bool
AgentInstallAll bool
MetricsAddr string
KubeConfig string
ClusterName string
HubConfigFilePathName string
TLSKeyFilePathName string
TLSCrtFilePathName string
SyncInterval int
DisableTLS bool
Standalone bool
AgentImage string
LeaseDurationSeconds int
LeaderElectionLeaseDurationSeconds int
RenewDeadlineSeconds int
RetryPeriodSeconds int
Debug bool
AgentInstallAll bool
}

var Options = SubscriptionCMDOptions{
MetricsAddr: "",
KubeConfig: "",
SyncInterval: 60,
LeaseDurationSeconds: 60,
Standalone: false,
AgentImage: "quay.io/open-cluster-management/multicloud-operators-subscription:latest",
Debug: false,
MetricsAddr: "",
KubeConfig: "",
SyncInterval: 60,
LeaseDurationSeconds: 60,
LeaderElectionLeaseDurationSeconds: 137,
RenewDeadlineSeconds: 107,
RetryPeriodSeconds: 26,
Standalone: false,
AgentImage: "quay.io/open-cluster-management/multicloud-operators-subscription:latest",
Debug: false,
}

// ProcessFlags parses command line parameters into Options
Expand Down Expand Up @@ -91,6 +97,27 @@ func ProcessFlags() {
"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.",
)

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.",
)
}