Skip to content

Commit

Permalink
https://github.com/portainer/agent/pull/342
Browse files Browse the repository at this point in the history
  • Loading branch information
madpeteguy committed Oct 27, 2022
1 parent c05f8fb commit 7740920
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
1 change: 1 addition & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type (
AgentServerAddr string
AgentServerPort string
AgentSecurityShutdown time.Duration
ClusterModeEnabled bool
ClusterAddress string
ClusterProbeTimeout time.Duration
ClusterProbeInterval time.Duration
Expand Down
8 changes: 6 additions & 2 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions os/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.<AGENT_SERVICE_NAME>:<AGENT_PORT> 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()
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7740920

Please sign in to comment.