executor: listen on wildcard address

Since the current logic is to use the first available private ip address as the
advertized address we have to listen on wildcard since a different host provided
in web.ListenAddress will make the executor unreachable.

In future improve this to let the user to manually define the bind and the
advertized address (perhaps using go-sockaddr templates like done by consul) to
also support nat between the schedulers and the executors.
This commit is contained in:
Simone Gotti 2019-08-06 11:14:28 +02:00
parent 7623202048
commit e31b0b47ef
1 changed files with 6 additions and 1 deletions

View File

@ -1308,6 +1308,7 @@ type Executor struct {
id string
runningTasks *runningTasks
driver driver.Driver
listenAddress string
listenURL string
dynamic bool
}
@ -1348,6 +1349,8 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
e.id = id
// TODO(sgotti) now the first available private ip will be used and the executor will bind to the wildcard address
// improve this to let the user define the bind and the advertize address
addr, err := sockaddr.GetPrivateIP()
if err != nil {
return nil, errors.Errorf("cannot discover executor listen address: %w", err)
@ -1366,6 +1369,8 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
u.Host = net.JoinHostPort(addr, port)
e.listenURL = u.String()
e.listenAddress = fmt.Sprintf(":%s", port)
var d driver.Driver
switch c.Driver.Type {
case config.DriverTypeDocker:
@ -1413,7 +1418,7 @@ func (e *Executor) Run(ctx context.Context) error {
go e.handleTasks(ctx, ch)
httpServer := http.Server{
Addr: e.c.Web.ListenAddress,
Addr: e.listenAddress,
Handler: apirouter,
}
lerrCh := make(chan error)