Skip to content

Commit

Permalink
Add no-drain flag and wait for workers ready after upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Jussi Nummelin <jnummelin@mirantis.com>
  • Loading branch information
jnummelin committed Feb 24, 2021
1 parent 7e6a116 commit 2116ac4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
9 changes: 8 additions & 1 deletion cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var applyCommand = &cli.Command{
Name: "no-wait",
Usage: "Do not wait for worker nodes to join",
},
&cli.BoolFlag{
Name: "no-drain",
Usage: "Do not drain worker nodes when upgrading",
},
debugFlag,
traceFlag,
analyticsFlag,
Expand All @@ -46,6 +50,7 @@ var applyCommand = &cli.Command{
}

phase.NoWait = ctx.Bool("no-wait")

manager := phase.Manager{Config: &c}

manager.AddPhase(
Expand All @@ -63,7 +68,9 @@ var applyCommand = &cli.Command{
&phase.InstallControllers{},
&phase.InstallWorkers{},
&phase.UpgradeControllers{},
&phase.UpgradeWorkers{},
&phase.UpgradeWorkers{
NoDrain: ctx.Bool("no-drain"),
},
&phase.Disconnect{},
)

Expand Down
10 changes: 0 additions & 10 deletions phase/gather_k0s_facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,11 @@ func (p *GatherK0sFacts) investigateK0s(h *cluster.Host) error {
return nil
}

<<<<<<< HEAD
switch status.Role {
case "server":
status.Role = "controller"
case "server+worker":
status.Role = "controller+worker"
=======
// Legacy role change
if status.Role == "server" {
status.Role = "controller"
>>>>>>> 489e103... Initial upgrade with server->controller migration
}

if status.Role != h.Role {
Expand All @@ -121,10 +115,6 @@ func (p *GatherK0sFacts) investigateK0s(h *cluster.Host) error {

func (p *GatherK0sFacts) needsUpgrade(h *cluster.Host) bool {
c, err := semver.NewConstraint(fmt.Sprintf("< %s", p.Config.Spec.K0s.Version))
if err != nil {
log.Warnf("%s: failed to parse version constraint: %s", h, err.Error())
return false
}
current, err := semver.NewVersion(h.Metadata.K0sRunningVersion)
if err != nil {
log.Warnf("%s: failed to parse version info: %s", h, err.Error())
Expand Down
30 changes: 23 additions & 7 deletions phase/upgrade_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
type UpgradeWorkers struct {
GenericPhase

NoDrain bool

hosts cluster.Hosts
leader *cluster.Host
}
Expand Down Expand Up @@ -72,11 +74,14 @@ func (p *UpgradeWorkers) Run() error {

func (p *UpgradeWorkers) upgradeWorker(h *cluster.Host) error {
log.Infof("%s: upgrade starting", h)
log.Debugf("%s: draining...", h)
if err := p.leader.DrainNode(h); err != nil {
return err

if !p.NoDrain {
log.Debugf("%s: draining...", h)
if err := p.leader.DrainNode(h); err != nil {
return err
}
log.Debugf("%s: draining complete", h)
}
log.Debugf("%s: draining complete", h)

log.Debugf("%s: Update and restart service", h)
if err := h.Configurer.StopService(h, h.K0sServiceName()); err != nil {
Expand All @@ -88,9 +93,20 @@ func (p *UpgradeWorkers) upgradeWorker(h *cluster.Host) error {
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
return err
}
log.Debugf("%s: marking node schedulable again", h)
if err := p.leader.UncordonNode(h); err != nil {
return err
if !p.NoDrain {
log.Debugf("%s: marking node schedulable again", h)
if err := p.leader.UncordonNode(h); err != nil {
return err
}
}
if NoWait {
log.Debugf("%s: not waiting because --no-wait given", h)
} else {
log.Infof("%s: waiting for node to become ready again", h)
if err := p.Config.Spec.K0sLeader().WaitKubeNodeReady(h); err != nil {
return err
}
h.Metadata.Ready = true
}
log.Infof("%s: upgrade successful", h)
return nil
Expand Down

0 comments on commit 2116ac4

Please sign in to comment.