Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSD-14573-warn-user-for-old-cli #113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}