Skip to content

Commit

Permalink
Merge pull request #1300 from silkeh/fix-ipv6-upstream-member
Browse files Browse the repository at this point in the history
Fix IPv6 adresses in upstream members
  • Loading branch information
bastelfreak authored Feb 1, 2019
2 parents 3effaff + f24fe69 commit 9e46927
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions manifests/resource/upstream/member.pp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@
default => "${nginx::config::conf_dir}/conf.d",
}

$_server = ($server =~ Pattern[/^unix:\/([^\/\0]+\/*)*$/]) ? {
true => $server,
false => "${server}:${port}",
$_server = $server ? {
Pattern[/^unix:\/([^\/\0]+\/*)*$/] => $server,
Stdlib::IP::Address::V6 => "[${server}]:${port}", #lint:ignore:unquoted_string_in_selector
default => "${server}:${port}",
}

concat::fragment { "${upstream}_upstream_member_${name}":
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.22.0 < 6.0.0"
"version_requirement": ">= 4.25.0 < 6.0.0"
},
{
"name": "puppetlabs/concat",
Expand Down
6 changes: 6 additions & 0 deletions spec/acceptance/nginx_upstream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class { 'nginx': }
backup => true,
comment => 'Appserver 03',
},
'appserver_v6' => {
server => '2001:db8::6',
port => 80,
comment => 'Appserver with IPv6 address',
},
},
zone => 'production 64k',
}
Expand Down Expand Up @@ -78,6 +83,7 @@ class { 'nginx': }
it { is_expected.to contain ' server 10.10.10.1:80 weight=2 max_conns=10 max_fails=10 fail_timeout=10s; # Appserver 01' }
it { is_expected.to contain ' server 10.10.10.2:80 weight=3 max_conns=15 max_fails=15 fail_timeout=15s; # Appserver 02' }
it { is_expected.to contain ' server 10.10.10.3:80 max_conns=20 max_fails=20 fail_timeout=20s backup; # Appserver 03' }
it { is_expected.to contain ' server [2001:db8::6]:80 max_conns=20 max_fails=20 fail_timeout=20s; # Appserver with IPv6 address' }
it { is_expected.to contain ' ip_hash;' }
it { is_expected.to contain ' zone production 64k;' }
it { is_expected.to contain ' keepalive 16;' }
Expand Down
8 changes: 8 additions & 0 deletions spec/defines/resource_upstream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@
value: { member1: { server: '127.0.0.1', port: 8080 } },
match: '127.0.0.1:8080;'
},
{
value: { member1: { server: '2001:db8::1' } },
match: '[2001:db8::1]:80;'
},
{
value: { member1: { server: '2001:db8::1', port: 8080 } },
match: '[2001:db8::1]:8080;'
},
{
value: { member1: { weight: 20 } },
match: 'member1:80 weight=20;'
Expand Down

0 comments on commit 9e46927

Please sign in to comment.