diff --git a/cmd/argocd/commands/admin/dashboard.go b/cmd/argocd/commands/admin/dashboard.go index 9da3582453856..abb0552bdc8de 100644 --- a/cmd/argocd/commands/admin/dashboard.go +++ b/cmd/argocd/commands/admin/dashboard.go @@ -13,18 +13,20 @@ import ( func NewDashboardCommand() *cobra.Command { var ( - port int + port int + address string ) cmd := &cobra.Command{ Use: "dashboard", Short: "Starts Argo CD Web UI locally", Run: func(cmd *cobra.Command, args []string) { - println(fmt.Sprintf("Argo CD UI is available at http://localhost:%d", port)) + 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) + headless.InitCommand(cmd, clientOpts, &port, &address) cmd.Flags().IntVar(&port, "port", common.DefaultPortAPIServer, "Listen on given port") + cmd.Flags().StringVar(&address, "address", common.DefaultAddressAPIServer, "Listen on given address") return cmd } diff --git a/cmd/argocd/commands/headless/headless.go b/cmd/argocd/commands/headless/headless.go index 0b70ac81889bf..f75ad47037984 100644 --- a/cmd/argocd/commands/headless/headless.go +++ b/cmd/argocd/commands/headless/headless.go @@ -54,7 +54,7 @@ func retrieveContextIfChanged(contextFlag *flag.Flag) string { // InitCommand allows executing command in a headless mode: on the fly starts Argo CD API server and // changes provided client options to use started API server port -func InitCommand(cmd *cobra.Command, clientOpts *argoapi.ClientOptions, port *int) *cobra.Command { +func InitCommand(cmd *cobra.Command, clientOpts *argoapi.ClientOptions, port *int, address *string) *cobra.Command { ctx, cancel := context.WithCancel(context.Background()) flags := pflag.NewFlagSet("tmp", pflag.ContinueOnError) clientConfig := cli.AddKubectlFlagsToSet(flags) @@ -90,8 +90,12 @@ func InitCommand(cmd *cobra.Command, clientOpts *argoapi.ClientOptions, port *in cli.SetLogLevel(log.ErrorLevel.String()) log.SetLevel(log.ErrorLevel) os.Setenv(v1alpha1.EnvVarFakeInClusterConfig, "true") + if address == nil { + *address = "localhost" + } if port == nil || *port == 0 { - ln, err := net.Listen("tcp", "localhost:0") + addr := fmt.Sprintf("%s:0", *address) + ln, err := net.Listen("tcp", addr) if err != nil { return err } @@ -135,12 +139,12 @@ func InitCommand(cmd *cobra.Command, clientOpts *argoapi.ClientOptions, port *in Cache: servercache.NewCache(appstateCache, 0, 0, 0), KubeClientset: kubeClientset, Insecure: true, - ListenHost: "localhost", + ListenHost: *address, RepoClientset: &forwardRepoClientset{namespace: namespace, context: context}, }) go srv.Run(ctx, *port, 0) - clientOpts.ServerAddr = fmt.Sprintf("localhost:%d", *port) + clientOpts.ServerAddr = fmt.Sprintf("%s:%d", *address, *port) clientOpts.PlainText = true if !cache.WaitForCacheSync(ctx.Done(), srv.Initialized) { log.Fatal("Timed out waiting for project cache to sync") diff --git a/cmd/argocd/commands/root.go b/cmd/argocd/commands/root.go index f5289948caf34..7ec9d022c35e7 100644 --- a/cmd/argocd/commands/root.go +++ b/cmd/argocd/commands/root.go @@ -40,19 +40,19 @@ func NewCommand() *cobra.Command { } command.AddCommand(NewCompletionCommand()) - command.AddCommand(headless.InitCommand(NewVersionCmd(&clientOpts), &clientOpts, nil)) - command.AddCommand(headless.InitCommand(NewClusterCommand(&clientOpts, pathOpts), &clientOpts, nil)) - command.AddCommand(headless.InitCommand(NewApplicationCommand(&clientOpts), &clientOpts, nil)) + command.AddCommand(headless.InitCommand(NewVersionCmd(&clientOpts), &clientOpts, nil, nil)) + command.AddCommand(headless.InitCommand(NewClusterCommand(&clientOpts, pathOpts), &clientOpts, nil, nil)) + command.AddCommand(headless.InitCommand(NewApplicationCommand(&clientOpts), &clientOpts, nil, nil)) command.AddCommand(NewLoginCommand(&clientOpts)) command.AddCommand(NewReloginCommand(&clientOpts)) - command.AddCommand(headless.InitCommand(NewRepoCommand(&clientOpts), &clientOpts, nil)) - command.AddCommand(headless.InitCommand(NewRepoCredsCommand(&clientOpts), &clientOpts, nil)) + command.AddCommand(headless.InitCommand(NewRepoCommand(&clientOpts), &clientOpts, nil, nil)) + command.AddCommand(headless.InitCommand(NewRepoCredsCommand(&clientOpts), &clientOpts, nil, nil)) command.AddCommand(NewContextCommand(&clientOpts)) - command.AddCommand(headless.InitCommand(NewProjectCommand(&clientOpts), &clientOpts, nil)) - command.AddCommand(headless.InitCommand(NewAccountCommand(&clientOpts), &clientOpts, nil)) + command.AddCommand(headless.InitCommand(NewProjectCommand(&clientOpts), &clientOpts, nil, nil)) + command.AddCommand(headless.InitCommand(NewAccountCommand(&clientOpts), &clientOpts, nil, nil)) command.AddCommand(NewLogoutCommand(&clientOpts)) - command.AddCommand(headless.InitCommand(NewCertCommand(&clientOpts), &clientOpts, nil)) - command.AddCommand(headless.InitCommand(NewGPGCommand(&clientOpts), &clientOpts, nil)) + command.AddCommand(headless.InitCommand(NewCertCommand(&clientOpts), &clientOpts, nil, nil)) + command.AddCommand(headless.InitCommand(NewGPGCommand(&clientOpts), &clientOpts, nil, nil)) command.AddCommand(admin.NewAdminCommand()) defaultLocalConfigPath, err := localconfig.DefaultLocalConfigPath() diff --git a/common/common.go b/common/common.go index b6f7be2754355..79bcceb1c1647 100644 --- a/common/common.go +++ b/common/common.go @@ -42,6 +42,11 @@ const ( DefaultPortRepoServerMetrics = 8084 ) +// Default listener address for ArgoCD components +const ( + DefaultAddressAPIServer = "localhost" +) + // Default paths on the pod's file system const ( // The default path where TLS certificates for repositories are located diff --git a/docs/user-guide/commands/argocd_admin_dashboard.md b/docs/user-guide/commands/argocd_admin_dashboard.md index d7760b2289990..76c9a49cf2d99 100644 --- a/docs/user-guide/commands/argocd_admin_dashboard.md +++ b/docs/user-guide/commands/argocd_admin_dashboard.md @@ -9,6 +9,7 @@ argocd admin dashboard [flags] ### Options ``` + --address string Listen on given address (default "localhost") --as string Username to impersonate for the operation --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. --certificate-authority string Path to a cert file for the certificate authority