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, so we always run the install script, and never test
version.

Signed-off-by: James Nesbitt <[email protected]>
  • Loading branch information
james-nesbitt committed Nov 26, 2024
1 parent ea2414c commit db95a39
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
@@ -1,13 +1,17 @@

Check failure on line 1 in pkg/mcr/mcr.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
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 {
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 !forceMCRRestart {
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 (requested:%s)", h, currentVersion, specMcrVersion)
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, 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
}
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, 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 db95a39

Please sign in to comment.