Skip to content

Commit 7740920

Browse files
committed
https://github.com/portainer/agent/pull/342
1 parent c05f8fb commit 7740920

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ we can leverage the internal Docker DNS to automatically join existing agents or
237237
* AGENT_PORT (*optional*): port on which the agent API will be exposed (default to `9001`)
238238
* AGENT_SECRET (*optional*): shared secret used in the signature verification process
239239
* AGENT_SECRET_TIMEOUT (*optional*): the duration after which the agent will be shutdown if not associated or secured by `AGENT_SECRET`. (defaults to `72h`)
240+
* 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.
240241
* 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)
241242
* 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)
242243
* LOG_LEVEL (*optional*): defines the log output verbosity (default to `INFO`)

agent.go

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type (
7474
AgentServerAddr string
7575
AgentServerPort string
7676
AgentSecurityShutdown time.Duration
77+
ClusterModeEnabled bool
7778
ClusterAddress string
7879
ClusterProbeTimeout time.Duration
7980
ClusterProbeInterval time.Duration

cmd/agent/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ func main() {
7878

7979
clusterMode := false
8080
if runtimeConfiguration.DockerConfiguration.EngineStatus == agent.EngineStatusSwarm {
81-
clusterMode = true
82-
log.Println("[INFO] [main] [message: Agent running on a Swarm cluster node. Running in cluster mode]")
81+
if options.ClusterModeEnabled {
82+
clusterMode = true
83+
log.Println("[INFO] [main] [message: Agent running on a Swarm cluster node. Running in cluster mode]")
84+
} else {
85+
log.Println("[INFO] [main] [message: Detected a Swarm cluster node. Although, Cluster mode is disabled.]")
86+
}
8387
}
8488

8589
containerName, err := os.GetHostName()

os/options.go

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
const (
1111
EnvKeyAgentHost = "AGENT_HOST"
1212
EnvKeyAgentPort = "AGENT_PORT"
13+
EnvKeyClusterModeEnabled = "AGENT_CLUSTER_MODE_ENABLED"
1314
EnvKeyClusterAddr = "AGENT_CLUSTER_ADDR"
1415
EnvKeyClusterProbeTimeout = "AGENT_CLUSTER_PROBE_TIMEOUT"
1516
EnvKeyClusterProbeInterval = "AGENT_CLUSTER_PROBE_INTERVAL"
@@ -44,6 +45,7 @@ var (
4445
fAgentServerAddr = kingpin.Flag("host", EnvKeyAgentHost+" address on which the agent API will be exposed").Envar(EnvKeyAgentHost).Default(agent.DefaultAgentAddr).IP()
4546
fAgentServerPort = kingpin.Flag("port", EnvKeyAgentPort+" port on which the agent API will be exposed").Envar(EnvKeyAgentPort).Default(agent.DefaultAgentPort).Int()
4647
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()
48+
fClusterModeEnabled = kingpin.Flag("cluster-mode-enabled", EnvKeyClusterModeEnabled+" boolean to enable or disable auto switching to cluster mode").Envar(EnvKeyClusterModeEnabled).Default("true").Bool()
4749
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.<AGENT_SERVICE_NAME>:<AGENT_PORT> as the address").Envar(EnvKeyClusterAddr).String()
4850
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()
4951
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) {
7779
AgentServerAddr: fAgentServerAddr.String(),
7880
AgentServerPort: strconv.Itoa(*fAgentServerPort),
7981
AgentSecurityShutdown: *fAgentSecurityShutdown,
82+
ClusterModeEnabled: *fClusterModeEnabled,
8083
ClusterAddress: *fClusterAddress,
8184
ClusterProbeTimeout: *fClusterProbeTimeout,
8285
ClusterProbeInterval: *fClusterProbeInterval,

0 commit comments

Comments
 (0)