Commit 52ebd4ec authored by Random-Liu's avatar Random-Liu

Add runtime-request-timeout kubelet flag.

parent 04fd079d
...@@ -85,6 +85,7 @@ func NewKubeletServer() *KubeletServer { ...@@ -85,6 +85,7 @@ func NewKubeletServer() *KubeletServer {
CgroupRoot: "", CgroupRoot: "",
ConfigureCBR0: false, ConfigureCBR0: false,
ContainerRuntime: "docker", ContainerRuntime: "docker",
RuntimeRequestTimeout: unversioned.Duration{Duration: 2 * time.Minute},
CPUCFSQuota: true, CPUCFSQuota: true,
DockerExecHandlerName: "native", DockerExecHandlerName: "native",
EventBurst: 10, EventBurst: 10,
...@@ -227,6 +228,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) { ...@@ -227,6 +228,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.CgroupRoot, "cgroup-root", s.CgroupRoot, "Optional root cgroup to use for pods. This is handled by the container runtime on a best effort basis. Default: '', which means use the container runtime default.") fs.StringVar(&s.CgroupRoot, "cgroup-root", s.CgroupRoot, "Optional root cgroup to use for pods. This is handled by the container runtime on a best effort basis. Default: '', which means use the container runtime default.")
fs.StringVar(&s.ContainerRuntime, "container-runtime", s.ContainerRuntime, "The container runtime to use. Possible values: 'docker', 'rkt'. Default: 'docker'.") fs.StringVar(&s.ContainerRuntime, "container-runtime", s.ContainerRuntime, "The container runtime to use. Possible values: 'docker', 'rkt'. Default: 'docker'.")
fs.DurationVar(&s.RuntimeRequestTimeout.Duration, "runtime-request-timeout", s.RuntimeRequestTimeout.Duration, "Timeout of all runtime requests except long running request - pull, logs, exec and attach. When timeout exceeded, kubelet will cancel the request, throw out an error and retry later. Default: 2m0s")
fs.StringVar(&s.LockFilePath, "lock-file", s.LockFilePath, "<Warning: Alpha feature> The path to file for kubelet to use as a lock file.") fs.StringVar(&s.LockFilePath, "lock-file", s.LockFilePath, "<Warning: Alpha feature> The path to file for kubelet to use as a lock file.")
fs.BoolVar(&s.ExitOnLockContention, "exit-on-lock-contention", s.ExitOnLockContention, "Whether kubelet should exit upon lock-file contention.") fs.BoolVar(&s.ExitOnLockContention, "exit-on-lock-contention", s.ExitOnLockContention, "Whether kubelet should exit upon lock-file contention.")
fs.StringVar(&s.RktPath, "rkt-path", s.RktPath, "Path of rkt binary. Leave empty to use the first rkt in $PATH. Only used if --container-runtime='rkt'.") fs.StringVar(&s.RktPath, "rkt-path", s.RktPath, "Path of rkt binary. Leave empty to use the first rkt in $PATH. Only used if --container-runtime='rkt'.")
......
...@@ -212,7 +212,7 @@ func UnsecuredKubeletConfig(s *options.KubeletServer) (*KubeletConfig, error) { ...@@ -212,7 +212,7 @@ func UnsecuredKubeletConfig(s *options.KubeletServer) (*KubeletConfig, error) {
ContainerRuntime: s.ContainerRuntime, ContainerRuntime: s.ContainerRuntime,
CPUCFSQuota: s.CPUCFSQuota, CPUCFSQuota: s.CPUCFSQuota,
DiskSpacePolicy: diskSpacePolicy, DiskSpacePolicy: diskSpacePolicy,
DockerClient: dockertools.ConnectToDockerOrDie(s.DockerEndpoint), DockerClient: dockertools.ConnectToDockerOrDie(s.DockerEndpoint, s.RuntimeRequestTimeout.Duration), // TODO(random-liu): Set RuntimeRequestTimeout for rkt.
RuntimeCgroups: s.RuntimeCgroups, RuntimeCgroups: s.RuntimeCgroups,
DockerExecHandler: dockerExecHandler, DockerExecHandler: dockerExecHandler,
EnableControllerAttachDetach: s.EnableControllerAttachDetach, EnableControllerAttachDetach: s.EnableControllerAttachDetach,
......
...@@ -184,7 +184,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) { ...@@ -184,7 +184,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
mockDriver = &MockExecutorDriver{} mockDriver = &MockExecutorDriver{}
registry = newFakeRegistry() registry = newFakeRegistry()
executor = New(Config{ executor = New(Config{
Docker: dockertools.ConnectToDockerOrDie("fake://"), Docker: dockertools.ConnectToDockerOrDie("fake://", 0),
NodeInfos: make(chan NodeInfo, 1), NodeInfos: make(chan NodeInfo, 1),
Registry: registry, Registry: registry,
}) })
...@@ -387,7 +387,7 @@ func TestExecutorFrameworkMessage(t *testing.T) { ...@@ -387,7 +387,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
kubeletFinished = make(chan struct{}) kubeletFinished = make(chan struct{})
registry = newFakeRegistry() registry = newFakeRegistry()
executor = New(Config{ executor = New(Config{
Docker: dockertools.ConnectToDockerOrDie("fake://"), Docker: dockertools.ConnectToDockerOrDie("fake://", 0),
NodeInfos: make(chan NodeInfo, 1), NodeInfos: make(chan NodeInfo, 1),
ShutdownAlert: func() { ShutdownAlert: func() {
close(kubeletFinished) close(kubeletFinished)
...@@ -584,7 +584,7 @@ func TestExecutorShutdown(t *testing.T) { ...@@ -584,7 +584,7 @@ func TestExecutorShutdown(t *testing.T) {
kubeletFinished = make(chan struct{}) kubeletFinished = make(chan struct{})
exitCalled = int32(0) exitCalled = int32(0)
executor = New(Config{ executor = New(Config{
Docker: dockertools.ConnectToDockerOrDie("fake://"), Docker: dockertools.ConnectToDockerOrDie("fake://", 0),
NodeInfos: make(chan NodeInfo, 1), NodeInfos: make(chan NodeInfo, 1),
ShutdownAlert: func() { ShutdownAlert: func() {
close(kubeletFinished) close(kubeletFinished)
......
...@@ -75,7 +75,7 @@ func (m *MockExecutorDriver) SendFrameworkMessage(msg string) (mesosproto.Status ...@@ -75,7 +75,7 @@ func (m *MockExecutorDriver) SendFrameworkMessage(msg string) (mesosproto.Status
func NewTestKubernetesExecutor() *Executor { func NewTestKubernetesExecutor() *Executor {
return New(Config{ return New(Config{
Docker: dockertools.ConnectToDockerOrDie("fake://"), Docker: dockertools.ConnectToDockerOrDie("fake://", 0),
Registry: newFakeRegistry(), Registry: newFakeRegistry(),
}) })
} }
......
...@@ -107,7 +107,7 @@ func (s *KubeletExecutorServer) runExecutor( ...@@ -107,7 +107,7 @@ func (s *KubeletExecutorServer) runExecutor(
exec := executor.New(executor.Config{ exec := executor.New(executor.Config{
Registry: registry, Registry: registry,
APIClient: apiclient, APIClient: apiclient,
Docker: dockertools.ConnectToDockerOrDie(s.DockerEndpoint), Docker: dockertools.ConnectToDockerOrDie(s.DockerEndpoint, 0),
SuicideTimeout: s.SuicideTimeout, SuicideTimeout: s.SuicideTimeout,
KubeletFinished: kubeletFinished, KubeletFinished: kubeletFinished,
ExitFunc: os.Exit, ExitFunc: os.Exit,
......
...@@ -398,6 +398,7 @@ root-dir ...@@ -398,6 +398,7 @@ root-dir
run-proxy run-proxy
runtime-cgroups runtime-cgroups
runtime-config runtime-config
runtime-request-timeout
save-config save-config
scheduler-config scheduler-config
scheduler-name scheduler-name
......
...@@ -263,6 +263,9 @@ type KubeletConfiguration struct { ...@@ -263,6 +263,9 @@ type KubeletConfiguration struct {
CgroupRoot string `json:"cgroupRoot,omitempty"` CgroupRoot string `json:"cgroupRoot,omitempty"`
// containerRuntime is the container runtime to use. // containerRuntime is the container runtime to use.
ContainerRuntime string `json:"containerRuntime"` ContainerRuntime string `json:"containerRuntime"`
// runtimeRequestTimeout is the timeout for all runtime requests except long running
// requests - pull, logs, exec and attach.
RuntimeRequestTimeout unversioned.Duration `json:"runtimeRequestTimeout,omitempty"`
// rktPath is the path of rkt binary. Leave empty to use the first rkt in // rktPath is the path of rkt binary. Leave empty to use the first rkt in
// $PATH. // $PATH.
RktPath string `json:"rktPath,omitempty"` RktPath string `json:"rktPath,omitempty"`
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"path" "path"
"strconv" "strconv"
"strings" "strings"
"time"
dockerref "github.com/docker/distribution/reference" dockerref "github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
...@@ -311,8 +312,11 @@ func getDockerClient(dockerEndpoint string) (*dockerapi.Client, error) { ...@@ -311,8 +312,11 @@ func getDockerClient(dockerEndpoint string) (*dockerapi.Client, error) {
// ConnectToDockerOrDie creates docker client connecting to docker daemon. // ConnectToDockerOrDie creates docker client connecting to docker daemon.
// If the endpoint passed in is "fake://", a fake docker client // If the endpoint passed in is "fake://", a fake docker client
// will be returned. The program exits if error occurs. // will be returned. The program exits if error occurs. The requestTimeout
func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface { // is the timeout for docker requests. If timeout is exceeded, the request
// will be cancelled and throw out an error. If requestTimeout is 0, a default
// value will be applied.
func ConnectToDockerOrDie(dockerEndpoint string, requestTimeout time.Duration) DockerInterface {
if dockerEndpoint == "fake://" { if dockerEndpoint == "fake://" {
return NewFakeDockerClient() return NewFakeDockerClient()
} }
...@@ -320,7 +324,8 @@ func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface { ...@@ -320,7 +324,8 @@ func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface {
if err != nil { if err != nil {
glog.Fatalf("Couldn't connect to docker: %v", err) glog.Fatalf("Couldn't connect to docker: %v", err)
} }
return newKubeDockerClient(client) glog.Infof("Start docker client with request timeout=%v", requestTimeout)
return newKubeDockerClient(client, requestTimeout)
} }
// milliCPUToQuota converts milliCPU to CFS quota and period values // milliCPUToQuota converts milliCPU to CFS quota and period values
......
...@@ -40,7 +40,7 @@ func NewConformanceImage(containerRuntime string, image string) (ci ConformanceI ...@@ -40,7 +40,7 @@ func NewConformanceImage(containerRuntime string, image string) (ci ConformanceI
//TODO: do not expose kubelet implementation details after we refactor the runtime API. //TODO: do not expose kubelet implementation details after we refactor the runtime API.
func dockerRuntime() kubecontainer.Runtime { func dockerRuntime() kubecontainer.Runtime {
dockerClient := dockertools.ConnectToDockerOrDie("") dockerClient := dockertools.ConnectToDockerOrDie("", 0)
pm := kubepod.NewBasicPodManager(nil) pm := kubepod.NewBasicPodManager(nil)
dm := dockertools.NewDockerManager( dm := dockertools.NewDockerManager(
dockerClient, dockerClient,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment