-
Notifications
You must be signed in to change notification settings - Fork 11
PRODENG-2480 Launchpad reset now cleans the lingering MCR files #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package configurer | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| common "github.com/Mirantis/mcc/pkg/product/common/api" | ||
| "github.com/k0sproject/rig/log" | ||
| "github.com/k0sproject/rig/os" | ||
| ) | ||
|
|
||
| type DockerConfigurer struct{} | ||
|
|
||
| // GetDockerInfo gets docker info from the host | ||
| func (c DockerConfigurer) GetDockerInfo(h os.Host, hostKind string) (common.DockerInfo, error) { | ||
| command := "docker info --format \"{{json . }}\"" | ||
| log.Infof("%s attempting to execute `docker info`", h) | ||
| info, err := h.ExecOutput(command) | ||
|
|
||
| if err != nil && hostKind != "windows" { | ||
| log.Infof("%s attempting to execute `docker info` with sudo", h) | ||
| info, err = h.ExecOutput(fmt.Sprintf("sudo %s", command)) | ||
| if err != nil { | ||
| return common.DockerInfo{}, err | ||
| } | ||
| } | ||
|
|
||
| var dockerInfo common.DockerInfo | ||
| err = json.Unmarshal([]byte(info), &dockerInfo) | ||
| if err != nil { | ||
| log.Infof("%s no `docker info` found", h) | ||
| return common.DockerInfo{}, err | ||
| } | ||
|
|
||
| return dockerInfo, nil | ||
| } | ||
|
|
||
| // GetDockerDaemonConfig parses docker daemon json string and populate DockerDaemonConfig struct | ||
| func (c DockerConfigurer) GetDockerDaemonConfig(dockerDaemon string) (common.DockerDaemonConfig, error) { | ||
| if dockerDaemon != "" { | ||
| return common.DockerDaemonConfig{}, fmt.Errorf("the docker daemon config is empty") | ||
| } | ||
|
|
||
| var config common.DockerDaemonConfig | ||
| if err := json.Unmarshal([]byte(dockerDaemon), &config); err != nil { | ||
| return common.DockerDaemonConfig{}, fmt.Errorf("failed to unmarshal json content: %w", err) | ||
| } | ||
|
|
||
| return config, nil | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,15 +21,25 @@ func (c Configurer) InstallMKEBasePackages(h os.Host) error { | |
|
|
||
| // UninstallMCR uninstalls docker-ee engine. | ||
| func (c Configurer) UninstallMCR(h os.Host, scriptPath string, engineConfig common.MCRConfig) error { | ||
| err := h.Exec("sudo docker system prune -f") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := c.StopService(h, "docker"); err != nil { | ||
| return err | ||
| var err error | ||
| info, getDockerError := c.GetDockerInfo(h, c.Kind()) | ||
| if getDockerError == nil { | ||
| if err = h.Exec("sudo docker system prune -f"); err != nil { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we put this into engineConfig.Prune control? Not required for this change, but it might be easy.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. I don't think we need to include it in this PR, but we might want to have a separate PR. |
||
| return err | ||
| } | ||
|
|
||
| if err = c.StopService(h, "docker"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err = c.StopService(h, "containerd"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = h.Exec("sudo apt-get remove -y docker-ee docker-ee-cli && sudo apt autoremove -y") | ||
| } | ||
| if err := c.StopService(h, "containerd"); err != nil { | ||
| return err | ||
| if engineConfig.Prune { | ||
| c.CleanupLingeringMCR(h, info) | ||
| } | ||
| return h.Exec("sudo apt-get remove -y docker-ee docker-ee-cli && sudo apt autoremove -y") | ||
| return err | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.