Skip to content

Commit

Permalink
Add advertise option to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed May 2, 2016
1 parent aa8e02f commit 3e1efe6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Usage: dkron agent [options]
Options:
-bind=0.0.0.0:8946 Address to bind network listeners to.
-advertise=bind_addr Address used to advertise to other nodes in the cluster. By default, the bind address is advertised.
-http-addr=0.0.0.0:8080 Address to bind the UI web server to. Only used when server.
-discover=cluster A cluster name used to discovery peers. On
networks that support multicast, this can be used to have
Expand Down Expand Up @@ -117,6 +118,8 @@ func (a *AgentCommand) readConfig(args []string) *Config {
viper.SetDefault("node_name", cmdFlags.Lookup("node").Value)
cmdFlags.String("bind", fmt.Sprintf("0.0.0.0:%d", DefaultBindPort), "address to bind listeners to")
viper.SetDefault("bind_addr", cmdFlags.Lookup("bind").Value)
cmdFlags.String("advertise", cmdFlags.Lookup("bind").Value.String(), "address to advertise to other nodes")
viper.SetDefault("advertise_addr", cmdFlags.Lookup("advertise").Value)
cmdFlags.String("http-addr", ":8080", "HTTP address")
viper.SetDefault("http_addr", cmdFlags.Lookup("http-addr").Value)
cmdFlags.String("discover", "dkron", "mDNS discovery name")
Expand Down Expand Up @@ -188,6 +191,7 @@ func (a *AgentCommand) readConfig(args []string) *Config {
return &Config{
NodeName: nodeName,
BindAddr: viper.GetString("bind_addr"),
AdvertiseAddr: viper.GetString("advertise_addr"),
HTTPAddr: viper.GetString("http_addr"),
Discover: viper.GetString("discover"),
Backend: viper.GetString("backend"),
Expand Down
43 changes: 43 additions & 0 deletions dkron/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,46 @@ func Test_getRPCAddr(t *testing.T) {

shutdownCh <- struct{}{}
}

func TestAgentConfig(t *testing.T) {
shutdownCh := make(chan struct{})
defer close(shutdownCh)

ui := new(cli.MockUi)
a := &AgentCommand{
Ui: ui,
ShutdownCh: shutdownCh,
}

args := []string{
"-bind", testutil.GetBindAddr().String(),
"-advertise", testutil.GetBindAddr().String(),
"-log-level", logLevel,
}

resultCh := make(chan int)
go func() {
resultCh <- a.Run(args)
}()

time.Sleep(2 * time.Second)

t.Log(a.config.BindAddr)
t.Log(a.config.AdvertiseAddr)

if a.config.AdvertiseAddr == a.config.BindAddr {
t.Fatal("Expected advertise address to be different than bind address")
}

// Send a shutdown request
shutdownCh <- struct{}{}

select {
case code := <-resultCh:
if code != 0 {
t.Fatalf("bad code: %d", code)
}
case <-time.After(50 * time.Millisecond):
t.Fatalf("timeout")
}
}

0 comments on commit 3e1efe6

Please sign in to comment.