diff --git a/pkg/mcr/mcr.go b/pkg/mcr/mcr.go index 57e262a3..2824c625 100644 --- a/pkg/mcr/mcr.go +++ b/pkg/mcr/mcr.go @@ -1,13 +1,17 @@ + package mcr import ( "fmt" - "github.com/Mirantis/mcc/pkg/constant" "github.com/Mirantis/mcc/pkg/product/mke/api" + log "github.com/sirupsen/logrus" ) -func EnsureMCRVersion(h *api.Host, specMcrVersion string) error { +// EnsureMCRVersion ensure that MCR is running after install/upgrade, and update the host information +// @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.) +// @SEE PRODENG-2789 : we no longer perform version checks, as the MCR versions don't always match the spec string. +func EnsureMCRVersion(h *api.Host, specMcrVersion string, forceMCRRestart bool) error { currentVersion, err := h.MCRVersion() if err != nil { if err := h.Reboot(); err != nil { @@ -17,8 +21,7 @@ func EnsureMCRVersion(h *api.Host, specMcrVersion string) error { if err != nil { return fmt.Errorf("%s: failed to query container runtime version after installation: %w", h, err) } - } - if currentVersion != specMcrVersion { + } else if !forceMCRRestart { err = h.Configurer.RestartMCR(h) if err != nil { return fmt.Errorf("%s: failed to restart container runtime: %w", h, err) @@ -28,8 +31,10 @@ func EnsureMCRVersion(h *api.Host, specMcrVersion string) error { return fmt.Errorf("%s: failed to query container runtime version after restart: %w", h, err) } } - if currentVersion != specMcrVersion { - return fmt.Errorf("%s: %w: container runtime version not %s after upgrade", h, constant.ErrVersionMismatch, specMcrVersion) - } + + log.Infof("%s: mirantis container runtime version %s (requested:%s)", h, currentVersion, specMcrVersion) + h.Metadata.MCRVersion = currentVersion + h.Metadata.MCRRestartRequired = false + return nil } diff --git a/pkg/product/mke/phase/install_mcr.go b/pkg/product/mke/phase/install_mcr.go index f1da0e95..d5dc4121 100644 --- a/pkg/product/mke/phase/install_mcr.go +++ b/pkg/product/mke/phase/install_mcr.go @@ -53,7 +53,7 @@ func (p *InstallMCR) Run() error { } func (p *InstallMCR) installMCR(h *api.Host) error { - err := retry.Do( + if err := retry.Do( func() error { log.Infof("%s: installing container runtime (%s)", h, p.Config.Spec.MCR.Version) if err := h.Configurer.InstallMCR(h, h.Metadata.MCRInstallScript, p.Config.Spec.MCR); err != nil { @@ -62,22 +62,19 @@ func (p *InstallMCR) installMCR(h *api.Host) error { } return nil }, - ) - if err != nil { + ); err != nil { return fmt.Errorf("retry count exceeded: %w", err) } if err := h.AuthorizeDocker(); err != nil { return fmt.Errorf("%s: failed to authorize docker: %w", h, err) } - err = mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version) - if err != nil { + + // check MCR is running, maybe rebooting and updating metadata (don't bother restarting MCR, as we just installed/started it + if err := mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version, false); err != nil { return fmt.Errorf("failed while attempting to ensure the installed version %w", err) } - log.Infof("%s: mirantis container runtime version %s installed", h, p.Config.Spec.MCR.Version) - h.Metadata.MCRVersion = p.Config.Spec.MCR.Version - h.Metadata.MCRRestartRequired = false h.Metadata.MCRInstalled = true return nil } diff --git a/pkg/product/mke/phase/upgrade_mcr.go b/pkg/product/mke/phase/upgrade_mcr.go index b4cb1dd4..5ea58ec1 100644 --- a/pkg/product/mke/phase/upgrade_mcr.go +++ b/pkg/product/mke/phase/upgrade_mcr.go @@ -163,7 +163,7 @@ func (p *UpgradeMCR) upgradeMCRs() error { } func (p *UpgradeMCR) upgradeMCR(h *api.Host) error { - err := retry.Do( + if err := retry.Do( func() error { log.Infof("%s: upgrading container runtime (%s -> %s)", h, h.Metadata.MCRVersion, p.Config.Spec.MCR.Version) if err := h.Configurer.InstallMCR(h, h.Metadata.MCRInstallScript, p.Config.Spec.MCR); err != nil { @@ -171,18 +171,15 @@ func (p *UpgradeMCR) upgradeMCR(h *api.Host) error { } return nil }, - ) - if err != nil { + ); err != nil { log.Errorf("%s: failed to update container runtime -> %s", h, err.Error()) return fmt.Errorf("retry count exceeded: %w", err) } - err = mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version) - if err != nil { + + // check MCR is running, and updating metadata + if err := mcr.EnsureMCRVersion(h, p.Config.Spec.MCR.Version, false); err != nil { return fmt.Errorf("failed while attempting to ensure the installed version: %w", err) } - log.Infof("%s: upgraded to mirantis container runtime version %s", h, p.Config.Spec.MCR.Version) - h.Metadata.MCRVersion = p.Config.Spec.MCR.Version - h.Metadata.MCRRestartRequired = false return nil }