Skip to content

Commit

Permalink
add controller args for setting additional leader election options
Browse files Browse the repository at this point in the history
  • Loading branch information
SNPI-Thomas-Zhang committed Oct 31, 2023
1 parent 5a5885b commit 687c632
Showing 1 changed file with 51 additions and 33 deletions.
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

0 comments on commit 687c632

Please sign in to comment.