From d72c0e162789e1bbb33c33cfa26858a1375efe01 Mon Sep 17 00:00:00 2001 From: Kubernetes Publisher Date: Sat, 15 Oct 2016 19:23:47 +0000 Subject: [PATCH] published by bot (https://github.com/kubernetes/contrib/tree/master/mungegithub) Directory 1.4 is copied from https://github.com/kubernetes/kubernetes.git, branch release-1.4, last commit is fc3dab7de68c15de3421896dd051c2f127fb64ab Directory 1.5 is copied from https://github.com/kubernetes/kubernetes.git, branch master, last commit is c32a05333b389be88ae51db6087db760bac6ed22 --- 1.5/rest/config.go | 4 ++++ 1.5/tools/clientcmd/client_config.go | 14 ++++++++++++++ 1.5/tools/clientcmd/overrides.go | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/1.5/rest/config.go b/1.5/rest/config.go index 5c5e1e03..41609617 100644 --- a/1.5/rest/config.go +++ b/1.5/rest/config.go @@ -25,6 +25,7 @@ import ( "path" gruntime "runtime" "strings" + "time" "github.com/golang/glog" @@ -109,6 +110,9 @@ type Config struct { // Rate limiter for limiting connections to the master from this client. If present overwrites QPS/Burst RateLimiter flowcontrol.RateLimiter + // The maximum length of time to wait before giving up on a server request. A value of zero means no timeout. + Timeout time.Duration + // Version forces a specific version to be used (if registered) // Do we need this? // Version string diff --git a/1.5/tools/clientcmd/client_config.go b/1.5/tools/clientcmd/client_config.go index a8b21768..1b300221 100644 --- a/1.5/tools/clientcmd/client_config.go +++ b/1.5/tools/clientcmd/client_config.go @@ -27,6 +27,9 @@ import ( "github.com/golang/glog" "github.com/imdario/mergo" + "strconv" + "time" + "k8s.io/client-go/1.5/pkg/api" "k8s.io/client-go/1.5/rest" clientauth "k8s.io/client-go/1.5/tools/auth" @@ -108,6 +111,17 @@ func (config *DirectClientConfig) ClientConfig() (*rest.Config, error) { clientConfig := &rest.Config{} clientConfig.Host = configClusterInfo.Server + + if len(config.overrides.Timeout) > 0 { + if i, err := strconv.ParseInt(config.overrides.Timeout, 10, 64); err == nil && i >= 0 { + clientConfig.Timeout = time.Duration(i) * time.Second + } else if requestTimeout, err := time.ParseDuration(config.overrides.Timeout); err == nil { + clientConfig.Timeout = requestTimeout + } else { + return nil, fmt.Errorf("Invalid value for option '--request-timeout'. Value must be a single integer, or an integer followed by a corresponding time unit (e.g. 1s | 2m | 3h)") + } + } + if u, err := url.ParseRequestURI(clientConfig.Host); err == nil && u.Opaque == "" && len(u.Path) > 1 { u.RawQuery = "" u.Fragment = "" diff --git a/1.5/tools/clientcmd/overrides.go b/1.5/tools/clientcmd/overrides.go index 304242f6..c81a7dd5 100644 --- a/1.5/tools/clientcmd/overrides.go +++ b/1.5/tools/clientcmd/overrides.go @@ -33,6 +33,7 @@ type ConfigOverrides struct { ClusterInfo clientcmdapi.Cluster Context clientcmdapi.Context CurrentContext string + Timeout string } // ConfigOverrideFlags holds the flag names to be used for binding command line flags. Notice that this structure tightly @@ -42,6 +43,7 @@ type ConfigOverrideFlags struct { ClusterOverrideFlags ClusterOverrideFlags ContextOverrideFlags ContextOverrideFlags CurrentContext FlagInfo + Timeout FlagInfo } // AuthOverrideFlags holds the flag names to be used for binding command line flags for AuthInfo objects @@ -121,6 +123,7 @@ const ( FlagImpersonate = "as" FlagUsername = "username" FlagPassword = "password" + FlagTimeout = "request-timeout" ) // RecommendedAuthOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing @@ -151,7 +154,9 @@ func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags { AuthOverrideFlags: RecommendedAuthOverrideFlags(prefix), ClusterOverrideFlags: RecommendedClusterOverrideFlags(prefix), ContextOverrideFlags: RecommendedContextOverrideFlags(prefix), - CurrentContext: FlagInfo{prefix + FlagContext, "", "", "The name of the kubeconfig context to use"}, + + CurrentContext: FlagInfo{prefix + FlagContext, "", "", "The name of the kubeconfig context to use"}, + Timeout: FlagInfo{prefix + FlagTimeout, "", "0", "The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests."}, } } @@ -190,6 +195,7 @@ func BindOverrideFlags(overrides *ConfigOverrides, flags *pflag.FlagSet, flagNam BindClusterFlags(&overrides.ClusterInfo, flags, flagNames.ClusterOverrideFlags) BindContextFlags(&overrides.Context, flags, flagNames.ContextOverrideFlags) flagNames.CurrentContext.BindStringFlag(flags, &overrides.CurrentContext) + flagNames.Timeout.BindStringFlag(flags, &overrides.Timeout) } // BindFlags is a convenience method to bind the specified flags to their associated variables