Skip to content

Commit

Permalink
Merge pull request #103 from giusdp/main
Browse files Browse the repository at this point in the history
feat: add operator version check
  • Loading branch information
francescotimperi authored Sep 29, 2023
2 parents 8a6fb13 + 5ad8016 commit 60b34b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 20 additions & 0 deletions prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/Masterminds/semver"
git "github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -136,13 +137,21 @@ func pullTasks(force, silent bool) error {

// check if the version is up to date, if not warn the user
if nuvVersion.LessThan(nuvRootVersion) {
fmt.Println()
fmt.Printf("Your nuv version (%v) is older than the required version in nuvroot.json (%v).\n", nuvVersion, nuvRootVersion)
fmt.Println("Attempting to update nuv...")
if err := autoCLIUpdate(); err != nil {
return err
}
}

err = checkOperatorVersion(nuvRoot.Config)
if err == nil {
fmt.Println()
fmt.Println("New operator version detected!")
fmt.Println("Current deployed operator can be updated with: nuv update operator")
}

return nil
}

Expand Down Expand Up @@ -209,8 +218,19 @@ func locateNuvRootSearch(cur string) string {
}

func autoCLIUpdate() error {
trace("autoCLIUpdate")
cmd := exec.Command("nuv", "update", "cli")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func checkOperatorVersion(nuvRootConfig map[string]interface{}) error {
trace("checkOperatorVersion")
images := nuvRootConfig["images"].(map[string]interface{})
operator := images["operator"].(string)
opVer := strings.Split(operator, ":")[1]

cmd := exec.Command("nuv", "util", "check-operator-version", opVer)
return cmd.Run()
}
7 changes: 3 additions & 4 deletions tools/needupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package tools

import (
"errors"
"flag"
"fmt"

Expand All @@ -29,8 +28,8 @@ func needUpdateTool(args []string) error {

flag := flag.NewFlagSet("needupdate", flag.ExitOnError)
flag.Usage = func() {
fmt.Println(`Check if a semver version is greater than another semver version.
Returns 0 if greater, 1 otherwise.
fmt.Println(`Check if a semver version A > semver version B.
Exits with 0 if greater, 1 otherwise.
Usage:
nuv -needupdate <versionA> <versionB>
Expand Down Expand Up @@ -73,5 +72,5 @@ Options:`)
return nil
}

return errors.New("a <= b")
return fmt.Errorf("%s is not greater than %s", a, b)
}

0 comments on commit 60b34b5

Please sign in to comment.