Skip to content

Commit

Permalink
PRODENG-2826 MCR Uninstall now swarm drains and prunes volumes
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar <[email protected]>
  • Loading branch information
cranzy committed Jan 14, 2025
1 parent 239f72e commit 1413100
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/product/mke/phase/uninstall_mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/Mirantis/mcc/pkg/phase"
"github.com/Mirantis/mcc/pkg/product/mke/api"
"github.com/Mirantis/mcc/pkg/swarm"
log "github.com/sirupsen/logrus"
)

Expand All @@ -30,6 +31,19 @@ func (p *UninstallMCR) Run() error {
func (p *UninstallMCR) uninstallMCR(h *api.Host, c *api.ClusterConfig) error {

Check failure on line 31 in pkg/product/mke/phase/uninstall_mcr.go

View workflow job for this annotation

GitHub Actions / Lint

parameter name 'c' is too short for the scope of its usage (varnamelen)
log.Infof("%s: uninstalling container runtime", h)

leader := c.Spec.SwarmLeader()

if err := p.drainNode(leader, h); err != nil {
return fmt.Errorf("%s: drain node: %w", h, err)
}

uVolumeCmd := h.Configurer.DockerCommandf("volume prune -f")
log.Infof("%s: unmounted dangling volumes", h)

if err := h.Exec(uVolumeCmd); err != nil {
return fmt.Errorf("%s: failed to unmount dangling volumes: %w", h, err)
}

if err := h.Configurer.UninstallMCR(h, h.Metadata.MCRInstallScript, c.Spec.MCR); err != nil {
return fmt.Errorf("%s: uninstall container runtime: %w", h, err)
}
Expand All @@ -38,3 +52,22 @@ func (p *UninstallMCR) uninstallMCR(h *api.Host, c *api.ClusterConfig) error {

return nil
}

// DrainNode drains a node from the workload via docker drain command.
func (p *UninstallMCR) drainNode(lead *api.Host, h *api.Host) error {
nodeID, err := swarm.NodeID(h)
if err != nil {
return fmt.Errorf("failed to get node ID for %s: %w", h, err)
}

drainCmd := lead.Configurer.DockerCommandf("node update --availability drain %s", nodeID)
if err := lead.Exec(drainCmd); err != nil {
return fmt.Errorf("%s: failed to run MKE uninstaller: %w", lead, err)
}
if err := lead.Exec(drainCmd); err != nil {
return fmt.Errorf("failed to drain node %s: %w", nodeID, err)
}

log.Infof("%s: node %s drained", lead, nodeID)
return nil
}

0 comments on commit 1413100

Please sign in to comment.