Skip to content

Commit

Permalink
Provide address flag for admin dashboard command (#8095)
Browse files Browse the repository at this point in the history
* feat: address flag for admin dashboard

Signed-off-by: Avinash Upadhyaya <avinashupadhya99@gmail.com>

* docs: address flag for admin dashboard

Signed-off-by: Avinash Upadhyaya <avinashupadhya99@gmail.com>
  • Loading branch information
avinashupadhya99 committed Jan 7, 2022
1 parent 37851b1 commit 8b57bc9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
8 changes: 5 additions & 3 deletions cmd/argocd/commands/admin/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 8 additions & 4 deletions cmd/argocd/commands/headless/headless.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down
18 changes: 9 additions & 9 deletions cmd/argocd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_admin_dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b57bc9

Please sign in to comment.