Skip to content

Commit 1510eee

Browse files
sagepedavejrt
authored andcommitted
Add support for default-addr-pool options to swarm init (#391)
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`.
1 parent 8aa50d8 commit 1510eee

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

lib/puppet/parser/functions/docker_swarm_init_flags.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ module Puppet::Parser::Functions
2424
flags << "--cert-expiry '#{opts['cert_expiry']}'"
2525
end
2626

27+
if opts['default_addr_pool'].is_a? Array
28+
opts['default_addr_pool'].each do |default_addr_pool|
29+
flags << "--default-addr-pool #{default_addr_pool}"
30+
end
31+
end
32+
33+
if opts['default_addr_pool_mask_length'] && opts['default_addr_pool_mask_length'].to_s != 'undef'
34+
flags << "--default-addr-pool-mask-length '#{opts['default_addr_pool_mask_length']}'"
35+
end
36+
2737
if opts['dispatcher_heartbeat'] && opts['dispatcher_heartbeat'].to_s != 'undef'
2838
flags << "--dispatcher-heartbeat '#{opts['dispatcher_heartbeat']}'"
2939
end

manifests/swarm.pp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
# Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
3535
# defaults to undef
3636
#
37+
# [*default_addr_pool*]
38+
# Array of default subnet pools for global scope networks (['30.30.0.0/16','40.40.0.0/16'])
39+
# defaults to undef
40+
#
41+
# [*default_addr_pool_mask_length*]
42+
# Default subnet pools mask length for default-addr-pools (CIDR block number)
43+
# defaults to undef
44+
#
3745
# [*dispatcher_heartbeat*]
3846
# Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
3947
# Defaults to undef
@@ -78,6 +86,8 @@
7886
Optional[String] $advertise_addr = undef,
7987
Optional[Boolean] $autolock = false,
8088
Optional[String] $cert_expiry = undef,
89+
Optional[Array] $default_addr_pool = undef,
90+
Optional[String] $default_addr_pool_mask_length = undef,
8191
Optional[String] $dispatcher_heartbeat = undef,
8292
Optional[String] $external_ca = undef,
8393
Optional[Boolean] $force_new_cluster = false,
@@ -115,16 +125,18 @@
115125

116126
if $init {
117127
$docker_swarm_init_flags = docker_swarm_init_flags({
118-
init => $init,
119-
advertise_addr => $advertise_addr,
120-
autolock => $autolock,
121-
cert_expiry => $cert_expiry,
122-
dispatcher_heartbeat => $dispatcher_heartbeat,
123-
external_ca => $external_ca,
124-
force_new_cluster => $force_new_cluster,
125-
listen_addr => $listen_addr,
126-
max_snapshots => $max_snapshots,
127-
snapshot_interval => $snapshot_interval,
128+
init => $init,
129+
advertise_addr => $advertise_addr,
130+
autolock => $autolock,
131+
cert_expiry => $cert_expiry,
132+
dispatcher_heartbeat => $dispatcher_heartbeat,
133+
default_addr_pool => $default_addr_pool,
134+
default_addr_pool_mask_length => $default_addr_pool_mask_length,
135+
external_ca => $external_ca,
136+
force_new_cluster => $force_new_cluster,
137+
listen_addr => $listen_addr,
138+
max_snapshots => $max_snapshots,
139+
snapshot_interval => $snapshot_interval,
128140
})
129141

130142
$exec_init = "${docker_command} ${docker_swarm_init_flags}"

spec/defines/swarm_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@
3030
let(:params) { {
3131
'init' => true,
3232
'advertise_addr' => '192.168.1.1',
33-
'listen_addr' => '192.168.1.1',
33+
'listen_addr' => '192.168.1.1',
34+
} }
35+
it { is_expected.to compile.with_all_deps }
36+
it { should contain_exec('Swarm init').with_command(/docker swarm init/) }
37+
end
38+
39+
context 'with ensure => present and swarm init and default-addr-pool and default_addr_pool_mask_length' do
40+
let(:params) { {
41+
'init' => true,
42+
'advertise_addr' => '192.168.1.1',
43+
'listen_addr' => '192.168.1.1',
44+
'default_addr_pool' => ['30.30.0.0/16', '40.40.0.0/16'],
45+
'default_addr_pool_mask_length' => '24',
3446
} }
3547
it { is_expected.to compile.with_all_deps }
3648
it { should contain_exec('Swarm init').with_command(/docker swarm init/) }

0 commit comments

Comments
 (0)