Skip to content

Commit

Permalink
config: support passing multiple server RPC addrs for registration (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Jan 29, 2024
1 parent 6cdc388 commit 3640019
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
10 changes: 5 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type Config struct {
// generating the simulated client name and ID.
NodeNamePrefix string `hcl:"node_name_prefix,optional"`

// ServerAddr is the RPC address of a Nomad server which will be used to
// set up the clients initial registration contact.
ServerAddr string `hcl:"server_addr,optional"`
// ServerAddr is a slice of server RPC addresses which will be used for the
// clients initial registration.
ServerAddr arrayFlagVar `hcl:"server_addr,optional"`

// NodeNum is the number of Nomad clients/nodes that will be started within
// this single nodesim process. Some basic testing indicates you will need
Expand Down Expand Up @@ -66,7 +66,7 @@ func Default() *Config {
return &Config{
WorkDir: fmt.Sprintf("nomad-nodesim-%d", os.Getpid()),
NodeNamePrefix: fmt.Sprintf("node-%s", uuid.Short()),
ServerAddr: "127.0.0.1:4647",
ServerAddr: []string{"127.0.0.1:4647"},
NodeNum: 1,
Log: &Log{
Level: "debug",
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *Config) Merge(z *Config) *Config {
if z.NodeNamePrefix != "" {
result.NodeNamePrefix = z.NodeNamePrefix
}
if z.ServerAddr != "" {
if len(z.ServerAddr) > 0 {
result.ServerAddr = z.ServerAddr
}
if z.NodeNum > 0 {
Expand Down
13 changes: 13 additions & 0 deletions internal/config/flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package config

type arrayFlagVar []string

func (i *arrayFlagVar) String() string { return "" }

func (i *arrayFlagVar) Set(value string) error {
*i = append(*i, value)
return nil
}
9 changes: 2 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
}

flag.StringVar(&flagConfig.WorkDir, "work-dir", "", "working directory")
flag.StringVar(&flagConfig.ServerAddr, "server-addr", "", "address of server's rpc port")
flag.Var(&flagConfig.ServerAddr, "server-addr", "address of server's rpc port; can be specified multiple times")
flag.StringVar(&flagConfig.NodeNamePrefix, "node-name-prefix", "", "nodes will be named [prefix]-[i]")
flag.IntVar(&flagConfig.NodeNum, "node-num", 0, "number of client nodes")

Expand Down Expand Up @@ -184,12 +184,7 @@ func startClient(logger hclog.Logger, buildInfo *internalSimnode.BuildInfo, cfg

clientCfg.MaxKillTimeout = time.Minute

//FIXME inject servers?
if cfg.ServerAddr != "" {
clientCfg.Servers = []string{cfg.ServerAddr}
} else {
clientCfg.Servers = []string{}
}
clientCfg.Servers = cfg.ServerAddr

tlsConfig := tlsConfigFromEnv()
tlsEnabled := true
Expand Down

0 comments on commit 3640019

Please sign in to comment.