mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
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:
commit
e4178c82f3
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user