Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change timeout for ExecSync, RunPodSandbox and PullImage. #41274

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/kubelet/remote/remote_image.go
Expand Up @@ -91,7 +91,7 @@ func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimea

// PullImage pulls an image with authentication config.
func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig) (string, error) {
ctx, cancel := getContextWithTimeout(r.timeout)
ctx, cancel := getContextWithCancel()
defer cancel()

resp, err := r.imageClient.PullImage(ctx, &runtimeapi.PullImageRequest{
Expand Down
10 changes: 8 additions & 2 deletions pkg/kubelet/remote/remote_runtime.go
Expand Up @@ -74,7 +74,9 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
// the sandbox is in ready state.
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()

resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{
Expand Down Expand Up @@ -281,7 +283,11 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
// 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.
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()

timeoutSeconds := int64(timeout.Seconds())
Expand Down
5 changes: 5 additions & 0 deletions pkg/kubelet/remote/utils.go
Expand Up @@ -36,6 +36,11 @@ func getContextWithTimeout(timeout time.Duration) (context.Context, context.Canc
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.
func verifySandboxStatus(status *runtimeapi.PodSandboxStatus) error {
if status.Id == "" {
Expand Down