From 8329d0164e7ac89490dfab7d571273426932db01 Mon Sep 17 00:00:00 2001 From: Andrew Rudoi Date: Wed, 18 Mar 2020 09:39:40 -0700 Subject: [PATCH] chore: expose leader election parameters as flags Co-Authored-By: Andrew Rudoi Co-Authored-By: Roger Torrentsgeneros --- bootstrap/kubeadm/main.go | 29 +++++++++++++++++++------- controlplane/kubeadm/main.go | 15 +++++++++++++ main.go | 15 +++++++++++++ third_party/kubernetes-drain/README.md | 2 +- third_party/kubernetes-drain/drain.go | 1 - 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/bootstrap/kubeadm/main.go b/bootstrap/kubeadm/main.go index 6dc9b07b0f0f..d7f9b7249c86 100644 --- a/bootstrap/kubeadm/main.go +++ b/bootstrap/kubeadm/main.go @@ -59,13 +59,16 @@ func init() { } var ( - metricsAddr string - enableLeaderElection bool - watchNamespace string - profilerAddress string - kubeadmConfigConcurrency int - syncPeriod time.Duration - webhookPort int + metricsAddr string + enableLeaderElection bool + leaderElectionLeaseDuration time.Duration + leaderElectionRenewDeadline time.Duration + leaderElectionRetryPeriod time.Duration + watchNamespace string + profilerAddress string + kubeadmConfigConcurrency int + syncPeriod time.Duration + webhookPort int ) func InitFlags(fs *pflag.FlagSet) { @@ -75,6 +78,15 @@ func InitFlags(fs *pflag.FlagSet) { fs.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") + fs.DurationVar(&leaderElectionLeaseDuration, "leader-election-lease-duration", 15*time.Second, + "Interval at which non-leader candidates will wait to force acquire leadership (duration string)") + + fs.DurationVar(&leaderElectionRenewDeadline, "leader-election-renew-deadline", 10*time.Second, + "Duration that the acting master will retry refreshing leadership before giving up (duration string)") + + fs.DurationVar(&leaderElectionRetryPeriod, "leader-election-retry-period", 2*time.Second, + "Duration the LeaderElector clients should wait between tries of actions (duration string)") + fs.StringVar(&watchNamespace, "namespace", "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") @@ -115,6 +127,9 @@ func main() { MetricsBindAddress: metricsAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "kubeadm-bootstrap-manager-leader-election-capi", + LeaseDuration: &leaderElectionLeaseDuration, + RenewDeadline: &leaderElectionRenewDeadline, + RetryPeriod: &leaderElectionRetryPeriod, Namespace: watchNamespace, SyncPeriod: &syncPeriod, NewClient: newClientFunc, diff --git a/controlplane/kubeadm/main.go b/controlplane/kubeadm/main.go index 0ca4d4248bb4..a2a660b8664a 100644 --- a/controlplane/kubeadm/main.go +++ b/controlplane/kubeadm/main.go @@ -58,6 +58,9 @@ func init() { var ( metricsAddr string enableLeaderElection bool + leaderElectionLeaseDuration time.Duration + leaderElectionRenewDeadline time.Duration + leaderElectionRetryPeriod time.Duration watchNamespace string profilerAddress string kubeadmControlPlaneConcurrency int @@ -73,6 +76,15 @@ func InitFlags(fs *pflag.FlagSet) { fs.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") + fs.DurationVar(&leaderElectionLeaseDuration, "leader-election-lease-duration", 15*time.Second, + "Interval at which non-leader candidates will wait to force acquire leadership (duration string)") + + fs.DurationVar(&leaderElectionRenewDeadline, "leader-election-renew-deadline", 10*time.Second, + "Duration that the acting master will retry refreshing leadership before giving up (duration string)") + + fs.DurationVar(&leaderElectionRetryPeriod, "leader-election-retry-period", 2*time.Second, + "Duration the LeaderElector clients should wait between tries of actions (duration string)") + fs.StringVar(&watchNamespace, "namespace", "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") @@ -107,6 +119,9 @@ func main() { MetricsBindAddress: metricsAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "kubeadm-control-plane-manager-leader-election-capi", + LeaseDuration: &leaderElectionLeaseDuration, + RenewDeadline: &leaderElectionRenewDeadline, + RetryPeriod: &leaderElectionRetryPeriod, Namespace: watchNamespace, SyncPeriod: &syncPeriod, NewClient: newClientFunc, diff --git a/main.go b/main.go index 565e6aeb5079..252c0c19d880 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,9 @@ var ( // flags metricsAddr string enableLeaderElection bool + leaderElectionLeaseDuration time.Duration + leaderElectionRenewDeadline time.Duration + leaderElectionRetryPeriod time.Duration watchNamespace string profilerAddress string clusterConcurrency int @@ -82,6 +85,15 @@ func InitFlags(fs *pflag.FlagSet) { fs.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") + fs.DurationVar(&leaderElectionLeaseDuration, "leader-election-lease-duration", 15*time.Second, + "Interval at which non-leader candidates will wait to force acquire leadership (duration string)") + + fs.DurationVar(&leaderElectionRenewDeadline, "leader-election-renew-deadline", 10*time.Second, + "Duration that the acting master will retry refreshing leadership before giving up (duration string)") + + fs.DurationVar(&leaderElectionRetryPeriod, "leader-election-retry-period", 2*time.Second, + "Duration the LeaderElector clients should wait between tries of actions (duration string)") + fs.StringVar(&watchNamespace, "namespace", "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") @@ -137,6 +149,9 @@ func main() { MetricsBindAddress: metricsAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "controller-leader-election-capi", + LeaseDuration: &leaderElectionLeaseDuration, + RenewDeadline: &leaderElectionRenewDeadline, + RetryPeriod: &leaderElectionRetryPeriod, Namespace: watchNamespace, SyncPeriod: &syncPeriod, NewClient: newClientFunc, diff --git a/third_party/kubernetes-drain/README.md b/third_party/kubernetes-drain/README.md index b512a5c7920d..946e9b65288e 100644 --- a/third_party/kubernetes-drain/README.md +++ b/third_party/kubernetes-drain/README.md @@ -1,2 +1,2 @@ The code in this directory has been copied from: -github.com/kubernetes/kubectl/pkg/drain@846b394714fe1cb467fca0e259890b8ba2ec4544 +github.com/kubernetes/kubectl/pkg/drain@a17d91f9f5b34c73bed0bfc75b70bd762b725231 diff --git a/third_party/kubernetes-drain/drain.go b/third_party/kubernetes-drain/drain.go index 8992a3ae522d..0ade8ebeb5c4 100644 --- a/third_party/kubernetes-drain/drain.go +++ b/third_party/kubernetes-drain/drain.go @@ -357,7 +357,6 @@ func waitForDelete(params waitForDeleteParams) ([]corev1.Pod, error) { default: return false, nil } - return false, nil } return true, nil })