mirror of
https://github.com/rancher/rke.git
synced 2025-09-01 06:56:29 +00:00
Add Rotate certificates command to rke
This commit is contained in:
committed by
Alena Prokharchyk
parent
7582083e7a
commit
3551e6e4b6
@@ -28,7 +28,7 @@ import (
|
||||
const (
|
||||
DockerRegistryURL = "docker.io"
|
||||
// RestartTimeout in seconds
|
||||
RestartTimeout = 30
|
||||
RestartTimeout = 5
|
||||
// StopTimeout in seconds
|
||||
StopTimeout = 5
|
||||
)
|
||||
@@ -230,6 +230,14 @@ func RemoveContainer(ctx context.Context, dClient *client.Client, hostname strin
|
||||
return nil
|
||||
}
|
||||
|
||||
func RestartContainer(ctx context.Context, dClient *client.Client, hostname, containerName string) error {
|
||||
restartTimeout := RestartTimeout * time.Second
|
||||
err := dClient.ContainerRestart(ctx, containerName, &restartTimeout)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Can't restart Docker container [%s] for host [%s]: %v", containerName, hostname, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func StopContainer(ctx context.Context, dClient *client.Client, hostname string, containerName string) error {
|
||||
// define the stop timeout
|
||||
stopTimeoutDuration := StopTimeout * time.Second
|
||||
@@ -455,3 +463,23 @@ func GetKubeletDockerConfig(prsMap map[string]v3.PrivateRegistry) (string, error
|
||||
}
|
||||
return string(cfg), nil
|
||||
}
|
||||
|
||||
func DoRestartContainer(ctx context.Context, dClient *client.Client, containerName, hostname string) error {
|
||||
logrus.Debugf("[restart/%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(ctx, containerName)
|
||||
if err != nil {
|
||||
if client.IsErrNotFound(err) {
|
||||
logrus.Debugf("[restart/%s] Container doesn't exist on host [%s]", containerName, hostname)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("[restart/%s] Restarting container on host [%s]", containerName, hostname)
|
||||
err = RestartContainer(ctx, dClient, hostname, containerName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof(ctx, "[restart/%s] Successfully restarted container on host [%s]", containerName, hostname)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user