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 controller args for setting additional leader election options #1

Closed
Closed
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
84 changes: 51 additions & 33 deletions pkg/config/runtime_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,33 @@ import (
)

const (
flagMetricsBindAddr = "metrics-bind-addr"
flagHealthProbeBindAddr = "health-probe-bind-addr"
flagWebhookBindPort = "webhook-bind-port"
flagEnableLeaderElection = "enable-leader-election"
flagLeaderElectionID = "leader-election-id"
flagLeaderElectionNamespace = "leader-election-namespace"
flagWatchNamespace = "watch-namespace"
flagSyncPeriod = "sync-period"
flagKubeconfig = "kubeconfig"
flagWebhookCertDir = "webhook-cert-dir"
flagWebhookCertName = "webhook-cert-file"
flagWebhookKeyName = "webhook-key-file"
flagMetricsBindAddr = "metrics-bind-addr"
flagHealthProbeBindAddr = "health-probe-bind-addr"
flagWebhookBindPort = "webhook-bind-port"
flagEnableLeaderElection = "enable-leader-election"
flagLeaderElectionID = "leader-election-id"
flagLeaderElectionNamespace = "leader-election-namespace"
flagLeaderElectionLeaseDuration = "leader-election-lease-duration"
flagLeaderElectionRenewDeadline = "leader-election-renew-deadline"
flagLeaderElectionRetryPeriod = "leader-election-retry-period"
flagWatchNamespace = "watch-namespace"
flagSyncPeriod = "sync-period"
flagKubeconfig = "kubeconfig"
flagWebhookCertDir = "webhook-cert-dir"
flagWebhookCertName = "webhook-cert-file"
flagWebhookKeyName = "webhook-key-file"

defaultKubeconfig = ""
defaultLeaderElectionID = "aws-load-balancer-controller-leader"
defaultLeaderElectionNamespace = ""
defaultWatchNamespace = corev1.NamespaceAll
defaultMetricsAddr = ":8080"
defaultHealthProbeBindAddress = ":61779"
defaultSyncPeriod = 10 * time.Hour
defaultWebhookBindPort = 9443
defaultKubeconfig = ""
defaultLeaderElectionID = "aws-load-balancer-controller-leader"
defaultLeaderElectionNamespace = ""
defaultLeaderElectionLeaseDuration = 15 * time.Second
defaultLeaderElectionRenewDeadline = 10 * time.Second
defaultLeaderElectionRetryPeriod = 2 * time.Second
defaultWatchNamespace = corev1.NamespaceAll
defaultMetricsAddr = ":8080"
defaultHealthProbeBindAddress = ":61779"
defaultSyncPeriod = 10 * time.Hour
defaultWebhookBindPort = 9443
// High enough QPS to fit all expected use cases. QPS=0 is not set here, because
// client code is overriding it.
defaultQPS = 1e6
Expand All @@ -49,19 +55,22 @@ const (

// RuntimeConfig stores the configuration for the controller-runtime
type RuntimeConfig struct {
APIServer string
KubeConfig string
WebhookBindPort int
MetricsBindAddress string
HealthProbeBindAddress string
EnableLeaderElection bool
LeaderElectionID string
LeaderElectionNamespace string
WatchNamespace string
SyncPeriod time.Duration
WebhookCertDir string
WebhookCertName string
WebhookKeyName string
APIServer string
KubeConfig string
WebhookBindPort int
MetricsBindAddress string
HealthProbeBindAddress string
EnableLeaderElection bool
LeaderElectionID string
LeaderElectionNamespace string
LeaderElectionLeaseDuration time.Duration
LeaderElectionRenewDeadline time.Duration
LeaderElectionRetryPeriod time.Duration
WatchNamespace string
SyncPeriod time.Duration
WebhookCertDir string
WebhookCertName string
WebhookKeyName string
}

// BindFlags binds the command line flags to the fields in the config object
Expand All @@ -81,6 +90,12 @@ func (c *RuntimeConfig) BindFlags(fs *pflag.FlagSet) {
"Name of the leader election ID to use for this controller")
fs.StringVar(&c.LeaderElectionNamespace, flagLeaderElectionNamespace, defaultLeaderElectionNamespace,
"Name of the leader election ID to use for this controller")
fs.DurationVar(&c.LeaderElectionLeaseDuration, flagLeaderElectionLeaseDuration, defaultLeaderElectionLeaseDuration,
"The duration that non-leader candidates will wait to force acquire leadership.")
fs.DurationVar(&c.LeaderElectionRenewDeadline, flagLeaderElectionRenewDeadline, defaultLeaderElectionRenewDeadline,
"The duration that the acting controlplane will retry refreshing leadership before giving up.")
fs.DurationVar(&c.LeaderElectionRetryPeriod, flagLeaderElectionRetryPeriod, defaultLeaderElectionRetryPeriod,
"The duration the LeaderElector clients should wait between tries of actions.")
fs.StringVar(&c.WatchNamespace, flagWatchNamespace, defaultWatchNamespace,
"Namespace the controller watches for updates to Kubernetes objects, If empty, all namespaces are watched.")
fs.DurationVar(&c.SyncPeriod, flagSyncPeriod, defaultSyncPeriod,
Expand Down Expand Up @@ -122,6 +137,9 @@ func BuildRuntimeOptions(rtCfg RuntimeConfig, scheme *runtime.Scheme) ctrl.Optio
LeaderElectionResourceLock: resourcelock.ConfigMapsLeasesResourceLock,
LeaderElectionID: rtCfg.LeaderElectionID,
LeaderElectionNamespace: rtCfg.LeaderElectionNamespace,
LeaseDuration: &rtCfg.LeaderElectionLeaseDuration,
RenewDeadline: &rtCfg.LeaderElectionRenewDeadline,
RetryPeriod: &rtCfg.LeaderElectionRetryPeriod,
Namespace: rtCfg.WatchNamespace,
SyncPeriod: &rtCfg.SyncPeriod,
ClientDisableCacheFor: []client.Object{&corev1.Secret{}},
Expand Down
Loading