mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #5635 from ravigadde/master
Add timeout to kubelet client
This commit is contained in:
commit
984bc8d5f6
@ -100,6 +100,7 @@ func NewAPIServer() *APIServer {
|
||||
KubeletConfig: client.KubeletConfig{
|
||||
Port: 10250,
|
||||
EnableHttps: false,
|
||||
HTTPTimeout: time.Duration(5) * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,7 @@ func NewCMServer() *CMServer {
|
||||
KubeletConfig: client.KubeletConfig{
|
||||
Port: ports.KubeletPort,
|
||||
EnableHttps: false,
|
||||
HTTPTimeout: time.Duration(5) * time.Second,
|
||||
},
|
||||
}
|
||||
return &s
|
||||
|
@ -16,12 +16,17 @@ limitations under the License.
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// FlagSet abstracts the flag interface for compatibility with both Golang "flag"
|
||||
// and cobra pflags (Posix style).
|
||||
type FlagSet interface {
|
||||
StringVar(p *string, name, value, usage string)
|
||||
BoolVar(p *bool, name string, value bool, usage string)
|
||||
UintVar(p *uint, name string, value uint, usage string)
|
||||
DurationVar(p *time.Duration, name string, value time.Duration, usage string)
|
||||
}
|
||||
|
||||
// BindClientConfigFlags registers a standard set of CLI flags for connecting to a Kubernetes API server.
|
||||
@ -38,6 +43,7 @@ func BindClientConfigFlags(flags FlagSet, config *Config) {
|
||||
func BindKubeletClientConfigFlags(flags FlagSet, config *KubeletConfig) {
|
||||
flags.BoolVar(&config.EnableHttps, "kubelet_https", config.EnableHttps, "Use https for kubelet connections")
|
||||
flags.UintVar(&config.Port, "kubelet_port", config.Port, "Kubelet port")
|
||||
flags.DurationVar(&config.HTTPTimeout, "kubelet_timeout", config.HTTPTimeout, "Timeout for kubelet operations")
|
||||
flags.StringVar(&config.CertFile, "kubelet_client_certificate", config.CertFile, "Path to a client key file for TLS.")
|
||||
flags.StringVar(&config.KeyFile, "kubelet_client_key", config.KeyFile, "Path to a client key file for TLS.")
|
||||
flags.StringVar(&config.CAFile, "kubelet_certificate_authority", config.CAFile, "Path to a cert. file for the certificate authority.")
|
||||
|
@ -18,6 +18,7 @@ package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
@ -57,6 +58,16 @@ func (f *fakeFlagSet) UintVar(p *uint, name string, value uint, usage string) {
|
||||
f.set.Insert(name)
|
||||
}
|
||||
|
||||
func (f *fakeFlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
|
||||
if p == nil {
|
||||
f.t.Errorf("unexpected nil pointer")
|
||||
}
|
||||
if usage == "" {
|
||||
f.t.Errorf("unexpected empty usage")
|
||||
}
|
||||
f.set.Insert(name)
|
||||
}
|
||||
|
||||
func TestBindClientConfigFlags(t *testing.T) {
|
||||
flags := &fakeFlagSet{t, util.StringSet{}}
|
||||
config := &Config{}
|
||||
@ -70,7 +81,7 @@ func TestBindKubeletClientConfigFlags(t *testing.T) {
|
||||
flags := &fakeFlagSet{t, util.StringSet{}}
|
||||
config := &KubeletConfig{}
|
||||
BindKubeletClientConfigFlags(flags, config)
|
||||
if len(flags.set) != 5 {
|
||||
if len(flags.set) != 6 {
|
||||
t.Errorf("unexpected flag set: %#v", flags)
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,9 @@ type KubeletConfig struct {
|
||||
|
||||
// TLSClientConfig contains settings to enable transport layer security
|
||||
TLSClientConfig
|
||||
|
||||
// HTTPTimeout is used by the client to timeout http requests to Kubelet.
|
||||
HTTPTimeout time.Duration
|
||||
}
|
||||
|
||||
// TLSClientConfig contains settings to enable transport layer security
|
||||
|
@ -89,6 +89,7 @@ func NewKubeletClient(config *KubeletConfig) (KubeletClient, error) {
|
||||
|
||||
c := &http.Client{
|
||||
Transport: transport,
|
||||
Timeout: config.HTTPTimeout,
|
||||
}
|
||||
return &HTTPKubeletClient{
|
||||
Client: c,
|
||||
|
Loading…
Reference in New Issue
Block a user