mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +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{
|
KubeletConfig: client.KubeletConfig{
|
||||||
Port: 10250,
|
Port: 10250,
|
||||||
EnableHttps: false,
|
EnableHttps: false,
|
||||||
|
HTTPTimeout: time.Duration(5) * time.Second,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ func NewCMServer() *CMServer {
|
|||||||
KubeletConfig: client.KubeletConfig{
|
KubeletConfig: client.KubeletConfig{
|
||||||
Port: ports.KubeletPort,
|
Port: ports.KubeletPort,
|
||||||
EnableHttps: false,
|
EnableHttps: false,
|
||||||
|
HTTPTimeout: time.Duration(5) * time.Second,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return &s
|
return &s
|
||||||
|
@ -16,12 +16,17 @@ limitations under the License.
|
|||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// FlagSet abstracts the flag interface for compatibility with both Golang "flag"
|
// FlagSet abstracts the flag interface for compatibility with both Golang "flag"
|
||||||
// and cobra pflags (Posix style).
|
// and cobra pflags (Posix style).
|
||||||
type FlagSet interface {
|
type FlagSet interface {
|
||||||
StringVar(p *string, name, value, usage string)
|
StringVar(p *string, name, value, usage string)
|
||||||
BoolVar(p *bool, name string, value bool, usage string)
|
BoolVar(p *bool, name string, value bool, usage string)
|
||||||
UintVar(p *uint, name string, value uint, 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.
|
// 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) {
|
func BindKubeletClientConfigFlags(flags FlagSet, config *KubeletConfig) {
|
||||||
flags.BoolVar(&config.EnableHttps, "kubelet_https", config.EnableHttps, "Use https for kubelet connections")
|
flags.BoolVar(&config.EnableHttps, "kubelet_https", config.EnableHttps, "Use https for kubelet connections")
|
||||||
flags.UintVar(&config.Port, "kubelet_port", config.Port, "Kubelet port")
|
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.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.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.")
|
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 (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"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)
|
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) {
|
func TestBindClientConfigFlags(t *testing.T) {
|
||||||
flags := &fakeFlagSet{t, util.StringSet{}}
|
flags := &fakeFlagSet{t, util.StringSet{}}
|
||||||
config := &Config{}
|
config := &Config{}
|
||||||
@ -70,7 +81,7 @@ func TestBindKubeletClientConfigFlags(t *testing.T) {
|
|||||||
flags := &fakeFlagSet{t, util.StringSet{}}
|
flags := &fakeFlagSet{t, util.StringSet{}}
|
||||||
config := &KubeletConfig{}
|
config := &KubeletConfig{}
|
||||||
BindKubeletClientConfigFlags(flags, config)
|
BindKubeletClientConfigFlags(flags, config)
|
||||||
if len(flags.set) != 5 {
|
if len(flags.set) != 6 {
|
||||||
t.Errorf("unexpected flag set: %#v", flags)
|
t.Errorf("unexpected flag set: %#v", flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,9 @@ type KubeletConfig struct {
|
|||||||
|
|
||||||
// TLSClientConfig contains settings to enable transport layer security
|
// TLSClientConfig contains settings to enable transport layer security
|
||||||
TLSClientConfig
|
TLSClientConfig
|
||||||
|
|
||||||
|
// HTTPTimeout is used by the client to timeout http requests to Kubelet.
|
||||||
|
HTTPTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLSClientConfig contains settings to enable transport layer security
|
// TLSClientConfig contains settings to enable transport layer security
|
||||||
|
@ -89,6 +89,7 @@ func NewKubeletClient(config *KubeletConfig) (KubeletClient, error) {
|
|||||||
|
|
||||||
c := &http.Client{
|
c := &http.Client{
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
|
Timeout: config.HTTPTimeout,
|
||||||
}
|
}
|
||||||
return &HTTPKubeletClient{
|
return &HTTPKubeletClient{
|
||||||
Client: c,
|
Client: c,
|
||||||
|
Loading…
Reference in New Issue
Block a user