Skip to content

Commit

Permalink
PRODENG-2528 allow force mcr upgrade
Browse files Browse the repository at this point in the history
This allows a command argument which will force the MCR upgrade phase
to select all hosts, even if they look like they already match the
requested version.

- product.Product.Apply now accepts "force upgrade compatible products" flag
- MKE product uses the flag in the upgrade MCR phase
- if MCR upgrade phase recieves true for the flag, then all hosts get
  upgraded
- cmd.Apply recieves a cli arg, and passes it as the "force upgrade"
  Product flag

Signed-off-by: James Nesbitt <[email protected]>
  • Loading branch information
james-nesbitt committed Feb 8, 2024
1 parent 376b351 commit 42b7124
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
8 changes: 7 additions & 1 deletion cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func NewApplyCommand() *cli.Command {
Value: false,
Hidden: true,
},
&cli.BoolFlag{
Name: "force-upgrade",
Usage: "force upgrade to run on compatible components, even if it doesn't look necessary",
Value: false,
Hidden: true,
},
}...),
Before: actions(initLogger, startUpgradeCheck, initAnalytics, checkLicense, initExec),
After: actions(closeAnalytics, upgradeCheckResult),
Expand Down Expand Up @@ -78,7 +84,7 @@ func NewApplyCommand() *cli.Command {
os.Stdout.WriteString(fmt.Sprintf(" Mirantis Launchpad (c) 2022 Mirantis, Inc. %s\n\n", version.Version))
}

err = product.Apply(ctx.Bool("disable-cleanup"), ctx.Bool("force"), ctx.Int("concurrency"))
err = product.Apply(ctx.Bool("disable-cleanup"), ctx.Bool("force"), ctx.Int("concurrency"), ctx.Bool("force-upgrade"))

if err != nil {
analytics.TrackEvent("Cluster Apply Failed", nil)
Expand Down
1 change: 1 addition & 0 deletions pkg/product/common/api/mcr_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type MCRConfig struct {
InstallURLWindows string `yaml:"installURLWindows,omitempty"`
Channel string `yaml:"channel,omitempty"`
Prune bool `yaml:"prune,omitempty"`
ForceUpgrade bool `yaml:"forceUpgrade,omitempty"`
}

// UnmarshalYAML puts in sane defaults when unmarshaling from yaml.
Expand Down
4 changes: 2 additions & 2 deletions pkg/product/mke/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// Apply - installs Docker Enterprise (MKE, MSR, MCR) on the hosts that are defined in the config.
func (p *MKE) Apply(disableCleanup, force bool, concurrency int) error {
func (p *MKE) Apply(disableCleanup, force bool, concurrency int, forceUpgrade bool) error {
phaseManager := phase.NewManager(&p.ClusterConfig)
phaseManager.SkipCleanup = disableCleanup

Expand All @@ -31,7 +31,7 @@ func (p *MKE) Apply(disableCleanup, force bool, concurrency int) error {
// begin mcr/mke phases
&mke.ConfigureMCR{},
&mke.InstallMCR{},
&mke.UpgradeMCR{Concurrency: concurrency},
&mke.UpgradeMCR{Concurrency: concurrency, ForceUpgrade: forceUpgrade},
&mke.RestartMCR{},
&mke.LoadImages{},
&mke.AuthenticateDocker{},
Expand Down
10 changes: 8 additions & 2 deletions pkg/product/mke/phase/upgrade_mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (
type UpgradeMCR struct {
phase.Analytics
phase.HostSelectPhase
Concurrency int

Concurrency int
ForceUpgrade bool
}

// HostFilterFunc returns true for hosts that do not have engine installed.
func (p *UpgradeMCR) HostFilterFunc(h *api.Host) bool {
return h.Metadata.MCRVersion != p.Config.Spec.MCR.Version
return p.ForceUpgrade || h.Metadata.MCRVersion != p.Config.Spec.MCR.Version
}

// Prepare collects the hosts.
Expand Down Expand Up @@ -69,6 +71,10 @@ func (p *UpgradeMCR) upgradeMCRs() error {
}
}

if p.ForceUpgrade {
log.Info("Force Upgrade option is enabled. Hosts are going to be upgraded, even it they don't appear to need it.")
}

// Upgrade managers individually
for _, h := range managers {
err := p.upgradeMCR(h)
Expand Down
2 changes: 1 addition & 1 deletion pkg/product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package product

// Product is an interface that represents a product that launchpad can manage.
type Product interface {
Apply(disableCleanup, force bool, concurrency int) error
Apply(disableCleanup, force bool, concurrency int, forceUpgrade bool) error
Reset() error
Describe(reportName string) error
ClientConfig() error
Expand Down

0 comments on commit 42b7124

Please sign in to comment.