diff --git a/pkg/cmd/upgrade/upgrade_cli.go b/pkg/cmd/upgrade/upgrade_cli.go index 83b216d266..40fee14f76 100644 --- a/pkg/cmd/upgrade/upgrade_cli.go +++ b/pkg/cmd/upgrade/upgrade_cli.go @@ -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" @@ -59,7 +58,6 @@ const ( type CLIOptions struct { CommandRunner cmdrunner.CommandRunner GitClient gitclient.Interface - JXClient versioned.Interface Version string VersionStreamGitURL string FromEnvironment bool @@ -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) @@ -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) + } + + env, err := jxenv.GetDevEnvironment(jXClient, jxcore.DefaultNamespace) if err == nil { if env.Spec.Source.URL != "" { gitURL = env.Spec.Source.URL diff --git a/pkg/cmd/upgrade/upgrade_cli_test.go b/pkg/cmd/upgrade/upgrade_cli_test.go index c19c5e852a..74f2b59e2f 100644 --- a/pkg/cmd/upgrade/upgrade_cli_test.go +++ b/pkg/cmd/upgrade/upgrade_cli_test.go @@ -2,7 +2,6 @@ package upgrade_test import ( "fmt" - "os" "testing" "github.com/jenkins-x/jx-logging/v3/pkg/log" @@ -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" ) @@ -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)