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

fix: don't require cluster for cli upgrade #8738

Merged
merged 1 commit into from
Jan 15, 2025
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
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 @@
"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 @@
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 @@
// 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 @@
}
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
Loading