diff --git a/README.md b/README.md index a72c3d7b8..e1413f438 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,7 @@ we can leverage the internal Docker DNS to automatically join existing agents or * AGENT_PORT (*optional*): port on which the agent API will be exposed (default to `9001`) * AGENT_SECRET (*optional*): shared secret used in the signature verification process * AGENT_SECRET_TIMEOUT (*optional*): the duration after which the agent will be shutdown if not associated or secured by `AGENT_SECRET`. (defaults to `72h`) +* AGENT_CLUSTER_MODE_ENABLED (*optional*): allows configuring the agent to ignore if node is with swarm enabled. Change this if your node is in a Swarm and you want to configure the agent in standalone mode. * AGENT_CLUSTER_PROBE_TIMEOUT (*optional*): timeout interval for receiving agent member probe responses (default to `500ms`, only change this setting if you know what you're doing) * AGENT_CLUSTER_PROBE_INTERVAL (*optional*): interval for repeating failed agent member probe (default to `1s`, only change this setting if you know what you're doing) * LOG_LEVEL (*optional*): defines the log output verbosity (default to `INFO`) diff --git a/agent.go b/agent.go index 8726ea2ec..396a53028 100644 --- a/agent.go +++ b/agent.go @@ -74,6 +74,7 @@ type ( AgentServerAddr string AgentServerPort string AgentSecurityShutdown time.Duration + ClusterModeEnabled bool ClusterAddress string ClusterProbeTimeout time.Duration ClusterProbeInterval time.Duration diff --git a/cmd/agent/main.go b/cmd/agent/main.go index cc3a6cb8b..47a65936b 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -78,8 +78,12 @@ func main() { clusterMode := false if runtimeConfiguration.DockerConfiguration.EngineStatus == agent.EngineStatusSwarm { - clusterMode = true - log.Println("[INFO] [main] [message: Agent running on a Swarm cluster node. Running in cluster mode]") + if options.ClusterModeEnabled { + clusterMode = true + log.Println("[INFO] [main] [message: Agent running on a Swarm cluster node. Running in cluster mode]") + } else { + log.Println("[INFO] [main] [message: Detected a Swarm cluster node. Although, Cluster mode is disabled.]") + } } containerName, err := os.GetHostName() diff --git a/os/options.go b/os/options.go index 960c13061..6acde27ef 100644 --- a/os/options.go +++ b/os/options.go @@ -10,6 +10,7 @@ import ( const ( EnvKeyAgentHost = "AGENT_HOST" EnvKeyAgentPort = "AGENT_PORT" + EnvKeyClusterModeEnabled = "AGENT_CLUSTER_MODE_ENABLED" EnvKeyClusterAddr = "AGENT_CLUSTER_ADDR" EnvKeyClusterProbeTimeout = "AGENT_CLUSTER_PROBE_TIMEOUT" EnvKeyClusterProbeInterval = "AGENT_CLUSTER_PROBE_INTERVAL" @@ -44,6 +45,7 @@ var ( fAgentServerAddr = kingpin.Flag("host", EnvKeyAgentHost+" address on which the agent API will be exposed").Envar(EnvKeyAgentHost).Default(agent.DefaultAgentAddr).IP() fAgentServerPort = kingpin.Flag("port", EnvKeyAgentPort+" port on which the agent API will be exposed").Envar(EnvKeyAgentPort).Default(agent.DefaultAgentPort).Int() fAgentSecurityShutdown = kingpin.Flag("secret-timeout", EnvKeyAgentSecurityShutdown+" the duration after which the agent will be shutdown if not associated or secured by AGENT_SECRET. (defaults to 72h)").Envar(EnvKeyAgentSecurityShutdown).Default(agent.DefaultAgentSecurityShutdown).Duration() + fClusterModeEnabled = kingpin.Flag("cluster-mode-enabled", EnvKeyClusterModeEnabled+" boolean to enable or disable auto switching to cluster mode").Envar(EnvKeyClusterModeEnabled).Default("true").Bool() fClusterAddress = kingpin.Flag("cluster-addr", EnvKeyClusterAddr+" address (in the IP:PORT format) of an existing agent to join the agent cluster. When deploying the agent as a Docker Swarm service, we can leverage the internal Docker DNS to automatically join existing agents or form a cluster by using tasks.: as the address").Envar(EnvKeyClusterAddr).String() fClusterProbeTimeout = kingpin.Flag("agent-cluster-timeout", EnvKeyClusterProbeTimeout+" timeout interval for receiving agent member probe responses (only change this setting if you know what you're doing)").Envar(EnvKeyClusterProbeTimeout).Default(agent.DefaultClusterProbeTimeout).Duration() fClusterProbeInterval = kingpin.Flag("agent-cluster-interval", EnvKeyClusterProbeInterval+" interval for repeating failed agent member probe (only change this setting if you know what you're doing)").Envar(EnvKeyClusterProbeInterval).Default(agent.DefaultClusterProbeInterval).Duration() @@ -77,6 +79,7 @@ func (parser *EnvOptionParser) Options() (*agent.Options, error) { AgentServerAddr: fAgentServerAddr.String(), AgentServerPort: strconv.Itoa(*fAgentServerPort), AgentSecurityShutdown: *fAgentSecurityShutdown, + ClusterModeEnabled: *fClusterModeEnabled, ClusterAddress: *fClusterAddress, ClusterProbeTimeout: *fClusterProbeTimeout, ClusterProbeInterval: *fClusterProbeInterval,