Skip to content

Commit

Permalink
PRODENG-2789 don't validate MCR version
Browse files Browse the repository at this point in the history
- 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

Signed-off-by: James Nesbitt <[email protected]>
  • Loading branch information
james-nesbitt committed Nov 26, 2024
1 parent ea2414c commit 2d3c895
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
19 changes: 12 additions & 7 deletions pkg/mcr/mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package mcr
import (
"fmt"

"github.com/Mirantis/mcc/pkg/constant"
log "github.com/sirupsen/logrus"

"github.com/Mirantis/mcc/pkg/product/mke/api"
)

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, otherwise it will restart MCR (skippable using the arg)
// @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, skipMCRRestart bool) error {
currentVersion, err := h.MCRVersion()
if err != nil {
if err := h.Reboot(); err != nil {
Expand All @@ -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 !skipMCRRestart {
err = h.Configurer.RestartMCR(h)
if err != nil {
return fmt.Errorf("%s: failed to restart container runtime: %w", h, err)
Expand All @@ -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", h, currentVersion)
h.Metadata.MCRVersion = currentVersion
h.Metadata.MCRRestartRequired = false

return nil
}
13 changes: 5 additions & 8 deletions pkg/product/mke/phase/install_mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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, true); err != nil {

Check failure on line 74 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err

Check failure on line 74 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err

Check failure on line 74 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err

Check failure on line 74 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / unit-test (ubuntu-latest)

undefined: err

Check failure on line 74 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / unit-test (macos-latest)

undefined: err
return fmt.Errorf("failed while attempting to ensure the installed version %w", err)

Check failure on line 75 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err (typecheck)

Check failure on line 75 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err) (typecheck)

Check failure on line 75 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err) (typecheck)

Check failure on line 75 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / unit-test (ubuntu-latest)

undefined: err

Check failure on line 75 in pkg/product/mke/phase/install_mcr.go

View workflow job for this annotation

GitHub Actions / unit-test (macos-latest)

undefined: 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
}
13 changes: 5 additions & 8 deletions pkg/product/mke/phase/upgrade_mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,23 @@ 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 {
return fmt.Errorf("%s: failed to install container runtime: %w", h, err)
}
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, maybe rebooting/restarting-mcr 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
}

0 comments on commit 2d3c895

Please sign in to comment.