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 9 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.

28 changes: 20 additions & 8 deletions cmd/argo/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"golang.org/x/net/context"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"github.com/skratchdot/open-golang/open"
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved

"github.com/argoproj/argo/cmd/argo/commands/client"
wfclientset "github.com/argoproj/argo/pkg/client/clientset/versioned"
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
disableOpenBrowser bool
alexec marked this conversation as resolved.
Show resolved Hide resolved
)

var command = cobra.Command{
Expand Down Expand Up @@ -87,7 +89,16 @@ 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 !disableOpenBrowser {
browserOpenFunc = func(url string) {
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 +114,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().BoolVar(&disableOpenBrowser, "disable-open-browser", false, "disable automatic launching of the browser [Hosted mode]")
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
return &command
}
2 changes: 1 addition & 1 deletion manifests/base/argo-server/argo-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
containers:
- name: argo-server
image: argoproj/argocli:latest
args: [server]
args: ["server","--disable-open-browser"]
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
ports:
- containerPort: 2746
readinessProbe:
Expand Down
1 change: 1 addition & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
image: argoproj/argocli:latest
name: argo-server
ports:
Expand Down
1 change: 1 addition & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
- --namespaced
image: argoproj/argocli:latest
name: argo-server
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
- --namespaced
image: argoproj/argocli:latest
name: argo-server
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-no-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
- --namespaced
image: argoproj/argocli:latest
name: argo-server
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
- --namespaced
image: argoproj/argocli:latest
name: argo-server
Expand Down
15 changes: 10 additions & 5 deletions server/apiserver/argoserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import (

const (
// MaxGRPCMessageSize contains max grpc message size
MaxGRPCMessageSize = 100 * 1024 * 1024
MaxGRPCMessageSize = 100 * 1024 * 1024
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
// Default listening host
DefaultListeningHost = "127.0.0.1"
)

type argoServer struct {
Expand All @@ -58,7 +60,7 @@ type argoServer struct {
}

type ArgoServerOpts struct {
BaseHRef string
BaseHRef string
Namespace string
KubeClientset *kubernetes.Clientset
WfClientSet *versioned.Clientset
Expand Down Expand Up @@ -105,7 +107,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 @@ -136,7 +138,7 @@ func (as *argoServer) Run(ctx context.Context, port int) {
// Start listener
var conn net.Listener
var listerErr error
address := fmt.Sprintf(":%d", port)
address := fmt.Sprintf("%s:%d", DefaultListeningHost, port)
err = wait.ExponentialBackoff(backoff, func() (bool, error) {
conn, listerErr = net.Listen("tcp", address)
if listerErr != nil {
Expand All @@ -158,7 +160,10 @@ func (as *argoServer) Run(ctx context.Context, port int) {
go func() { as.checkServeErr("grpcServer", grpcServer.Serve(grpcL)) }()
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)
log.Infof("Argo Server started successfully on address %s", conn.Addr().String())

browserOpenFunc("http://" + conn.Addr().String())

as.stopCh = make(chan struct{})
<-as.stopCh
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/manifests/mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
- --namespaced
- --auth-mode
- client
Expand Down
1 change: 1 addition & 0 deletions test/e2e/manifests/no-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
- --namespaced
- --auth-mode
- client
Expand Down
1 change: 1 addition & 0 deletions test/e2e/manifests/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ spec:
containers:
- args:
- server
- --disable-open-browser
- --namespaced
- --auth-mode
- client
Expand Down