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

feat: Implemented open default browser in local mode #2122

Merged
merged 18 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 17 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
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 21 additions & 8 deletions cmd/argo/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/argoproj/pkg/cli"
"github.com/argoproj/pkg/stats"
log "github.com/sirupsen/logrus"
"github.com/skratchdot/open-golang/open"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"k8s.io/client-go/kubernetes"
Expand All @@ -21,13 +22,14 @@ import (

func NewServerCommand() *cobra.Command {
var (
logLevel string // --loglevel
authMode string
configMap string
port int
baseHRef string
namespaced bool // --namespaced
managedNamespace string // --managed-namespace
logLevel string // --loglevel
authMode string
configMap string
port int
baseHRef string
namespaced bool // --namespaced
managedNamespace string // --managed-namespace
enableOpenBrowser bool
)

var command = cobra.Command{
Expand Down Expand Up @@ -87,7 +89,17 @@ See %s`, help.ArgoSever),
if err != nil {
return err
}
apiserver.NewArgoServer(opts).Run(ctx, port)
browserOpenFunc := func(url string) {}
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
if enableOpenBrowser {
browserOpenFunc = func(url string) {
log.Infof("Argo UI is available at %s", url)
err := open.Run(url)
if err != nil {
log.Warnf("Unable to open the browser. %v", err)
}
}
}
apiserver.NewArgoServer(opts).Run(ctx, port, browserOpenFunc)
return nil
},
}
Expand All @@ -103,5 +115,6 @@ See %s`, help.ArgoSever),
command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().BoolVar(&namespaced, "namespaced", false, "run as namespaced mode")
command.Flags().StringVar(&managedNamespace, "managed-namespace", "", "namespace that watches, default to the installation namespace")
command.Flags().BoolVarP(&enableOpenBrowser, "enable-open-browser", "b", false, "enable automatic launching of the browser [local mode]")
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
return &command
}
5 changes: 4 additions & 1 deletion server/apiserver/argoserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (ao ArgoServerOpts) ValidateOpts() error {
return nil
}

func (as *argoServer) Run(ctx context.Context, port int) {
func (as *argoServer) Run(ctx context.Context, port int, browserOpenFunc func(string)) {

configMap, err := as.rsyncConfig()
if err != nil {
Expand Down Expand Up @@ -159,6 +159,9 @@ func (as *argoServer) Run(ctx context.Context, port int) {
go func() { as.checkServeErr("httpServer", httpServer.Serve(httpL)) }()
go func() { as.checkServeErr("tcpm", tcpm.Serve()) }()
log.Infof("Argo Server started successfully on address %s", address)

browserOpenFunc("http://localhost" + address)
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved

as.stopCh = make(chan struct{})
<-as.stopCh
}
Expand Down