From 1ad92caf16c3385f2e163fb46648a10a471362ef Mon Sep 17 00:00:00 2001 From: James Nesbitt Date: Wed, 27 Nov 2024 11:15:53 +0200 Subject: [PATCH] PRODENG-2789 don't validate MCR version (#522) * PRODENG-2789 don't validate MCR version - we no longer validate installed MCR version compared to config spec version string - make the EnsureMCR function responsible for updating metadata (simplify, dedup) WHY? MCR versions installed no longer match the spec string, so we can't tell if the version installed was the expected version, nor can we tell if there is a newer version that can be installed, so we always run the install script, and never test version. ALSO: - fixed the full smoke GH action, as the branches were cleaned up and renamed Signed-off-by: James Nesbitt --- .github/workflows/smoke-test-full.yaml | 3 +-- pkg/mcr/mcr.go | 18 +++++++++++------- pkg/product/mke/phase/install_mcr.go | 13 +++++-------- pkg/product/mke/phase/upgrade_mcr.go | 13 +++++-------- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/.github/workflows/smoke-test-full.yaml b/.github/workflows/smoke-test-full.yaml index 4261c275..70cf2621 100644 --- a/.github/workflows/smoke-test-full.yaml +++ b/.github/workflows/smoke-test-full.yaml @@ -3,8 +3,7 @@ name: Smoke Full Test on: push: branches: - - master - - v1.5.9-release-branch + - main paths: - '**.go' - '**.tf' diff --git a/pkg/mcr/mcr.go b/pkg/mcr/mcr.go index 57e262a3..8d41b356 100644 --- a/pkg/mcr/mcr.go +++ b/pkg/mcr/mcr.go @@ -3,11 +3,14 @@ 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 +20,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 +30,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: MCR 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 }