From 6cd0449015f89011e4baf3a6c43b6531614b9596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Przychodze=C5=84?= Date: Thu, 14 Jan 2021 11:33:58 +0100 Subject: [PATCH] [cloud-controller-manager] Lower timeout for leaderelection resourcelock Migrate how resource lock and leader election config is generated to new way, hidding kubeClient. This also halfs kubeClient timeout, making it an useful value. If timeout is equal to RenewDeadline and we hit client timeout on request, there will be no retry, as RenewDeadline part will cancel the context and lose leader election. So setting a timeout to value at least equal to RenewDeadline is pointless. Setting it as half of RenewDeadline is a heuristic to resolve this missing retry problem without adding additional parameter --- staging/src/k8s.io/cloud-provider/app/config/config.go | 3 --- .../src/k8s.io/cloud-provider/app/controllermanager.go | 8 ++++---- staging/src/k8s.io/cloud-provider/options/options.go | 2 -- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/staging/src/k8s.io/cloud-provider/app/config/config.go b/staging/src/k8s.io/cloud-provider/app/config/config.go index be6ad618949..d6971adcac7 100644 --- a/staging/src/k8s.io/cloud-provider/app/config/config.go +++ b/staging/src/k8s.io/cloud-provider/app/config/config.go @@ -42,9 +42,6 @@ type Config struct { // the general kube client Client *clientset.Clientset - // the client only used for leader election - LeaderElectionClient *clientset.Clientset - // the rest config for the master Kubeconfig *restclient.Config diff --git a/staging/src/k8s.io/cloud-provider/app/controllermanager.go b/staging/src/k8s.io/cloud-provider/app/controllermanager.go index 27b06ffaf09..7c7e9a90061 100644 --- a/staging/src/k8s.io/cloud-provider/app/controllermanager.go +++ b/staging/src/k8s.io/cloud-provider/app/controllermanager.go @@ -186,15 +186,15 @@ func Run(c *cloudcontrollerconfig.CompletedConfig, controllerInitializers map[st id = id + "_" + string(uuid.NewUUID()) // Lock required for leader election - rl, err := resourcelock.New(c.ComponentConfig.Generic.LeaderElection.ResourceLock, + rl, err := resourcelock.NewFromKubeconfig(c.ComponentConfig.Generic.LeaderElection.ResourceLock, c.ComponentConfig.Generic.LeaderElection.ResourceNamespace, c.ComponentConfig.Generic.LeaderElection.ResourceName, - c.LeaderElectionClient.CoreV1(), - c.LeaderElectionClient.CoordinationV1(), resourcelock.ResourceLockConfig{ Identity: id, EventRecorder: c.EventRecorder, - }) + }, + c.Kubeconfig, + c.ComponentConfig.Generic.LeaderElection.RenewDeadline.Duration) if err != nil { klog.Fatalf("error creating lock: %v", err) } diff --git a/staging/src/k8s.io/cloud-provider/options/options.go b/staging/src/k8s.io/cloud-provider/options/options.go index 6f852d8ec87..b156011c995 100644 --- a/staging/src/k8s.io/cloud-provider/options/options.go +++ b/staging/src/k8s.io/cloud-provider/options/options.go @@ -188,8 +188,6 @@ func (o *CloudControllerManagerOptions) ApplyTo(c *config.Config, userAgent stri return err } - c.LeaderElectionClient = clientset.NewForConfigOrDie(restclient.AddUserAgent(c.Kubeconfig, "leader-election")) - c.EventRecorder = createRecorder(c.Client, userAgent) rootClientBuilder := clientbuilder.SimpleControllerClientBuilder{