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

Co-authored-by: Kimmo Lehto <[email protected]>
Signed-off-by: James Nesbitt <[email protected]>
  • Loading branch information
james-nesbitt and kke committed Feb 8, 2024
1 parent c758b02 commit dcfcbab
Show file tree
Hide file tree
Showing 5 changed files with 22 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 @@ -44,6 +44,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 @@ -79,7 +85,7 @@ func NewApplyCommand() *cli.Command {
fmt.Fprintf(os.Stdout, " 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)
return fmt.Errorf("failed to apply cluster: %w", err)
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 @@ -12,7 +12,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 @@ -30,7 +30,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
13 changes: 11 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,21 @@ 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
if h.Metadata.MCRVersion != p.Config.Spec.MCR.Version {
return true
}
if p.ForceUpgrade {
log.Warnf("%s: MCR version is already %s but attempting an upgrade anyway because --force-upgrade was given", h, h.Metadata.MCRVersion)
return true
}
return false
}

// Prepare collects the hosts.
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 dcfcbab

Please sign in to comment.