Skip to content

Commit

Permalink
Add support for default-addr-pool options to swarm init (#391)
Browse files Browse the repository at this point in the history
Docker API version 1.39 introduced the ability to configure the address
pools and CIDR block size used for creating global scope networks. This
adds support for the `--default-addr-pool` and the associated
`--default-addr-pool-mask-length` options to `swarm init`.
  • Loading branch information
sagepe authored and davejrt committed Dec 14, 2018
1 parent 8aa50d8 commit 1510eee
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
10 changes: 10 additions & 0 deletions lib/puppet/parser/functions/docker_swarm_init_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ module Puppet::Parser::Functions
flags << "--cert-expiry '#{opts['cert_expiry']}'"
end

if opts['default_addr_pool'].is_a? Array
opts['default_addr_pool'].each do |default_addr_pool|
flags << "--default-addr-pool #{default_addr_pool}"
end
end

if opts['default_addr_pool_mask_length'] && opts['default_addr_pool_mask_length'].to_s != 'undef'
flags << "--default-addr-pool-mask-length '#{opts['default_addr_pool_mask_length']}'"
end

if opts['dispatcher_heartbeat'] && opts['dispatcher_heartbeat'].to_s != 'undef'
flags << "--dispatcher-heartbeat '#{opts['dispatcher_heartbeat']}'"
end
Expand Down
32 changes: 22 additions & 10 deletions manifests/swarm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
# Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
# defaults to undef
#
# [*default_addr_pool*]
# Array of default subnet pools for global scope networks (['30.30.0.0/16','40.40.0.0/16'])
# defaults to undef
#
# [*default_addr_pool_mask_length*]
# Default subnet pools mask length for default-addr-pools (CIDR block number)
# defaults to undef
#
# [*dispatcher_heartbeat*]
# Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
# Defaults to undef
Expand Down Expand Up @@ -78,6 +86,8 @@
Optional[String] $advertise_addr = undef,
Optional[Boolean] $autolock = false,
Optional[String] $cert_expiry = undef,
Optional[Array] $default_addr_pool = undef,
Optional[String] $default_addr_pool_mask_length = undef,
Optional[String] $dispatcher_heartbeat = undef,
Optional[String] $external_ca = undef,
Optional[Boolean] $force_new_cluster = false,
Expand Down Expand Up @@ -115,16 +125,18 @@

if $init {
$docker_swarm_init_flags = docker_swarm_init_flags({
init => $init,
advertise_addr => $advertise_addr,
autolock => $autolock,
cert_expiry => $cert_expiry,
dispatcher_heartbeat => $dispatcher_heartbeat,
external_ca => $external_ca,
force_new_cluster => $force_new_cluster,
listen_addr => $listen_addr,
max_snapshots => $max_snapshots,
snapshot_interval => $snapshot_interval,
init => $init,
advertise_addr => $advertise_addr,
autolock => $autolock,
cert_expiry => $cert_expiry,
dispatcher_heartbeat => $dispatcher_heartbeat,
default_addr_pool => $default_addr_pool,
default_addr_pool_mask_length => $default_addr_pool_mask_length,
external_ca => $external_ca,
force_new_cluster => $force_new_cluster,
listen_addr => $listen_addr,
max_snapshots => $max_snapshots,
snapshot_interval => $snapshot_interval,
})

$exec_init = "${docker_command} ${docker_swarm_init_flags}"
Expand Down
14 changes: 13 additions & 1 deletion spec/defines/swarm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@
let(:params) { {
'init' => true,
'advertise_addr' => '192.168.1.1',
'listen_addr' => '192.168.1.1',
'listen_addr' => '192.168.1.1',
} }
it { is_expected.to compile.with_all_deps }
it { should contain_exec('Swarm init').with_command(/docker swarm init/) }
end

context 'with ensure => present and swarm init and default-addr-pool and default_addr_pool_mask_length' do
let(:params) { {
'init' => true,
'advertise_addr' => '192.168.1.1',
'listen_addr' => '192.168.1.1',
'default_addr_pool' => ['30.30.0.0/16', '40.40.0.0/16'],
'default_addr_pool_mask_length' => '24',
} }
it { is_expected.to compile.with_all_deps }
it { should contain_exec('Swarm init').with_command(/docker swarm init/) }
Expand Down

0 comments on commit 1510eee

Please sign in to comment.