mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
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:
parent
e5fbea62c6
commit
87a370f67c
@ -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