Skip to content

Commit

Permalink
fix: don't require cluster for cli upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Mårten Svantesson <Marten.Svantesson@ticket.se>
  • Loading branch information
msvticket committed Jan 15, 2025
1 parent 3d3bea0 commit 514d22a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 6 additions & 8 deletions pkg/cmd/upgrade/upgrade_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/jenkins-x/jx/pkg/cmd/version"

jxcore "github.com/jenkins-x/jx-api/v4/pkg/apis/core/v4beta1"
"github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned"
"github.com/jenkins-x/jx-helpers/v3/pkg/termcolor"
"github.com/rhysd/go-github-selfupdate/selfupdate"

Expand Down Expand Up @@ -59,7 +58,6 @@ const (
type CLIOptions struct {
CommandRunner cmdrunner.CommandRunner
GitClient gitclient.Interface
JXClient versioned.Interface
Version string
VersionStreamGitURL string
FromEnvironment bool
Expand Down Expand Up @@ -88,12 +86,7 @@ func NewCmdUpgradeCLI() (*cobra.Command, *CLIOptions) {
// Run implements the command
func (o *CLIOptions) Run() error {
var err error
o.JXClient, err = jxclient.LazyCreateJXClient(o.JXClient)
if err != nil {
return fmt.Errorf("failed to create jx client: %w", err)
}

// upgrading to a specific version is not yet supported in brew so lets disable it for upgrades
candidateInstallVersion, err := o.candidateInstallVersion()
if err != nil {
return fmt.Errorf("failed to find jx cli version: %w", err)
Expand Down Expand Up @@ -179,7 +172,12 @@ func (o *CLIOptions) getVersionStreamURL(gitURL string) (string, error) {
}
if o.FromEnvironment {
// lookup the cluster git repo from the dev environment and use that as the versionstream
env, err := jxenv.GetDevEnvironment(o.JXClient, jxcore.DefaultNamespace)
jXClient, err := jxclient.LazyCreateJXClient(nil)
if err != nil {
return "", fmt.Errorf("failed to create jx client: %w", err)
}

Check warning on line 178 in pkg/cmd/upgrade/upgrade_cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/upgrade/upgrade_cli.go#L175-L178

Added lines #L175 - L178 were not covered by tests

env, err := jxenv.GetDevEnvironment(jXClient, jxcore.DefaultNamespace)

Check warning on line 180 in pkg/cmd/upgrade/upgrade_cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/upgrade/upgrade_cli.go#L180

Added line #L180 was not covered by tests
if err == nil {
if env.Spec.Source.URL != "" {
gitURL = env.Spec.Source.URL
Expand Down
5 changes: 0 additions & 5 deletions pkg/cmd/upgrade/upgrade_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package upgrade_test

import (
"fmt"
"os"
"testing"

"github.com/jenkins-x/jx-logging/v3/pkg/log"
Expand All @@ -11,7 +10,6 @@ import (

"github.com/blang/semver"

jxfake "github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
// typev1 "github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned/typed/jenkins.io/v1"
)
Expand Down Expand Up @@ -49,10 +47,7 @@ func TestNeedsUpgrade(t *testing.T) {
}

func TestNewCmdUpgradeCLI(t *testing.T) {
kubeClient := jxfake.NewSimpleClientset()
os.Setenv("KUBECONFIG", "testdata/kubeconfig")
cmd, o := upgrade.NewCmdUpgradeCLI()
o.JXClient = kubeClient
o.Version = "3.2.238"
err := cmd.Execute()
assert.NoError(t, err)
Expand Down

0 comments on commit 514d22a

Please sign in to comment.