loadbalancer: do not manage HAproxy service on BACKUP nodes

When a loadbalancer is in BACKUP mode, HAproxy can't bind the pools to
the VIP, since the VIP is not hosted. Puppet warns it when compiling in
the catalogue.
This patch ensure HAproxy is run where we Keepalived is in MASTER mode.

If a failover occurs and MASTER has changed, Keepalived & HAproxy are auto-migrated thanks to VRRP to another node. The worth case will only show warnings in Puppet catalog but HAproxy won't start anyway on the node.

Bug #237
This commit is contained in:
Emilien Macchi 2014-04-29 15:55:02 +02:00
parent 32e17370fb
commit 047741708c
4 changed files with 21 additions and 4 deletions

View File

@ -41,7 +41,7 @@ fixtures:
ref: '04356974f72b90a1d0f57346a00e95a717924e43'
'haproxy':
repo: 'git://github.com/enovance/puppetlabs-haproxy.git'
ref: '0d4c50ed56f4fce06b66c04611cebec29f7a37a8'
ref: 'ff713f85d8fac7ade808f3d65d949a1a06b8ea88'
'keepalived':
repo: 'git://github.com/enovance/puppet-module-keepalived.git'
ref: 'eb345b6d3b25106cbe166028f2b8dd9974a10230'

View File

@ -74,7 +74,7 @@ mod 'dnsclient',
:ref => '4158b30f4660623f98dcdbd1ce9b482556180b57'
mod 'haproxy',
:git => 'git://github.com/enovance/puppetlabs-haproxy.git',
:ref => '0d4c50ed56f4fce06b66c04611cebec29f7a37a8'
:ref => 'ff713f85d8fac7ade808f3d65d949a1a06b8ea88'
mod 'inifile',
:git => 'git://github.com/enovance/puppetlabs-inifile.git',
:ref => 'ae23a4db97d2815ec305d0529912685f07746d3c'

View File

@ -253,9 +253,20 @@ class cloud::loadbalancer(
fail('galera_ip should be part of keepalived_public_ipvs or keepalived_internal_ipvs.')
}
# Ensure HAproxy service is only started on MASTER node
# It avoids binding warnings when running Puppet on BACKUP nodes where HAproxy
# tries to bind the services to the VIP which is not here.
if $keepalived_state == 'BACKUP' {
$manage_haproxy_service = false
} else {
$manage_haproxy_service = true
}
# Ensure Keepalived is started before HAproxy to avoid binding errors.
class { 'keepalived': } ->
class { 'haproxy': }
class { 'haproxy':
service_manage => $manage_haproxy_service
}
keepalived::vrrp_script { 'haproxy':
name_is_process => true

View File

@ -111,7 +111,7 @@ describe 'cloud::loadbalancer' do
end
end
context 'configure keepalived in backup' do
context 'when keepalived and HAproxy are in backup' do
it 'configure vrrp_instance with BACKUP state' do
should contain_keepalived__instance('1').with({
'interface' => params[:keepalived_public_interface],
@ -123,6 +123,9 @@ describe 'cloud::loadbalancer' do
'notify_backup' => '"/etc/init.d/haproxy stop"',
})
end # configure vrrp_instance with BACKUP state
it 'configure haproxy server without service managed' do
should contain_class('haproxy').with(:service_manage => false)
end # configure haproxy server
end # configure keepalived in backup
context 'configure keepalived in master' do
@ -139,6 +142,9 @@ describe 'cloud::loadbalancer' do
'notify_backup' => '"/etc/init.d/haproxy stop"',
})
end
it 'configure haproxy server with service managed' do
should contain_class('haproxy').with(:service_manage => true)
end # configure haproxy server
end # configure keepalived in master
context 'configure logrotate file' do