1
0
mirror of https://github.com/rancher/rke.git synced 2025-09-12 04:20:26 +00:00

Cluster Down/Remove

Reverse order and add force flag
This commit is contained in:
galal-hussein
2017-11-20 20:08:50 +02:00
parent e53f7adf02
commit 892e9ab5d9
13 changed files with 329 additions and 67 deletions

View File

@@ -69,6 +69,32 @@ func DoRollingUpdateContainer(dClient *client.Client, imageCfg *container.Config
return err
}
func DoRemoveContainer(dClient *client.Client, containerName, hostname string) error {
logrus.Infof("[down/%s] Checking if container is running on host [%s]", containerName, hostname)
// not using the wrapper to check if the error is a NotFound error
_, err := dClient.ContainerInspect(context.Background(), containerName)
if err != nil {
if client.IsErrNotFound(err) {
logrus.Infof("[down/%s] Container doesn't exist on host [%s]", containerName, hostname)
return nil
}
return err
}
logrus.Infof("[down/%s] Stopping container on host [%s]", containerName, hostname)
err = StopContainer(dClient, hostname, containerName)
if err != nil {
return err
}
logrus.Infof("[down/%s] Removing container on host [%s]", containerName, hostname)
err = RemoveContainer(dClient, hostname, containerName)
if err != nil {
return err
}
logrus.Infof("[down/%s] Sucessfully removed container on host [%s]", containerName, hostname)
return nil
}
func IsContainerRunning(dClient *client.Client, hostname string, containerName string) (bool, error) {
logrus.Debugf("Checking if container %s is running on host [%s]", containerName, hostname)
containers, err := dClient.ContainerList(context.Background(), types.ContainerListOptions{})