diff --git a/cmd/argocd/commands/login.go b/cmd/argocd/commands/login.go index fff0bba2d0b4c..254b6800c676a 100644 --- a/cmd/argocd/commands/login.go +++ b/cmd/argocd/commands/login.go @@ -154,14 +154,29 @@ argocd login cd.argoproj.io --core`, if localCfg == nil { localCfg = &localconfig.LocalConfig{} } - localCfg.UpsertServer(localconfig.Server{ - Server: server, - PlainText: globalClientOpts.PlainText, - Insecure: globalClientOpts.Insecure, - GRPCWeb: globalClientOpts.GRPCWeb, - GRPCWebRootPath: globalClientOpts.GRPCWebRootPath, - Core: globalClientOpts.Core, - }) + + if globalClientOpts.PortForward && globalClientOpts.PortForwardNamespace != "" { + localCfg.UpsertServer(localconfig.Server{ + Server: server, + PlainText: globalClientOpts.PlainText, + Insecure: globalClientOpts.Insecure, + GRPCWeb: globalClientOpts.GRPCWeb, + GRPCWebRootPath: globalClientOpts.GRPCWebRootPath, + Core: globalClientOpts.Core, + PortForward: globalClientOpts.PortForward, + PortForwardNamespace: globalClientOpts.PortForwardNamespace, + }) + } else { + localCfg.UpsertServer(localconfig.Server{ + Server: server, + PlainText: globalClientOpts.PlainText, + Insecure: globalClientOpts.Insecure, + GRPCWeb: globalClientOpts.GRPCWeb, + GRPCWebRootPath: globalClientOpts.GRPCWebRootPath, + Core: globalClientOpts.Core, + }) + } + localCfg.UpsertUser(localconfig.User{ Name: ctxName, AuthToken: tokenString, diff --git a/util/localconfig/localconfig.go b/util/localconfig/localconfig.go index 59099c81f8981..819149cadbeec 100644 --- a/util/localconfig/localconfig.go +++ b/util/localconfig/localconfig.go @@ -56,6 +56,10 @@ type Server struct { PlainText bool `json:"plain-text,omitempty"` // Core indicates to talk to Kubernetes API without using Argo CD API server Core bool `json:"core,omitempty"` + // PortForward enables automatic port forwarding when the ArgoCD CLI communicates with the API server + PortForward bool `json:"port-forward,omitempty"` + // PortForwardNamespace specifies the namespace where port forwarding should be applied (default: argocd) + PortForwardNamespace string `json:"port-forward-namespace,omitempty"` } // User contains user authentication information