Commit fa3f3783 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #41274 from Random-Liu/remove-timeout-for-long-running-operation

Automatic merge from submit-queue Change timeout for ExecSync, RunPodSandbox and PullImage. For https://github.com/kubernetes/kubernetes/issues/41225. This PR: * Change `ExecSync` to respect passed-in timeout. * Double `RunPodSandbox` timeout. * Remove `PullImage` timeout. /cc @yujuhong @timstclair @feiskyer @freehan @kubernetes/sig-node-bugs
parents 198fcf60 81770309
...@@ -91,7 +91,7 @@ func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimea ...@@ -91,7 +91,7 @@ func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimea
// PullImage pulls an image with authentication config. // PullImage pulls an image with authentication config.
func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig) (string, error) { func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig) (string, error) {
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithCancel()
defer cancel() defer cancel()
resp, err := r.imageClient.PullImage(ctx, &runtimeapi.PullImageRequest{ resp, err := r.imageClient.PullImage(ctx, &runtimeapi.PullImageRequest{
......
...@@ -74,7 +74,9 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe ...@@ -74,7 +74,9 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure // RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
// the sandbox is in ready state. // the sandbox is in ready state.
func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig) (string, error) { func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig) (string, error) {
ctx, cancel := getContextWithTimeout(r.timeout) // Use 2 times longer timeout for sandbox operation (4 mins by defualt)
// TODO: Make the pod sandbox timeout configurable.
ctx, cancel := getContextWithTimeout(r.timeout * 2)
defer cancel() defer cancel()
resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{ resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{
...@@ -281,7 +283,11 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi. ...@@ -281,7 +283,11 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
// ExecSync executes a command in the container, and returns the stdout output. // ExecSync executes a command in the container, and returns the stdout output.
// If command exits with a non-zero exit code, an error is returned. // If command exits with a non-zero exit code, an error is returned.
func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) { func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(timeout)
if timeout == 0 {
// Do not set timeout when timeout is 0.
ctx, cancel = getContextWithCancel()
}
defer cancel() defer cancel()
timeoutSeconds := int64(timeout.Seconds()) timeoutSeconds := int64(timeout.Seconds())
......
...@@ -36,6 +36,11 @@ func getContextWithTimeout(timeout time.Duration) (context.Context, context.Canc ...@@ -36,6 +36,11 @@ func getContextWithTimeout(timeout time.Duration) (context.Context, context.Canc
return context.WithTimeout(context.Background(), timeout) return context.WithTimeout(context.Background(), timeout)
} }
// getContextWithCancel returns a context with cancel.
func getContextWithCancel() (context.Context, context.CancelFunc) {
return context.WithCancel(context.Background())
}
// verifySandboxStatus verified whether all required fields are set in PodSandboxStatus. // verifySandboxStatus verified whether all required fields are set in PodSandboxStatus.
func verifySandboxStatus(status *runtimeapi.PodSandboxStatus) error { func verifySandboxStatus(status *runtimeapi.PodSandboxStatus) error {
if status.Id == "" { if status.Id == "" {
......
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