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 21, 2025
1 parent 239f72e commit 8b5b13a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
21 changes: 21 additions & 0 deletions pkg/mcr/mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"

"github.com/Mirantis/mcc/pkg/product/mke/api"
"github.com/Mirantis/mcc/pkg/swarm"

Check failure on line 8 in pkg/mcr/mcr.go

View workflow job for this annotation

GitHub Actions / Lint

File is not properly formatted (gci)
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -37,3 +39,22 @@ func EnsureMCRVersion(h *api.Host, specMcrVersion string, forceMCRRestart bool)

return nil
}

// DrainNode drains a node from the workload via docker drain command.
func 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
}
18 changes: 16 additions & 2 deletions pkg/product/mke/phase/uninstall_mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package phase
import (
"fmt"

"github.com/Mirantis/mcc/pkg/mcr"
"github.com/Mirantis/mcc/pkg/phase"
"github.com/Mirantis/mcc/pkg/product/mke/api"
log "github.com/sirupsen/logrus"
Expand All @@ -27,10 +28,23 @@ func (p *UninstallMCR) Run() error {
return nil
}

func (p *UninstallMCR) uninstallMCR(h *api.Host, c *api.ClusterConfig) error {
func (p *UninstallMCR) uninstallMCR(h *api.Host, config *api.ClusterConfig) error {
log.Infof("%s: uninstalling container runtime", h)

if err := h.Configurer.UninstallMCR(h, h.Metadata.MCRInstallScript, c.Spec.MCR); err != nil {
leader := config.Spec.SwarmLeader()

if err := mcr.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, config.Spec.MCR); err != nil {
return fmt.Errorf("%s: uninstall container runtime: %w", h, err)
}

Expand Down

0 comments on commit 8b5b13a

Please sign in to comment.