Skip to content

Commit

Permalink
(CONT-1144) - Conversion of ERB to EPP templates
Browse files Browse the repository at this point in the history
  • Loading branch information
praj1001 committed Jul 25, 2023
1 parent b667bfe commit 5678de5
Show file tree
Hide file tree
Showing 64 changed files with 719 additions and 565 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/labeller.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
name: community-labeller
name: Labeller

on:
issues:
types:
- opened
- labeled
- unlabeled
pull_request_target:
types:
- opened
- labeled
- unlabeled

jobs:
label:
runs-on: ubuntu-latest
steps:

- uses: puppetlabs/community-labeller@v0
- uses: puppetlabs/community-labeller@v1.0.1
name: Label issues or pull requests
with:
label_name: community
label_color: '5319e7'
org_membership: puppetlabs
fail_if_member: 'true'
token: ${{ secrets.IAC_COMMUNITY_LABELER }}
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-03-29 09:56:35 UTC using RuboCop version 1.48.1.
# on 2023-07-20 04:54:59 UTC using RuboCop version 1.48.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -41,8 +41,8 @@ RSpec/NamedSubject:
- 'spec/classes/haproxy_spec.rb'
- 'spec/defines/instance_service_spec.rb'
- 'spec/defines/instance_spec.rb'
# Offense count: 183

# Offense count: 181
# Configuration parameters: AllowedPatterns.
# AllowedPatterns: ^expect_, ^assert_
RSpec/NoExpectationExample:
Expand Down
610 changes: 291 additions & 319 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ Data type: `String`

The template that will be used to create an unit file.

Default value: `'haproxy/instance_service_unit.erb'`
Default value: `'haproxy/instance_service_unit.epp'`

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

Expand Down
14 changes: 14 additions & 0 deletions lib/puppet/functions/haproxy/generate_error_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Function created to generate error message. Any string as error message can be passed and the function can
# be called in epp templates.

Puppet::Functions.create_function(:'haproxy::generate_error_message') do
dispatch :generate_error_message do
param 'String', :error_message
end

def generate_error_message(error_message)
raise(error_message)
end
end
15 changes: 15 additions & 0 deletions lib/puppet/functions/haproxy/sort_bind.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

Puppet::Functions.create_function(:'haproxy::sort_bind') do
dispatch :sort_bind do
param 'Hash', :bind
return_type 'Array'
end

def sort_bind(bind)
bind.sort_by do |address_port|
md = %r{^((\d+)\.(\d+)\.(\d+)\.(\d+))?(.*)}.match(address_port[0])
[(md[1] ? md[2..5].inject(0) { |addr, octet| (addr << 8) + octet.to_i } : -1), md[6]]
end
end
end
17 changes: 17 additions & 0 deletions lib/puppet/functions/haproxy/validate_ip_addr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'ipaddr'

Puppet::Functions.create_function(:'haproxy::validate_ip_addr') do
dispatch :validate_ip_addr do
param 'String', :virtual_ip
return_type 'Boolean'
end

def validate_ip_addr(virtual_ip)
IPAddr.new(virtual_ip)
true
rescue StandardError
false
end
end
10 changes: 9 additions & 1 deletion manifests/backend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,19 @@
$order = "25-${defaults}-${section_name}-01"
}

$parameters = {
'section_name' => $section_name,
'mode' => $mode,
'description' => $description,
'_sort_options_alphabetic' => $_sort_options_alphabetic,
'options' => $options,
}

# Template uses: $section_name, $ipaddress, $ports, $options
concat::fragment { "${instance_name}-${section_name}_backend_block":
order => $order,
target => $_config_file,
content => template('haproxy/haproxy_backend_block.erb'),
content => epp('haproxy/haproxy_backend_block.epp', $parameters),
}

if $collect_exported {
Expand Down
17 changes: 16 additions & 1 deletion manifests/balancermember.pp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,25 @@
} else {
$order = "25-${defaults}-${listening_service}-02-${name}"
}

$parameters = {
'type' => $type,
'ipaddresses' => $ipaddresses,
'server_names' => $server_names,
'ports' => $ports,
'define_cookies' => $define_cookies,
'options' => $options,
'verifyhost' => $verifyhost,
'weight' => $weight,
'prefix' => $prefix,
'amount' => $amount,
'fqdn' => $fqdn,
'port' => $port,
}
# Template uses $ipaddresses, $server_name, $ports, $option
concat::fragment { "${instance_name}-${listening_service}_balancermember_${name}":
order => $order,
target => $_config_file,
content => template('haproxy/haproxy_balancermember.erb'),
content => epp('haproxy/haproxy_balancermember.epp', $parameters),
}
}
8 changes: 7 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@
content => "# This file is managed by Puppet\n",
}

$parameters = {
'_global_options' => $_global_options,
'_defaults_options' => $_defaults_options,
'custom_fragment' => $custom_fragment,
}

# Template uses $_global_options, $_defaults_options, $custom_fragment
concat::fragment { "${instance_name}-haproxy-base":
target => $_config_file,
order => '10',
content => template("${module_name}/haproxy-base.cfg.erb"),
content => epp("${module_name}/haproxy-base.cfg.epp", $parameters),
}
}

Expand Down
8 changes: 7 additions & 1 deletion manifests/defaults.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@
include haproxy::globals
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)

$parameters = {
'_sort_options_alphabetic' => $_sort_options_alphabetic,
'options' => $options,
'name' => $name,
}

concat::fragment { "${instance_name}-${name}_defaults_block":
order => "25-${name}",
target => $config_file,
content => template('haproxy/haproxy_defaults_block.erb'),
content => epp('haproxy/haproxy_defaults_block.epp', $parameters),
}
}
15 changes: 14 additions & 1 deletion manifests/frontend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,23 @@
$order = "25-${defaults}-${section_name}-00"
}
}

$parameters = {
'section_name' => $section_name,
'bind' => $bind,
'ipaddress' => $ipaddress,
'ports' => $ports,
'bind_options' => $bind_options,
'mode' => $mode,
'description' => $description,
'options' => $options,
'_sort_options_alphabetic' => $_sort_options_alphabetic,
}

# Template uses: $section_name, $ipaddress, $ports, $options
concat::fragment { "${instance_name}-${section_name}_frontend_block":
order => $order,
target => $_config_file,
content => template('haproxy/haproxy_frontend_block.erb'),
content => epp('haproxy/haproxy_frontend_block.epp', $parameters),
}
}
8 changes: 6 additions & 2 deletions manifests/instance_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#
define haproxy::instance_service (
Optional[String] $haproxy_init_source = undef,
String $haproxy_unit_template = 'haproxy/instance_service_unit.erb',
String $haproxy_unit_template = 'haproxy/instance_service_unit.epp',
String $haproxy_package = 'haproxy',
Stdlib::Absolutepath $bindir = '/opt/haproxy/bin',
) {
Expand Down Expand Up @@ -103,12 +103,16 @@
$unitfile = "/lib/systemd/system/haproxy-${title}.service"
}

$parameters = {
'title' => $title,
'wrapper' => $wrapper,
}
file { $unitfile:
ensure => file,
mode => '0644',
owner => 'root',
group => 'root',
content => template($haproxy_unit_template),
content => epp($haproxy_unit_template, $parameters),
notify => Exec['systemctl daemon-reload'],
}
if (!defined(Exec['systemctl daemon-reload'])) {
Expand Down
14 changes: 13 additions & 1 deletion manifests/listen.pp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,23 @@
$order = "25-${defaults}-${section_name}-00"
}

$parameters = {
'section_name' => $section_name,
'bind' => $bind,
'ipaddress' => $ipaddress,
'ports' => $ports,
'bind_options' => $bind_options,
'mode' => $mode,
'description' => $description,
'options' => $options,
'_sort_options_alphabetic' => $_sort_options_alphabetic,
}

# Template uses: $section_name, $ipaddress, $ports, $options
concat::fragment { "${instance_name}-${section_name}_listen_block":
order => $order,
target => $_config_file,
content => template('haproxy/haproxy_listen_block.erb'),
content => epp('haproxy/haproxy_listen_block.epp', $parameters),
}

if $collect_exported {
Expand Down
8 changes: 7 additions & 1 deletion manifests/mailer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@
$config_file = inline_template($haproxy::params::config_file_tmpl)
}

$parameters = {
'ipaddresses' => $ipaddresses,
'server_names' => $server_names,
'port' => $port,
}

# Templates uses $ipaddresses, $server_name, $ports, $option
concat::fragment { "${instance_name}-mailers-${mailers_name}-${name}":
order => "40-mailers-01-${mailers_name}-${name}",
target => $config_file,
content => template('haproxy/haproxy_mailer.erb'),
content => epp('haproxy/haproxy_mailer.epp', $parameters),
}
}
6 changes: 5 additions & 1 deletion manifests/mailers.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
$config_file = inline_template($haproxy::params::config_file_tmpl)
}

$parameters = {
'name' => $name,
}

# Template uses: $name
concat::fragment { "${instance_name}-${name}_mailers_block":
order => "40-mailers-00-${name}",
target => $config_file,
content => template('haproxy/haproxy_mailers_block.erb'),
content => epp('haproxy/haproxy_mailers_block.epp', $parameters),
}

if $collect_exported {
Expand Down
7 changes: 6 additions & 1 deletion manifests/mapfile.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@
notify => Haproxy::Service[$_instances],
}

$parameters = {
'mappings' => $mappings,
'mapfile_name' => $mapfile_name,
}

concat::fragment { "haproxy_mapfile_${mapfile_name}-top":
target => $_mapfile_name,
content => template('haproxy/haproxy_mapfile.erb'),
content => epp('haproxy/haproxy_mapfile.epp', $parameters),
order => '00',
}
}
7 changes: 6 additions & 1 deletion manifests/mapfile/entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
) {
$_mapfile_name = "${haproxy::config_dir}/${mapfile}.map"

$parameters = {
'mappings' => $mappings,
'mapfile_name' => $title,
}

concat::fragment { "haproxy_mapfile_${mapfile}-${title}":
target => $_mapfile_name,
content => template('haproxy/haproxy_mapfile.erb'),
content => epp('haproxy/haproxy_mapfile.epp', $parameters),
order => $order,
}
}
8 changes: 7 additions & 1 deletion manifests/peer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}

$parameters = {
'ipaddresses' => $ipaddresses,
'server_names' => $server_names,
'port' => $port,
}

# Templates uses $ipaddresses, $server_name, $ports, $option
concat::fragment { "${instance_name}-peers-${peers_name}-${name}":
order => "30-peers-01-${peers_name}-${name}",
target => $_config_file,
content => template('haproxy/haproxy_peer.erb'),
content => epp('haproxy/haproxy_peer.epp', $parameters),
}
}
2 changes: 1 addition & 1 deletion manifests/peers.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
concat::fragment { "${instance_name}-${name}_peers_block":
order => "30-peers-00-${name}",
target => $_config_file,
content => template('haproxy/haproxy_peers_block.erb'),
content => epp('haproxy/haproxy_peers_block.epp', { 'name' => $name }),
}

if $collect_exported {
Expand Down
11 changes: 10 additions & 1 deletion manifests/resolver.pp
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,20 @@
$order = "25-${defaults}-${section_name}-02"
}

$parameters = {
'section_name' => $section_name,
'nameservers' => $nameservers,
'parse_resolv_conf' => $parse_resolv_conf,
'resolve_retries' => $resolve_retries,
'timeout' => $timeout,
'hold' => $hold,
'accepted_payload_size' => $accepted_payload_size,
}
# Template uses: $section_name
concat::fragment { "${instance_name}-${section_name}_resolver_block":
order => $order,
target => $_config_file,
content => template('haproxy/haproxy_resolver_block.erb'),
content => epp('haproxy/haproxy_resolver_block.epp', $parameters),
}

if $collect_exported {
Expand Down
Loading

0 comments on commit 5678de5

Please sign in to comment.