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

feat: make LeaseDuration configurable via --leader-election-lease-duration flag #3835

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/deploy/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Currently, you can set only 1 namespace to watch in this flag. See [this Kuberne
| kubeconfig | string | in-cluster config | Path to the kubeconfig file containing authorization and API server information |
| leader-election-id | string | aws-load-balancer-controller-leader | Name of the leader election ID to use for this controller |
| leader-election-namespace | string | | Name of the leader election ID to use for this controller |
| leader-election-lease-duration | duration | 15s | The duration that non-leader candidates will wait to force acquire leadership. |
| load-balancer-class | string | service.k8s.aws/nlb | Name of the load balancer class specified in service `spec.loadBalancerClass` reconciled by this controller |
| log-level | string | info | Set the controller log level - info, debug |
| metrics-bind-addr | string | :8080 | The address the metric endpoint binds to |
Expand Down
3 changes: 3 additions & 0 deletions helm/aws-load-balancer-controller/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ spec:
{{- if .Values.loadBalancerClass }}
- --load-balancer-class={{ .Values.loadBalancerClass }}
{{- end }}
{{- if .Values.leaseDuration }}
- --leader-election-lease-duration={{ .Values.leaseDuration }}
{{- end }}
{{- if or .Values.env .Values.envSecretName }}
env:
{{- if .Values.env}}
Expand Down
3 changes: 3 additions & 0 deletions helm/aws-load-balancer-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,8 @@ serviceTargetENISGTags:
# Specifies the class of load balancer to use for services. This affects how services are provisioned if type LoadBalancer is used (default service.k8s.aws/nlb)
loadBalancerClass:

# Specifies the duration that non-leader candidates will wait to force acquire leadership. (default 15s)
leaseDuration: 15s

# creator will disable helm default labels, so you can only add yours
# creator: "me"
73 changes: 39 additions & 34 deletions pkg/config/runtime_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ 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"
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
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 @@ -52,19 +54,20 @@ 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
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 @@ -91,7 +94,8 @@ func (c *RuntimeConfig) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&c.WebhookCertDir, flagWebhookCertDir, defaultWebhookCertDir, "WebhookCertDir is the directory that contains the webhook server key and certificate.")
fs.StringVar(&c.WebhookCertName, flagWebhookCertName, defaultWebhookCertName, "WebhookCertName is the webhook server certificate name.")
fs.StringVar(&c.WebhookKeyName, flagWebhookKeyName, defaultWebhookKeyName, "WebhookKeyName is the webhook server key name.")

fs.DurationVar(&c.LeaderElectionLeaseDuration, flagLeaderElectionLeaseDuration, defaultLeaderElectionLeaseDuration,
"The duration that non-leader candidates will wait to force acquire leadership.")
}

// BuildRestConfig builds the REST config for the controller runtime
Expand Down Expand Up @@ -122,6 +126,7 @@ func BuildRuntimeOptions(rtCfg RuntimeConfig, scheme *runtime.Scheme) ctrl.Optio
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionID: rtCfg.LeaderElectionID,
LeaderElectionNamespace: rtCfg.LeaderElectionNamespace,
LeaseDuration: &rtCfg.LeaderElectionLeaseDuration,
Cache: cache.Options{
SyncPeriod: &rtCfg.SyncPeriod,
},
Expand Down