set leader election client timeout

pull/8/head
xuzhonghu 2018-06-14 17:55:29 +08:00
parent f0c89c00a0
commit 7c6213e922
2 changed files with 11 additions and 4 deletions

View File

@ -432,7 +432,10 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy
return nil, err
}
leaderElectionClient := clientset.NewForConfigOrDie(restclient.AddUserAgent(kubeconfig, "leader-election"))
// shallow copy, do not modify the kubeconfig.Timeout.
config := *kubeconfig
config.Timeout = s.GenericComponent.LeaderElection.RenewDeadline.Duration
leaderElectionClient := clientset.NewForConfigOrDie(restclient.AddUserAgent(&config, "leader-election"))
eventRecorder := createRecorder(client, KubeControllerManagerUserAgent)

View File

@ -21,6 +21,7 @@ import (
"net"
"os"
"strconv"
"time"
"github.com/golang/glog"
"github.com/spf13/pflag"
@ -203,7 +204,7 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) {
}
// prepare kube clients.
client, leaderElectionClient, eventClient, err := createClients(c.ComponentConfig.ClientConnection, o.Master)
client, leaderElectionClient, eventClient, err := createClients(o.ComponentConfig.ClientConnection, o.Master, o.ComponentConfig.LeaderElection.RenewDeadline.Duration)
if err != nil {
return nil, err
}
@ -264,7 +265,7 @@ func makeLeaderElectionConfig(config componentconfig.KubeSchedulerLeaderElection
// createClients creates a kube client and an event client from the given config and masterOverride.
// TODO remove masterOverride when CLI flags are removed.
func createClients(config componentconfig.ClientConnectionConfiguration, masterOverride string) (clientset.Interface, clientset.Interface, v1core.EventsGetter, error) {
func createClients(config componentconfig.ClientConnectionConfiguration, masterOverride string, timeout time.Duration) (clientset.Interface, clientset.Interface, v1core.EventsGetter, error) {
if len(config.KubeConfigFile) == 0 && len(masterOverride) == 0 {
glog.Warningf("Neither --kubeconfig nor --master was specified. Using default API client. This might not work.")
}
@ -289,7 +290,10 @@ func createClients(config componentconfig.ClientConnectionConfiguration, masterO
return nil, nil, nil, err
}
leaderElectionClient, err := clientset.NewForConfig(restclient.AddUserAgent(kubeConfig, "leader-election"))
// shallow copy, do not modify the kubeConfig.Timeout.
restConfig := *kubeConfig
restConfig.Timeout = timeout
leaderElectionClient, err := clientset.NewForConfig(restclient.AddUserAgent(&restConfig, "leader-election"))
if err != nil {
return nil, nil, nil, err
}