Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agent): including new option to disable auto cluster mode #342

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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