Skip to content

Commit

Permalink
Data Path Port configuration support
Browse files Browse the repository at this point in the history
This PR chnages allow user to configure data path
port number. By default we use 4789 port number. But this commit
will allow user to configure port number during swarm init.
Data path port can't be modified after swarm init.

Signed-off-by: selansen <[email protected]>
  • Loading branch information
selansen committed Nov 26, 2018
1 parent 052133a commit a01545f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cli/command/swarm/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type initOptions struct {
// Not a NodeAddrOption because it has no default port.
advertiseAddr string
dataPathAddr string
dataPathPort uint32
forceNewCluster bool
availability string
defaultAddrPools []net.IPNet
Expand All @@ -45,6 +46,8 @@ func newInitCommand(dockerCli command.Cli) *cobra.Command {
flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: <ip|interface>[:port])")
flags.StringVar(&opts.dataPathAddr, flagDataPathAddr, "", "Address or interface to use for data path traffic (format: <ip|interface>)")
flags.SetAnnotation(flagDataPathAddr, "version", []string{"1.31"})
flags.Uint32Var(&opts.dataPathPort, flagDataPathPort, 0, "Port number to use for data path traffic (1024 - 49151). If no value is set or is set to 0, the default port (4789) is used.")
flags.SetAnnotation(flagDataPathPort, "version", []string{"1.40"})
flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state")
flags.BoolVar(&opts.autolock, flagAutolock, false, "Enable manager autolocking (requiring an unlock key to start a stopped manager)")
flags.StringVar(&opts.availability, flagAvailability, "active", `Availability of the node ("active"|"pause"|"drain")`)
Expand Down Expand Up @@ -74,6 +77,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro
Spec: opts.swarmOptions.ToSpec(flags),
AutoLockManagers: opts.swarmOptions.autolock,
SubnetSize: opts.DefaultAddrPoolMaskLength,
DataPathPort: opts.dataPathPort,
}
if flags.Changed(flagAvailability) {
availability := swarm.NodeAvailability(strings.ToLower(opts.availability))
Expand Down
1 change: 1 addition & 0 deletions cli/command/swarm/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
flagListenAddr = "listen-addr"
flagAdvertiseAddr = "advertise-addr"
flagDataPathAddr = "data-path-addr"
flagDataPathPort = "data-path-port"
flagDefaultAddrPool = "default-addr-pool"
flagDefaultAddrPoolMaskLength = "default-addr-pool-mask-length"
flagQuiet = "quiet"
Expand Down
3 changes: 3 additions & 0 deletions cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ func printSwarmInfo(dockerCli command.Cli, info types.Info) {
fmt.Fprintln(dockerCli.Out(), " Default Address Pool:", strAddrPool.String())
fmt.Fprintln(dockerCli.Out(), " SubnetSize:", info.Swarm.Cluster.SubnetSize)
}
if info.Swarm.Cluster.DataPathPort > 0 {
fmt.Fprintln(dockerCli.Out(), " Data Path Port:", info.Swarm.Cluster.DataPathPort)
}
fmt.Fprintln(dockerCli.Out(), " Orchestration:")

taskHistoryRetentionLimit := int64(0)
Expand Down
1 change: 1 addition & 0 deletions cli/command/system/testdata/docker-info-with-swarm.golden
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Swarm: active
ClusterID: 9vs5ygs0gguyyec4iqf2314c0
Managers: 1
Nodes: 1
Data Path Port: 0
Orchestration:
Task History Retention Limit: 5
Raft:
Expand Down
4 changes: 2 additions & 2 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -3698,7 +3698,7 @@ _docker_swarm_init() {
COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
return
;;
--cert-expiry|--default-addr-pool|--default-addr-pool-mask-length|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit )
--cert-expiry|--data-path-port|--default-addr-pool|--default-addr-pool-mask-length|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit )
return
;;
--data-path-addr)
Expand All @@ -3718,7 +3718,7 @@ _docker_swarm_init() {

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --data-path-addr --default-addr-pool --default-addr-pool-mask-length --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --data-path-addr --data-path-port --default-addr-pool --default-addr-pool-mask-length --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit " -- "$cur" ) )
;;
esac
}
Expand Down
1 change: 1 addition & 0 deletions contrib/completion/zsh/_docker
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,7 @@ __docker_swarm_subcommand() {
$opts_help \
"($help)--advertise-addr=[Advertised address]:ip\:port: " \
"($help)--data-path-addr=[Data path IP or interface]:ip " \
"($help)--data-path-port=[Data Path Port] " \
"($help)--default-addr-pool=[Default address pool]" \
"($help)--default-addr-pool-mask-length=[Default address pool subnet mask length]" \
"($help)--autolock[Enable manager autolocking]" \
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/commandline/swarm_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Options:
--availability string Availability of the node ("active"|"pause"|"drain") (default "active")
--cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
--data-path-addr string Address or interface to use for data path traffic (format: <ip|interface>)
--data-path-port uint Data path port number used for data path traffic
--default-addr-pool IPnet List of default address pool (format: <cidr>)
--default-addr-pool-mask-length Subnet mask length for default address pool (default 24)
--dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
Expand Down Expand Up @@ -130,6 +131,21 @@ management traffic of the cluster.
If unspecified, Docker will use the same IP address or interface that is used for the
advertise address.

### `--data-path-port`

This flag specifies data path port number to use for data path traffic (1024 - 49151).
If no value is set or is set to 0, the default port (4789) is used. This value is set for per cluster
so the option is supported only via swarm init command. swarm update or swarm join commands do not support
this option. The port is reserved for UDP traffic.
Format example is `docker swarm init --data-path-addr=20.20.20.1 --data-path-port=7777`

Docker info output will display currently used port for data path traffic.
Docker info #
ClusterID: 9vs5ygs0gguyyec4iqf2314c0
Managers: 1
Nodes: 1
Data Path Port: 7777

### `--default-addr-pool`
This flag specifies default subnet pools for global scope networks.
Format example is `--default-addr-pool 30.30.0.0/16 --default-addr-pool 40.40.0.0/16`
Expand Down

0 comments on commit a01545f

Please sign in to comment.