From 10a41c914e785c1118c1053901999b68997fd4ae Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 24 Sep 2020 13:14:45 -0400 Subject: [PATCH] Force worker to use the local controller when running in combined mode (#429) --- internal/cmd/commands/server/server.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/cmd/commands/server/server.go b/internal/cmd/commands/server/server.go index 31b2dcdbaa..ebe4935c38 100644 --- a/internal/cmd/commands/server/server.go +++ b/internal/cmd/commands/server/server.go @@ -172,7 +172,7 @@ func (c *Command) Run(args []string) int { } // Perform controller-specific listener checks here before setup - var foundCluster bool + var clusterAddr string var foundApi bool var foundProxy bool for _, lnConfig := range c.Config.Listeners { @@ -185,7 +185,10 @@ func (c *Command) Run(args []string) int { purpose := lnConfig.Purpose[0] switch purpose { case "cluster": - foundCluster = true + clusterAddr = lnConfig.Address + if clusterAddr == "" { + clusterAddr = "127.0.0.1:9201" + } case "api": foundApi = true case "proxy": @@ -205,7 +208,7 @@ func (c *Command) Run(args []string) int { c.UI.Error(`Config activates controller but no listener with "api" purpose found`) return 1 } - if !foundCluster { + if clusterAddr == "" { c.UI.Error(`Config activates controller but no listener with "cluster" purpose found`) return 1 } @@ -215,6 +218,20 @@ func (c *Command) Run(args []string) int { c.UI.Error(`Config activates worker but no listener with "proxy" purpose found`) return 1 } + if c.Config.Controller != nil { + switch len(c.Config.Worker.Controllers) { + case 0: + case 1: + if c.Config.Worker.Controllers[0] == clusterAddr { + break + } + fallthrough + default: + c.UI.Error(`When running a combined controller and worker, it's invalid to specify a "controllers" key in the worker block with any value other than the controller cluster address`) + return 1 + } + c.Config.Worker.Controllers = []string{clusterAddr} + } } if err := c.SetupListeners(c.UI, c.Config.SharedConfig, []string{"api", "cluster", "proxy"}); err != nil { c.UI.Error(err.Error())