Skip to content

Commit

Permalink
Merge pull request #2136 from rohantmp/fixVersionCheck
Browse files Browse the repository at this point in the history
fix(cli): improve UX around vcluster upgrade command
  • Loading branch information
FabianKramm authored Sep 16, 2024
2 parents e7464fb + 6e00f0c commit 10d3d18
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ func CheckForNewerVersion() (string, error) {
errLatestVersion = err
return
}

v := semver.MustParse(version)
// if latest not found or latest version found is less than or equal to the current version, do not upgrade
if !found || latest.Version.Compare(v) != 1 {
if !found {
return
}

Expand Down Expand Up @@ -147,13 +145,27 @@ func Upgrade(flagVersion string, log log.Logger) error {
return nil
}

newerVersion, err := CheckForNewerVersion()
latestStable, err := CheckForNewerVersion()
if err != nil {
return err
}
if newerVersion == "" {
if latestStable == "" {
log.Infof("Current binary is the latest version: %s", version)
return nil
}

version = GetVersion()
semverCurrentVersion := semver.MustParse(version)
semverLatestStableVersion := semver.MustParse(latestStable)
cmp := semverLatestStableVersion.Compare(semverCurrentVersion)
if cmp == 0 {
log.Infof("Current binary is the latest version: %s", version)
return nil
} else if cmp == -1 {
command := fmt.Sprintf("%s upgrade --version %s", os.Args[0], latestStable)
log.Infof("Current binary version is newer than the latest stable version: %q", version)
log.Infof("To upgrade to latest stable use %q.", command)
return nil
}

v := semver.MustParse(version)
Expand Down

0 comments on commit 10d3d18

Please sign in to comment.