Skip to content

Commit

Permalink
OSD-14573 - Warn user for using old backplane CLI
Browse files Browse the repository at this point in the history
OSD-14573 - Add nil safety for command and context objects

OSD-14573 - Change message level to debug

OSD-14573 - Fix version mismatch due to extra characters in GitHub API tags

Update cmd/ocm-backplane/login/login.go

Co-authored-by: Supreeth Basabattini <sbasabat@redhat.com>

OSD-14573 - Move backplane version check functionality to utils

OSD-14573 - Add backplane version check to cloud console
  • Loading branch information
Tafhim committed May 24, 2023
1 parent e9a6d0d commit d887c21
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/ocm-backplane/cloud/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func init() {
func runConsole(cmd *cobra.Command, argv []string) (err error) {
var clusterKey string

utils.CheckBackplaneVersion(cmd)

err = validateParams(argv)

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/ocm-backplane/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func init() {
func runLogin(cmd *cobra.Command, argv []string) (err error) {
var clusterKey string

utils.CheckBackplaneVersion(cmd)

// Get The cluster ID
if len(argv) == 1 {
// if explicitly one cluster key given, use it to log in.
Expand Down
43 changes: 43 additions & 0 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
"reflect"
"strings"

logger "github.com/sirupsen/logrus"
netUrl "net/url"

BackplaneApi "github.com/openshift/backplane-api/pkg/client"

"github.com/openshift/backplane-cli/internal/github"
"github.com/openshift/backplane-cli/pkg/info"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
Expand Down Expand Up @@ -205,3 +209,42 @@ func RemoveTempKubeConfig() {
os.Remove(path)
}
}

// checkBackplaneVersion checks the backplane version and aims to only
// report any errors encountered in the process in order to
// avoid calling functions act as usual
func CheckBackplaneVersion(cmd *cobra.Command) {
if cmd == nil {
logger.Debugln("Command object is nil")
return
}

ctx := cmd.Context()
if ctx == nil {
logger.Debugln("Context object is nil")
return
}

git := github.NewClient()
if err := git.CheckConnection(); err != nil {
logger.WithField("Connection error", err).Warn("Could not connect to GitHub")
return
}

// Get the latest version from the GitHub API
latestVersionTag, err := git.GetLatestVersion(ctx)
if err != nil {
logger.WithField("Fetch error", err).Warn("Could not fetch latest version from GitHub")
return
}
// GitHub API keeps the v prefix in front which causes mismatch with info.Version
latestVersion := strings.TrimLeft(latestVersionTag.TagName, "v")

// Check if the local version is already up-to-date
if latestVersion == info.Version {
logger.WithField("Current version", info.Version).Info("Already up-to-date")
return
}

logger.WithField("Current version", info.Version).WithField("Latest version", latestVersion).Warn("Your Backplane CLI is not up to date. Please run the command 'ocm backplane upgrade' to upgrade to the latest version")
}

0 comments on commit d887c21

Please sign in to comment.