From 42b7124c2515cc56ba4565aa063fa6bd5d552895 Mon Sep 17 00:00:00 2001 From: James Nesbitt Date: Thu, 8 Feb 2024 13:01:00 +0200 Subject: [PATCH] PRODENG-2528 allow force mcr upgrade 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 --- cmd/apply.go | 8 +++++++- pkg/product/common/api/mcr_config.go | 1 + pkg/product/mke/apply.go | 4 ++-- pkg/product/mke/phase/upgrade_mcr.go | 10 ++++++++-- pkg/product/product.go | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/apply.go b/cmd/apply.go index 2758f4208..1d4edec8c 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -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), @@ -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) diff --git a/pkg/product/common/api/mcr_config.go b/pkg/product/common/api/mcr_config.go index c50df2606..2c1fa77ec 100644 --- a/pkg/product/common/api/mcr_config.go +++ b/pkg/product/common/api/mcr_config.go @@ -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. diff --git a/pkg/product/mke/apply.go b/pkg/product/mke/apply.go index 76025c985..979594533 100644 --- a/pkg/product/mke/apply.go +++ b/pkg/product/mke/apply.go @@ -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 @@ -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{}, diff --git a/pkg/product/mke/phase/upgrade_mcr.go b/pkg/product/mke/phase/upgrade_mcr.go index 6a9aa238b..3c0676e90 100644 --- a/pkg/product/mke/phase/upgrade_mcr.go +++ b/pkg/product/mke/phase/upgrade_mcr.go @@ -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. @@ -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) diff --git a/pkg/product/product.go b/pkg/product/product.go index ede243c63..32ea22fa7 100644 --- a/pkg/product/product.go +++ b/pkg/product/product.go @@ -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