Skip to content

Commit

Permalink
[command] om daemon leave and join support custom listener port
Browse files Browse the repository at this point in the history
- om daemon join --node node1 --token <xxx> --server https://node1:<custom-port>
- om daemon leave will use automatic client url from the cluster node to leave from
  • Loading branch information
cgalibern committed Sep 30, 2023
1 parent 339509b commit 8ab64c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ func newCmdDaemonJoin() *cobra.Command {
}
flags := cmd.Flags()
flags.StringVar(&options.Node, "node", "", "the name of the cluster node we want to join")
flags.StringVar(&options.Server, "server", "", "URI of the opensvc api server when custom port is used.")

if err := cmd.MarkFlagRequired("node"); err != nil {
panic(err)
}
Expand Down
13 changes: 10 additions & 3 deletions core/commands/daemon_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ type (
CmdDaemonJoin struct {
CmdDaemonCommon

Node string
Token string
Node string
Server string
Token string

// Timeout is the maximum duration for leave
Timeout time.Duration
Expand Down Expand Up @@ -65,8 +66,14 @@ func (t *CmdDaemonJoin) run() error {
_ = os.Remove(name)
}(certFile)

var url string
if t.Server == "" {
url = daemonenv.UrlHttpNode(t.Node)
} else {
url = t.Server
}
cli, err = client.New(
client.WithURL(daemonenv.UrlHttpNode(t.Node)),
client.WithURL(url),
client.WithRootCa(certFile),
client.WithBearer(t.Token),
)
Expand Down
3 changes: 1 addition & 2 deletions core/commands/daemon_leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/opensvc/om3/core/event"
"github.com/opensvc/om3/core/object"
"github.com/opensvc/om3/daemon/api"
"github.com/opensvc/om3/daemon/daemonenv"
"github.com/opensvc/om3/daemon/msgbus"
"github.com/opensvc/om3/util/hostname"
)
Expand All @@ -37,7 +36,7 @@ func (t *CmdDaemonLeave) Run() (err error) {
return err
}
t.cli, err = client.New(
client.WithURL(daemonenv.UrlHttpNode(t.ApiNode)),
client.WithURL(t.ApiNode),
)
if err != nil {
return
Expand Down

0 comments on commit 8ab64c2

Please sign in to comment.