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: argocd version --client tries to connect server #8341

Merged
merged 10 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
16 changes: 9 additions & 7 deletions cmd/argocd/commands/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
"github.com/spf13/cobra"
"golang.org/x/term"

"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/initialize"
argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
accountpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/account"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/headless"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/session"
"github.com/argoproj/argo-cd/v2/server/rbacpolicy"
"github.com/argoproj/argo-cd/v2/util/cli"
Expand Down Expand Up @@ -72,7 +74,7 @@ has appropriate RBAC permissions to change other accounts.
c.HelpFunc()(c, args)
os.Exit(1)
}
acdClient := argocdclient.NewClientOrDie(clientOpts)
acdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do this a little bit cleaner. Everywhere we repeat a call to initialize.RetrieveContextIfChanged when initializing the client. i.e.:

headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))

Can we somehow improve/reduce this to:

headless.NewClientOrDie(clientOpts)

Can we update the clientOpts to have a .context field so we don't have to parse this everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was initially thinking of doing that but this specific context is only required when we need to create the local server and the CLientOptions struct is a more general client pkg data that might be used by other API clients and binaries so I felt it might be better to keep it specific to the cli only instead of modifying the original struct. But we can add it in there too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. But unfortunately, there's already a clientOpts.Core which is a useless flag to the generic argocd client package. So for better or worse, we already have CLI specific flag which made its way into in clientOpts.

If we want to be slightly cleaner about this, we could preserve the existing API client constructor. e.g.:

apiclient.NewClientOrDie(clientOpts)

And introduce a CLI specific constructor that accepts the cobra.Command as a second argument:

headless.NewClientOrDie(clientOpts, c)

The headless.NewClientOrDie would call:

initialize.RetrieveContextIfChanged(c.Flag("context"))
...
apiclient.NewClientOrDie(clientOpts)

Then we don't have to introduce more useless options to clientOpts which aren't really used by the API client package. And we could even remove the Core option from clientOpts. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me, also we'll shift the headless.NewClientOrDie to the CLI pkg so it will not technically change anything in the apiclient pkg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

conn, usrIf := acdClient.NewAccountClientOrDie()
defer io.Close(conn)

Expand Down Expand Up @@ -146,7 +148,7 @@ func NewAccountGetUserInfoCommand(clientOpts *argocdclient.ClientOptions) *cobra
os.Exit(1)
}

conn, client := argocdclient.NewClientOrDie(clientOpts).NewSessionClientOrDie()
conn, client := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewSessionClientOrDie()
defer io.Close(conn)

ctx := context.Background()
Expand Down Expand Up @@ -201,7 +203,7 @@ Resources: %v
os.Exit(1)
}

conn, client := argocdclient.NewClientOrDie(clientOpts).NewAccountClientOrDie()
conn, client := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewAccountClientOrDie()
defer io.Close(conn)

ctx := context.Background()
Expand Down Expand Up @@ -241,7 +243,7 @@ func NewAccountListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman
Example: "argocd account list",
Run: func(c *cobra.Command, args []string) {

conn, client := argocdclient.NewClientOrDie(clientOpts).NewAccountClientOrDie()
conn, client := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewAccountClientOrDie()
defer io.Close(conn)

ctx := context.Background()
Expand Down Expand Up @@ -287,7 +289,7 @@ argocd account get
# Get details for an account by name
argocd account get --account <account-name>`,
Run: func(c *cobra.Command, args []string) {
clientset := argocdclient.NewClientOrDie(clientOpts)
clientset := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))

if account == "" {
account = getCurrentAccount(clientset).Username
Expand Down Expand Up @@ -359,7 +361,7 @@ argocd account generate-token
argocd account generate-token --account <account-name>`,
Run: func(c *cobra.Command, args []string) {

clientset := argocdclient.NewClientOrDie(clientOpts)
clientset := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, client := clientset.NewAccountClientOrDie()
defer io.Close(conn)
if account == "" {
Expand Down Expand Up @@ -401,7 +403,7 @@ argocd account delete-token --account <account-name> ID`,
}
id := args[0]

clientset := argocdclient.NewClientOrDie(clientOpts)
clientset := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, client := clientset.NewAccountClientOrDie()
defer io.Close(conn)
if account == "" {
Expand Down
9 changes: 4 additions & 5 deletions cmd/argocd/commands/admin/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"sort"
"time"

"github.com/argoproj/argo-cd/v2/util/argo"

"github.com/ghodss/yaml"
"github.com/spf13/cobra"
apiv1 "k8s.io/api/core/v1"
Expand All @@ -29,7 +27,8 @@ import (
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
appinformers "github.com/argoproj/argo-cd/v2/pkg/client/informers/externalversions"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
argocdclient "github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/argoproj/argo-cd/v2/util/argo"
cacheutil "github.com/argoproj/argo-cd/v2/util/cache"
appstatecache "github.com/argoproj/argo-cd/v2/util/cache/appstate"
"github.com/argoproj/argo-cd/v2/util/cli"
Expand Down Expand Up @@ -263,7 +262,7 @@ func NewReconcileCommand() *cobra.Command {
errors.CheckError(err)
repoServerAddress = fmt.Sprintf("localhost:%d", repoServerPort)
}
repoServerClient := apiclient.NewRepoServerClientset(repoServerAddress, 60, apiclient.TLSConfiguration{DisableTLS: false, StrictValidation: false})
repoServerClient := argocdclient.NewRepoServerClientset(repoServerAddress, 60, argocdclient.TLSConfiguration{DisableTLS: false, StrictValidation: false})

appClientset := appclientset.NewForConfigOrDie(cfg)
kubeClientset := kubernetes.NewForConfigOrDie(cfg)
Expand Down Expand Up @@ -327,7 +326,7 @@ func reconcileApplications(
kubeClientset kubernetes.Interface,
appClientset appclientset.Interface,
namespace string,
repoServerClient apiclient.Clientset,
repoServerClient argocdclient.Clientset,
selector string,
createLiveStateCache func(argoDB db.ArgoDB, appInformer kubecache.SharedIndexInformer, settingsMgr *settings.SettingsManager, server *metrics.MetricsServer) cache.LiveStateCache,
) ([]appReconcileResult, error) {
Expand Down
7 changes: 3 additions & 4 deletions cmd/argocd/commands/admin/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package admin
import (
"testing"

"github.com/argoproj/argo-cd/v2/test"

clustermocks "github.com/argoproj/gitops-engine/pkg/cache/mocks"
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
Expand All @@ -21,8 +19,9 @@ import (
"github.com/argoproj/argo-cd/v2/controller/metrics"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appfake "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned/fake"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
argocdclient "github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient/mocks"
"github.com/argoproj/argo-cd/v2/test"
"github.com/argoproj/argo-cd/v2/util/db"
"github.com/argoproj/argo-cd/v2/util/settings"
)
Expand Down Expand Up @@ -90,7 +89,7 @@ func TestGetReconcileResults_Refresh(t *testing.T) {
clusterCache := clustermocks.ClusterCache{}
clusterCache.On("IsNamespaced", mock.Anything).Return(true, nil)
repoServerClient := mocks.RepoServerServiceClient{}
repoServerClient.On("GenerateManifest", mock.Anything, mock.Anything).Return(&apiclient.ManifestResponse{
repoServerClient.On("GenerateManifest", mock.Anything, mock.Anything).Return(&argocdclient.ManifestResponse{
Manifests: []string{test.DeploymentManifest},
}, nil)
repoServerClientset := mocks.Clientset{RepoServerServiceClient: &repoServerClient}
Expand Down
10 changes: 6 additions & 4 deletions cmd/argocd/commands/admin/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (

"github.com/spf13/cobra"

"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/headless"
"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/initialize"
"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/headless"
"github.com/argoproj/argo-cd/v2/util/errors"
)

func NewDashboardCommand() *cobra.Command {
Expand All @@ -20,12 +22,12 @@ func NewDashboardCommand() *cobra.Command {
Use: "dashboard",
Short: "Starts Argo CD Web UI locally",
Run: func(cmd *cobra.Command, args []string) {
errors.CheckError(headless.StartLocalServer(&argocdclient.ClientOptions{Core: true}, initialize.RetrieveContextIfChanged(cmd.Flag("context")), &port, &address))
println(fmt.Sprintf("Argo CD UI is available at http://%s:%d", address, port))
<-context.Background().Done()
},
}
clientOpts := &apiclient.ClientOptions{Core: true}
headless.InitCommand(cmd, clientOpts, &port, &address)
initialize.InitCommand(cmd)
cmd.Flags().IntVar(&port, "port", common.DefaultPortAPIServer, "Listen on given port")
cmd.Flags().StringVar(&address, "address", common.DefaultAddressAPIServer, "Listen on given address")
return cmd
Expand Down
48 changes: 24 additions & 24 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
"time"
"unicode/utf8"

"github.com/argoproj/gitops-engine/pkg/sync/common"

"github.com/argoproj/gitops-engine/pkg/health"
"github.com/argoproj/gitops-engine/pkg/sync/common"
"github.com/argoproj/gitops-engine/pkg/sync/hook"
"github.com/argoproj/gitops-engine/pkg/sync/ignore"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
Expand All @@ -31,13 +30,14 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"

"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/initialize"
cmdutil "github.com/argoproj/argo-cd/v2/cmd/util"
"github.com/argoproj/argo-cd/v2/controller"
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
applicationpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
clusterpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/headless"
projectpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/project"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/settings"
settingspkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/settings"
Expand Down Expand Up @@ -133,7 +133,7 @@ func NewApplicationCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra.
argocd app create ksane --repo https://github.com/argoproj/argocd-example-apps.git --path plugins/kasane --dest-namespace default --dest-server https://kubernetes.default.svc --config-management-plugin kasane
`,
Run: func(c *cobra.Command, args []string) {
argocdClient := argocdclient.NewClientOrDie(clientOpts)
argocdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))

apps, err := cmdutil.ConstructApps(fileURL, appName, labels, annotations, args, appOpts, c.Flags())
errors.CheckError(err)
Expand Down Expand Up @@ -215,14 +215,14 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
c.HelpFunc()(c, args)
os.Exit(1)
}
acdClient := argocdclient.NewClientOrDie(clientOpts)
acdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, appIf := acdClient.NewApplicationClientOrDie()
defer argoio.Close(conn)
appName := args[0]
app, err := appIf.Get(context.Background(), &applicationpkg.ApplicationQuery{Name: &appName, Refresh: getRefreshType(refresh, hardRefresh)})
errors.CheckError(err)

pConn, projIf := argocdclient.NewClientOrDie(clientOpts).NewProjectClientOrDie()
pConn, projIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewProjectClientOrDie()
defer argoio.Close(pConn)
proj, err := projIf.Get(context.Background(), &projectpkg.ProjectQuery{Name: app.Spec.Project})
errors.CheckError(err)
Expand Down Expand Up @@ -292,7 +292,7 @@ func NewApplicationLogsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
c.HelpFunc()(c, args)
os.Exit(1)
}
acdClient := argocdclient.NewClientOrDie(clientOpts)
acdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, appIf := acdClient.NewApplicationClientOrDie()
defer argoio.Close(conn)
appName := args[0]
Expand Down Expand Up @@ -531,7 +531,7 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
}
ctx := context.Background()
appName := args[0]
argocdClient := argocdclient.NewClientOrDie(clientOpts)
argocdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, appIf := argocdClient.NewApplicationClientOrDie()
defer argoio.Close(conn)
app, err := appIf.Get(ctx, &applicationpkg.ApplicationQuery{Name: &appName})
Expand Down Expand Up @@ -587,7 +587,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
os.Exit(1)
}
appName := args[0]
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
app, err := appIf.Get(context.Background(), &applicationpkg.ApplicationQuery{Name: &appName})
errors.CheckError(err)
Expand Down Expand Up @@ -835,7 +835,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
os.Exit(2)
}

clientset := argocdclient.NewClientOrDie(clientOpts)
clientset := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, appIf := clientset.NewApplicationClientOrDie()
defer argoio.Close(conn)
appName := args[0]
Expand Down Expand Up @@ -995,7 +995,7 @@ func NewApplicationDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra.
c.HelpFunc()(c, args)
os.Exit(1)
}
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
var isTerminal bool = isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
var isConfirmAll bool = false
Expand Down Expand Up @@ -1108,7 +1108,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
# List apps by label, in this example we listing apps that are children of another app (aka app-of-apps)
argocd app list -l app.kubernetes.io/instance=my-app`,
Run: func(c *cobra.Command, args []string) {
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
apps, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{Selector: selector})
errors.CheckError(err)
Expand Down Expand Up @@ -1248,7 +1248,7 @@ func NewApplicationWaitCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
}
selectedResources := parseSelectedResources(resources)
appNames := args
acdClient := argocdclient.NewClientOrDie(clientOpts)
acdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
closer, appIf := acdClient.NewApplicationClientOrDie()
defer argoio.Close(closer)
if selector != "" {
Expand Down Expand Up @@ -1327,7 +1327,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
c.HelpFunc()(c, args)
os.Exit(1)
}
acdClient := argocdclient.NewClientOrDie(clientOpts)
acdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, appIf := acdClient.NewApplicationClientOrDie()
defer argoio.Close(conn)

Expand Down Expand Up @@ -1621,7 +1621,7 @@ func checkResourceStatus(watchSync bool, watchHealth bool, watchOperation bool,

const waitFormatString = "%s\t%5s\t%10s\t%10s\t%20s\t%8s\t%7s\t%10s\t%s\n"

func waitOnApplicationStatus(acdClient apiclient.Client, appName string, timeout uint, watchSync bool, watchHealth bool, watchOperation bool, watchSuspended bool, selectedResources []argoappv1.SyncOperationResource) (*argoappv1.Application, error) {
func waitOnApplicationStatus(acdClient argocdclient.Client, appName string, timeout uint, watchSync bool, watchHealth bool, watchOperation bool, watchSuspended bool, selectedResources []argoappv1.SyncOperationResource) (*argoappv1.Application, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -1842,7 +1842,7 @@ func NewApplicationHistoryCommand(clientOpts *argocdclient.ClientOptions) *cobra
c.HelpFunc()(c, args)
os.Exit(1)
}
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
appName := args[0]
app, err := appIf.Get(context.Background(), &applicationpkg.ApplicationQuery{Name: &appName})
Expand Down Expand Up @@ -1896,7 +1896,7 @@ func NewApplicationRollbackCommand(clientOpts *argocdclient.ClientOptions) *cobr
depID, err = strconv.Atoi(args[1])
errors.CheckError(err)
}
acdClient := argocdclient.NewClientOrDie(clientOpts)
acdClient := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context")))
conn, appIf := acdClient.NewApplicationClientOrDie()
defer argoio.Close(conn)
ctx := context.Background()
Expand Down Expand Up @@ -1963,7 +1963,7 @@ func NewApplicationManifestsCommand(clientOpts *argocdclient.ClientOptions) *cob
os.Exit(1)
}
appName := args[0]
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
ctx := context.Background()
resources, err := appIf.ManagedResources(context.Background(), &applicationpkg.ResourcesQuery{ApplicationName: &appName})
Expand Down Expand Up @@ -2021,7 +2021,7 @@ func NewApplicationTerminateOpCommand(clientOpts *argocdclient.ClientOptions) *c
os.Exit(1)
}
appName := args[0]
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
ctx := context.Background()
_, err := appIf.TerminateOperation(ctx, &applicationpkg.OperationTerminateRequest{Name: &appName})
Expand All @@ -2042,7 +2042,7 @@ func NewApplicationEditCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
os.Exit(1)
}
appName := args[0]
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
app, err := appIf.Get(context.Background(), &applicationpkg.ApplicationQuery{Name: &appName})
errors.CheckError(err)
Expand Down Expand Up @@ -2087,7 +2087,7 @@ func NewApplicationListResourcesCommand(clientOpts *argocdclient.ClientOptions)
}
listAll := !c.Flag("orphaned").Changed
appName := args[0]
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
appResourceTree, err := appIf.ResourceTree(context.Background(), &applicationpkg.ResourcesQuery{ApplicationName: &appName})
errors.CheckError(err)
Expand Down Expand Up @@ -2133,7 +2133,7 @@ func NewApplicationPatchCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
os.Exit(1)
}
appName := args[0]
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)

patchedApp, err := appIf.Patch(context.Background(), &applicationpkg.ApplicationPatchRequest{
Expand Down Expand Up @@ -2220,7 +2220,7 @@ func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions)
}
appName := args[0]

conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
ctx := context.Background()
resources, err := appIf.ManagedResources(ctx, &applicationpkg.ResourcesQuery{ApplicationName: &appName})
Expand Down Expand Up @@ -2276,7 +2276,7 @@ func NewApplicationDeleteResourceCommand(clientOpts *argocdclient.ClientOptions)
}
appName := args[0]

conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
conn, appIf := headless.NewClientOrDie(clientOpts, initialize.RetrieveContextIfChanged(c.Flag("context"))).NewApplicationClientOrDie()
defer argoio.Close(conn)
ctx := context.Background()
resources, err := appIf.ManagedResources(ctx, &applicationpkg.ResourcesQuery{ApplicationName: &appName})
Expand Down
Loading