Skip to content

Commit

Permalink
Merge pull request #610 from traylenator/ports
Browse files Browse the repository at this point in the history
Allow ports parameters as Stdlib::Ports
  • Loading branch information
bastelfreak authored May 22, 2024
2 parents 19051b6 + 13b08bb commit dcfd35d
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 59 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ node 'haproxy-server' {
haproxy::listen { 'puppet00':
collect_exported => false,
ipaddress => $facts['networking']['ip'],
ports => '8140',
ports => [8140],
}
haproxy::balancermember { 'server00':
listening_service => 'puppet00',
server_names => 'server00.example.com',
ipaddresses => '10.0.0.10',
ports => '8140',
ports => [8140],
options => 'check',
}
haproxy::balancermember { 'server01':
listening_service => 'puppet00',
server_names => 'server01.example.com',
ipaddresses => '10.0.0.11',
ports => '8140',
ports => [8140],
options => 'check',
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ To export the resource for a balancermember and collect it on a single HAProxy l
~~~puppet
haproxy::listen { 'puppet00':
ipaddress => $facts['networking']['ip'],
ports => '8140',
ports => [8140],
mode => 'tcp',
options => {
'option' => [
Expand Down Expand Up @@ -213,7 +213,7 @@ Then create the resource for multiple balancermembers at once:
~~~puppet
haproxy::balancermember { 'haproxy':
listening_service => 'puppet00',
ports => '8140',
ports => 8140,
server_names => ['server01', 'server02'],
ipaddresses => ['192.168.56.200', '192.168.56.201'],
options => 'check',
Expand All @@ -231,7 +231,7 @@ node 'haproxy-server' {
include ::haproxy
haproxy::listen { 'puppet00':
ipaddress => $facts['networking']['ip'],
ports => '8140',
ports => 8140,
}
}
Expand All @@ -240,7 +240,7 @@ node /^server\d+/ {
listening_service => 'puppet00',
server_names => $facts['networking']['hostname'],
ipaddresses => $facts['networking']['ip'],
ports => '8140',
ports => 8140,
options => 'check',
}
}
Expand All @@ -255,7 +255,7 @@ This example routes traffic from port 8140 to all balancermembers added to a bac
~~~puppet
haproxy::frontend { 'puppet00':
ipaddress => $facts['networking']['ip'],
ports => '8140',
ports => 8140,
mode => 'tcp',
bind_options => 'accept-proxy',
options => {
Expand All @@ -274,7 +274,7 @@ If option order is important, pass an array of hashes to the `options` parameter
~~~puppet
haproxy::frontend { 'puppet00':
ipaddress => $facts['networking']['ip'],
ports => '8140',
ports => [8140],
mode => 'tcp',
bind_options => 'accept-proxy',
options => [
Expand Down Expand Up @@ -353,7 +353,7 @@ haproxy::resolver { 'puppet00':
# Setup the balancermember to use the resolver for DNS resolution
haproxy::balancermember { 'haproxy':
listening_service => 'puppet00',
ports => '8140',
ports => 8140,
server_names => ['server01', 'server02'],
ipaddresses => ['server01', 'server02'],
options => 'check resolvers puppet00 resolve-prefer ipv4',
Expand Down Expand Up @@ -399,7 +399,7 @@ class and uses `haproxy::instance` to add an additional instance called
instance => 'haproxy',
collect_exported => false,
ipaddress => $facts['networking']['ip'],
ports => '8800',
ports => 8800,
}
haproxy::instance { 'beta': }
Expand All @@ -413,7 +413,7 @@ class and uses `haproxy::instance` to add an additional instance called
instance => 'beta',
collect_exported => false,
ipaddress => $facts['networking']['ip'],
ports => '9900',
ports => 9900,
}
~~~

Expand All @@ -432,7 +432,7 @@ The second uses a custom package.
instance => 'group1',
collect_exported => false,
ipaddress => $facts['networking']['ip'],
ports => '8800',
ports => 8800,
}
haproxy::instance { 'group2': }
->
Expand All @@ -446,7 +446,7 @@ The second uses a custom package.
instance => 'group2',
collect_exported => false,
ipaddress => $facts['networking']['ip'],
ports => '9900',
ports => 9900,
}
~~~

Expand Down Expand Up @@ -481,7 +481,7 @@ Or expressed using `haproxy::frontend`:
~~~puppet
haproxy::frontend { 'ft_allapps':
ipaddress => '0.0.0.0',
ports => '80',
ports => ['80'],
mode => 'http',
options => {
'use_backend' => '%[req.hdr(host),lower,map(/etc/haproxy/domains-to-backends.map,bk_default)]'
Expand Down
26 changes: 19 additions & 7 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ file on an haproxy load balancer.
* [`haproxy::sort_bind`](#haproxy--sort_bind)
* [`haproxy::validate_ip_addr`](#haproxy--validate_ip_addr)

### Data types

* [`Haproxy::Ports`](#Haproxy--Ports): Port or list of ports for haproxy. Supports `,` seperated list of ports also.

## Classes

### <a name="haproxy"></a>`haproxy`
Expand Down Expand Up @@ -485,7 +489,7 @@ Exporting the resource for a balancer member:
@@haproxy::balancermember { 'haproxy':
listening_service => 'puppet00',
ports => '8140',
ports => [8140],
server_names => $::hostname,
ipaddresses => $::ipaddress,
options => 'check',
Expand All @@ -505,7 +509,7 @@ pass to export the resources if you know the members in advance):
haproxy::balancermember { 'haproxy':
listening_service => 'puppet00',
ports => '8140',
ports => 8140,
server_names => ['server01', 'server02'],
ipaddresses => ['192.168.56.200', '192.168.56.201'],
options => 'check',
Expand Down Expand Up @@ -566,7 +570,7 @@ The haproxy service's instance name (or, the title of the

##### <a name="-haproxy--balancermember--ports"></a>`ports`

Data type: `Optional[Variant[Array, String]]`
Data type: `Optional[Haproxy::Ports]`

An array or commas-separated list of ports for which the balancer member
will accept connections from the load balancer. Note that cookie values
Expand Down Expand Up @@ -777,7 +781,7 @@ Exporting the resource for a balancer member:
haproxy::frontend { 'puppet00':
ipaddress => $::ipaddress,
ports => '18140',
ports => [18140],
mode => 'tcp',
bind_options => 'accept-proxy',
options => {
Expand Down Expand Up @@ -821,7 +825,7 @@ Default value: `$name`

##### <a name="-haproxy--frontend--ports"></a>`ports`

Data type: `Optional[Variant[Array, String]]`
Data type: `Optional[Haproxy::Ports]`

Ports on which the proxy will listen for connections on the ip address
specified in the ipaddress parameter. Accepts either a single
Expand Down Expand Up @@ -1286,7 +1290,7 @@ load balancer server.
```puppet
haproxy::listen { 'puppet00':
ipaddress => $::ipaddress,
ports => '18140',
ports => [18140],
mode => 'tcp',
options => {
'option' => [
Expand Down Expand Up @@ -1327,7 +1331,7 @@ Default value: `$name`

##### <a name="-haproxy--listen--ports"></a>`ports`

Data type: `Optional[Variant[Array, String]]`
Data type: `Optional[Haproxy::Ports]`

Ports on which the proxy will listen for connections on the ip address
specified in the ipaddress parameter. Accepts either a single
Expand Down Expand Up @@ -2085,3 +2089,11 @@ Data type: `String`



## Data types

### <a name="Haproxy--Ports"></a>`Haproxy::Ports`

Port or list of ports for haproxy. Supports `,` seperated list of ports also.

Alias of `Variant[Array[Variant[Pattern[/^[0-9]+$/],Stdlib::Port],0], Pattern[/^[0-9,]+$/], Stdlib::Port]`

6 changes: 3 additions & 3 deletions manifests/balancermember.pp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
#
# @@haproxy::balancermember { 'haproxy':
# listening_service => 'puppet00',
# ports => '8140',
# ports => [8140],
# server_names => $::hostname,
# ipaddresses => $::ipaddress,
# options => 'check',
Expand All @@ -108,7 +108,7 @@
#
# haproxy::balancermember { 'haproxy':
# listening_service => 'puppet00',
# ports => '8140',
# ports => 8140,
# server_names => ['server01', 'server02'],
# ipaddresses => ['192.168.56.200', '192.168.56.201'],
# options => 'check',
Expand Down Expand Up @@ -137,7 +137,7 @@
define haproxy::balancermember (
String $listening_service,
Enum['server', 'default-server', 'server-template'] $type = 'server',
Optional[Variant[Array, String]] $ports = undef,
Optional[Haproxy::Ports] $ports = undef,
Optional[Variant[String, Stdlib::Port]] $port = undef,
Variant[String[1], Array] $server_names = $facts['networking']['hostname'],
Variant[String, Array] $ipaddresses = $facts['networking']['ip'],
Expand Down
4 changes: 2 additions & 2 deletions manifests/frontend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#
# haproxy::frontend { 'puppet00':
# ipaddress => $::ipaddress,
# ports => '18140',
# ports => [18140],
# mode => 'tcp',
# bind_options => 'accept-proxy',
# options => {
Expand All @@ -91,7 +91,7 @@
# Gary Larizza <[email protected]>
#
define haproxy::frontend (
Optional[Variant[Array, String]] $ports = undef,
Optional[Haproxy::Ports] $ports = undef,
Optional[Variant[String, Array]] $ipaddress = undef,
Optional[Hash] $bind = undef,
Optional[Enum['tcp', 'http', 'health']] $mode = undef,
Expand Down
4 changes: 2 additions & 2 deletions manifests/listen.pp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
# @example
# haproxy::listen { 'puppet00':
# ipaddress => $::ipaddress,
# ports => '18140',
# ports => [18140],
# mode => 'tcp',
# options => {
# 'option' => [
Expand All @@ -94,7 +94,7 @@
# Gary Larizza <[email protected]>
#
define haproxy::listen (
Optional[Variant[Array, String]] $ports = undef,
Optional[Haproxy::Ports] $ports = undef,
Optional[Variant[String, Array]] $ipaddress = undef,
Optional[Hash] $bind = undef,
Optional[Enum['tcp', 'http', 'health']] $mode = undef,
Expand Down
30 changes: 28 additions & 2 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ class { 'haproxy':

describe 'configuring haproxy load balancing' do
describe 'multiple ports' do
pp_two = <<-PUPPETCODE
class { 'haproxy': }
haproxy::listen { 'stats':
ipaddress => '127.0.0.1',
ports => [9090, 9091],
mode => 'http',
options => { 'stats' => ['uri /','auth puppet:puppet'], },
}
PUPPETCODE
it 'is able to listen on an array of ports' do
retry_on_error_matching do
apply_manifest(pp_two, catch_failures: true)
end
end

['9090', '9091'].each do |port|
it "port #{port} has stats listening on each port" do
run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
expect(r.stdout).to contain %r{HAProxy}
expect(r.exit_code).to eq 0
end
end
end
end

describe 'multiple ports as strings' do
pp_two = <<-PUPPETCODE
class { 'haproxy': }
haproxy::listen { 'stats':
Expand Down Expand Up @@ -71,7 +97,7 @@ class { 'haproxy::globals':
class { 'haproxy': }
haproxy::listen { 'stats':
ipaddress => '127.0.0.1',
ports => ['9090','9091'],
ports => [9090,9091],
mode => 'http',
options => { 'stats' => ['uri /','auth puppet:puppet'], },
}
Expand Down Expand Up @@ -101,7 +127,7 @@ class { 'haproxy::globals':
class { 'haproxy': }
haproxy::listen { 'stats':
ipaddress => '127.0.0.1',
ports => ['9091'],
ports => [9091],
mode => 'http',
}
haproxy::backend { 'servers':
Expand Down
Loading

0 comments on commit dcfd35d

Please sign in to comment.