Skip to content
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

Drain workers before MCR upgrade #359

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions pkg/product/mke/phase/upgrade_mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Mirantis/mcc/pkg/msr"
"github.com/Mirantis/mcc/pkg/phase"
"github.com/Mirantis/mcc/pkg/product/mke/api"
"github.com/Mirantis/mcc/pkg/swarm"

retry "github.com/avast/retry-go"
"github.com/gammazero/workerpool"
Expand Down Expand Up @@ -52,7 +53,6 @@ func (p *UpgradeMCR) Run() error {
}

// Upgrades host docker engines, first managers (one-by-one) and then ~10% rolling update to workers
// TODO: should we drain?
func (p *UpgradeMCR) upgradeMCRs() error {
var managers api.Hosts
var workers api.Hosts
Expand Down Expand Up @@ -155,8 +155,36 @@ func (p *UpgradeMCR) upgradeMCRs() error {
func (p *UpgradeMCR) upgradeMCR(h *api.Host) error {
err := retry.Do(
func() error {
var nodeID string
var leader *api.Host
if h.Role == "worker" {
id, err := swarm.NodeID(h)
if err == nil && id != "" {
nodeID = id
leader = p.Config.Spec.SwarmLeader()
log.Infof("%s: draining node %s (%s)", leader, h, nodeID)
err := leader.Exec(leader.Configurer.DockerCommandf("node update --availability drain %s", nodeID))
if err != nil {
return fmt.Errorf("%s: drain of node %s failed: %w", leader, h, err)
}
time.Sleep(30 * time.Second)
log.Infof("%s: drained", h)
}
}

log.Infof("%s: upgrading container runtime (%s -> %s)", h, h.Metadata.MCRVersion, p.Config.Spec.MCR.Version)
return h.Configurer.InstallMCR(h, h.Metadata.MCRInstallScript, p.Config.Spec.MCR)
if err := h.Configurer.InstallMCR(h, h.Metadata.MCRInstallScript, p.Config.Spec.MCR); err != nil {
return err
}

if nodeID != "" {
log.Infof("%s: reactivating node %s (%s)", leader, h, nodeID)
if err := leader.Exec(leader.Configurer.DockerCommandf("node update --availability active %s", nodeID)); err != nil {
return fmt.Errorf("%s: reactivation of node %s failed: %w", leader, h, err)
}
}

return nil
},
)
if err != nil {
Expand Down