Merge pull request #31275 from dims/fix-issue-31219

Automatic merge from submit-queue

Increase request timeout based on termination grace period

When terminationGracePeriodSeconds is set to > 2 minutes (which is
the default request timeout), ContainerStop() times out at 2 minutes.
We should check the timeout being passed in and bump up the
request timeout if needed.

Fixes #31219
This commit is contained in:
Kubernetes Submit Queue 2016-08-25 03:20:32 -07:00 committed by GitHub
commit e4178c82f3

View File

@ -152,7 +152,7 @@ func (d *kubeDockerClient) StartContainer(id string) error {
// Stopping an already stopped container will not cause an error in engine-api.
func (d *kubeDockerClient) StopContainer(id string, timeout int) error {
ctx, cancel := d.getTimeoutContext()
ctx, cancel := d.getCustomTimeoutContext(time.Duration(timeout) * time.Second)
defer cancel()
err := d.client.ContainerStop(ctx, id, timeout)
if ctxErr := contextError(ctx); ctxErr != nil {
@ -534,6 +534,15 @@ func (d *kubeDockerClient) getTimeoutContext() (context.Context, context.CancelF
return context.WithTimeout(context.Background(), d.timeout)
}
// getCustomTimeoutContext returns a new context with a specific request timeout
func (d *kubeDockerClient) getCustomTimeoutContext(timeout time.Duration) (context.Context, context.CancelFunc) {
// Pick the larger of the two
if d.timeout > timeout {
timeout = d.timeout
}
return context.WithTimeout(context.Background(), timeout)
}
// ParseDockerTimestamp parses the timestamp returned by DockerInterface from string to time.Time
func ParseDockerTimestamp(s string) (time.Time, error) {
// Timestamp returned by Docker is in time.RFC3339Nano format.