mirror of
https://github.com/rancher/rke.git
synced 2025-07-16 08:25:51 +00:00
Add stop container timeout
This commit is contained in:
parent
95ba4ea61f
commit
be7bc526ab
@ -27,7 +27,10 @@ import (
|
||||
|
||||
const (
|
||||
DockerRegistryURL = "docker.io"
|
||||
RestartTimeout = 30
|
||||
// RestartTimeout in seconds
|
||||
RestartTimeout = 30
|
||||
// StopTimeout in seconds
|
||||
StopTimeout = 30
|
||||
)
|
||||
|
||||
var K8sDockerVersions = map[string][]string{
|
||||
@ -136,12 +139,6 @@ func DoRemoveContainer(ctx context.Context, dClient *client.Client, containerNam
|
||||
}
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("[remove/%s] Stopping container on host [%s]", containerName, hostname)
|
||||
err = StopContainer(ctx, dClient, hostname, containerName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("[remove/%s] Removing container on host [%s]", containerName, hostname)
|
||||
err = RemoveContainer(ctx, dClient, hostname, containerName)
|
||||
if err != nil {
|
||||
@ -225,7 +222,7 @@ func UseLocalOrPull(ctx context.Context, dClient *client.Client, hostname string
|
||||
}
|
||||
|
||||
func RemoveContainer(ctx context.Context, dClient *client.Client, hostname string, containerName string) error {
|
||||
err := dClient.ContainerRemove(ctx, containerName, types.ContainerRemoveOptions{})
|
||||
err := dClient.ContainerRemove(ctx, containerName, types.ContainerRemoveOptions{Force: true})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Can't remove Docker container [%s] for host [%s]: %v", containerName, hostname, err)
|
||||
}
|
||||
@ -233,7 +230,9 @@ func RemoveContainer(ctx context.Context, dClient *client.Client, hostname strin
|
||||
}
|
||||
|
||||
func StopContainer(ctx context.Context, dClient *client.Client, hostname string, containerName string) error {
|
||||
err := dClient.ContainerStop(ctx, containerName, nil)
|
||||
// define the stop timeout
|
||||
stopTimeoutDuration := StopTimeout * time.Second
|
||||
err := dClient.ContainerStop(ctx, containerName, &stopTimeoutDuration)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Can't stop Docker container [%s] for host [%s]: %v", containerName, hostname, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user