Skip to content

Commit 6892888

Browse files
committed
PRODENG-2966 mcr upgrade skip detect refactor
- mcr upgrade now: - skips if an install was just run - skips if the host config has the "skipUpgrade" flag ALSO: - small go fmt change on the helm testutil Signed-off-by: James Nesbitt <[email protected]>
1 parent 6832c4e commit 6892888

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

pkg/helm/testutil.go

-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ func NewHelmTestClient(t *testing.T, options ...HelmTestClientOption) *Helm {
7777
}
7878
}
7979

80-
81-
8280
// InstallCertManagerChart installs cert-manager
8381
// to use as a chart to query for testing purposes and returns the
8482
// ReleaseDetails for the chart as well as a function to uninstall the chart.

pkg/mcr/mcr.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
)
1010

1111
// EnsureMCRVersion ensure that MCR is running after install/upgrade, and update the host information
12-
// @NOTE will reboot the machine if MCR isn't detected, and MCR can be force restarted if desired (I could drop the mcr restart, but I kept it in case we want a run-time flag for it.)
12+
// @NOTE will reboot the machine if MCR isn't detected
1313
// @SEE PRODENG-2789 : we no longer perform version checks, as the MCR versions don't always match the spec string.
14-
func EnsureMCRVersion(h *api.Host, specMcrVersion string, forceMCRRestart bool) error {
14+
func EnsureMCRVersion(h *api.Host, specMcrVersion string) error {
1515
currentVersion, err := h.MCRVersion()
1616
if err != nil {
1717
if err := h.Reboot(); err != nil {
@@ -21,20 +21,12 @@ func EnsureMCRVersion(h *api.Host, specMcrVersion string, forceMCRRestart bool)
2121
if err != nil {
2222
return fmt.Errorf("%s: failed to query container runtime version after installation: %w", h, err)
2323
}
24-
} else if !forceMCRRestart {
25-
err = h.Configurer.RestartMCR(h)
26-
if err != nil {
27-
return fmt.Errorf("%s: failed to restart container runtime: %w", h, err)
28-
}
29-
currentVersion, err = h.MCRVersion()
30-
if err != nil {
31-
return fmt.Errorf("%s: failed to query container runtime version after restart: %w", h, err)
32-
}
24+
// as we rebooted the machine, no need to also restart MCR
25+
h.Metadata.MCRRestartRequired = false
3326
}
3427

3528
log.Infof("%s: MCR version %s (requested: %s)", h, currentVersion, specMcrVersion)
3629
h.Metadata.MCRVersion = currentVersion
37-
h.Metadata.MCRRestartRequired = false
3830

3931
return nil
4032
}

pkg/product/mke/api/host.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (h *Host) ConfigureMCR() error {
348348

349349
if h.Metadata.MCRVersion != "" {
350350
h.Metadata.MCRRestartRequired = true
351-
log.Debugf("%s: host marked for mcr restart", h)
351+
log.Debugf("%s: host marked for mcr restart as MCR config was changed", h)
352352
}
353353

354354
return nil

pkg/product/mke/phase/install_mcr.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ func (p *InstallMCR) installMCR(h *api.Host) error {
7070
return fmt.Errorf("%s: failed to authorize docker: %w", h, err)
7171
}
7272

73-
// check MCR is running, maybe rebooting and updating metadata (don't bother restarting MCR, as we just installed/started it
74-
if err := mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version, false); err != nil {
73+
// check MCR is running, maybe rebooting and updating metadata
74+
if err := mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version); err != nil {
7575
return fmt.Errorf("failed while attempting to ensure the installed version %w", err)
7676
}
7777

78+
log.Infof("%s: mcr installed", h)
7879
h.Metadata.MCRInstalled = true
80+
h.Metadata.MCRRestartRequired = false // we just installed, so a restart is not required
7981
return nil
8082
}

pkg/product/mke/phase/uninstall_mcr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (p *UninstallMCR) uninstallMCR(h *api.Host, config *api.ClusterConfig) erro
6565
}
6666

6767
if err := h.Configurer.UninstallMCR(h, h.Metadata.MCRInstallScript, config.Spec.MCR); err != nil {
68-
return fmt.Errorf("%s: uninstall container runtime: %w", h, err)
68+
return fmt.Errorf("%s: uninstall container runtime failed: %w", h, err)
6969
}
7070

7171
log.Infof("%s: mirantis container runtime uninstalled", h)

pkg/product/mke/phase/upgrade_mcr.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ type UpgradeMCR struct {
2727

2828
// HostFilterFunc returns true for hosts that do not have engine installed.
2929
func (p *UpgradeMCR) HostFilterFunc(h *api.Host) bool {
30-
if h.Metadata.MCRVersion != p.Config.Spec.MCR.Version {
31-
return true
30+
if h.Metadata.MCRInstalled {
31+
// we just did an install, no need to run an upgrade
32+
return false
3233
}
3334
if h.MCRUpgradeSkip {
3435
log.Warnf("%s: MCR Upgrade configuration for host instructs launchpad to skip upgrading this host.", h)
3536
return false
3637
}
37-
if p.ForceUpgrade && !h.Metadata.MCRInstalled {
38+
if p.ForceUpgrade {
3839
log.Warnf("%s: MCR version is already %s but attempting an upgrade anyway because --force-upgrade was given", h, h.Metadata.MCRVersion)
3940
return true
4041
}
41-
return false
42+
43+
// the following version check prevents upgrades on MCR<25, but MCR25 should always upgrade.
44+
return h.Metadata.MCRVersion != p.Config.Spec.MCR.Version
4245
}
4346

4447
// Prepare collects the hosts.
@@ -180,10 +183,14 @@ func (p *UpgradeMCR) upgradeMCR(h *api.Host) error {
180183
return fmt.Errorf("retry count exceeded: %w", err)
181184
}
182185

183-
// check MCR is running, and updating metadata
184-
if err := mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version, false); err != nil {
186+
// ensure that MCR is installed and running
187+
if err := mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version); err != nil {
185188
return fmt.Errorf("failed while attempting to ensure the installed version: %w", err)
186189
}
187190

191+
log.Infof("%s: mcr upgrade has been run", h)
192+
log.Debugf("%s: mcr upgrade means that any planned MCR restarts are cancelled", h)
193+
// the upgraded machine "may" have been restarted. We don't really know, but we err on the side of reducing restarts. We likely need a flag to force a restart.
194+
h.Metadata.MCRRestartRequired = false
188195
return nil
189196
}

0 commit comments

Comments
 (0)