From facd4080362e7a8d072ab675072d76e3bc564ab1 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 14:14:04 +0200 Subject: [PATCH 01/46] add multi instance support for redis-sentinel --- manifests/params.pp | 14 ++ manifests/sentinel.pp | 127 +++++++++++------- templates/redis-sentinel.conf.erb | 24 ---- .../sentinal/redis-sentinel.conf_footer.erb | 3 + .../sentinal/redis-sentinel.conf_header.erb | 7 + .../sentinal/redis-sentinel.conf_master.epp | 27 ++++ types/mastername.pp | 12 ++ 7 files changed, 141 insertions(+), 73 deletions(-) delete mode 100644 templates/redis-sentinel.conf.erb create mode 100644 templates/sentinal/redis-sentinel.conf_footer.erb create mode 100644 templates/sentinal/redis-sentinel.conf_header.erb create mode 100644 templates/sentinal/redis-sentinel.conf_master.epp create mode 100644 types/mastername.pp diff --git a/manifests/params.pp b/manifests/params.pp index 7c1b5145..71a2c1d7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -200,4 +200,18 @@ fail "Operating system ${facts['os']['name']} is not supported yet." } } + + $sentinel_master_name = [ + 'mymaster' => { + redis_host => '127.0.0.1', + redis_port => 6379, + quorum => 2, + down_after => 30000, + parallel_sync => 1, + failover_timeout => 180000, + auth_pass => undef, + notification_script => undef, + client_reconfig_script => undef, + } + ] } diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 14948742..3f968cc7 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -1,7 +1,42 @@ # @summary Install redis-sentinel # -# @param auth_pass -# The password to use to authenticate with the master and slaves. +# @param master_name +# Specify the name of the master redis server. +# The valid charset is A-z 0-9 and the three characters ".-_". +# Hash with following Keys: +# @key auth_pass +# The password to use to authenticate with the master and slaves. +# +# @key redis_host +# Specify the bound host of the master redis server. +# +# @key redis_port +# Specify the port of the master redis server. +# +# @key daemonize +# Have Redis sentinel run as a daemon. +# +# @key down_after +# Number of milliseconds the master (or any attached slave or sentinel) +# should be unreachable (as in, not acceptable reply to PING, continuously, +# for the specified period) in order to consider it in S_DOWN state. +# +# @key failover_timeout +# Specify the failover timeout in milliseconds. +# +# @key parallel_sync +# How many slaves can be reconfigured at the same time to use a +# new master after a failover. +# +# @key quorum +# Number of sentinels that must agree that a master is down to +# signal sdown state. +# +# @key notification_script +# Path to the notification script +# +# @key client_reconfig_script +# Path to the client-reconfig script # # @param config_file # The location and name of the sentinel config file. @@ -19,17 +54,6 @@ # @param conf_template # Define which template to use. # -# @param daemonize -# Have Redis sentinel run as a daemon. -# -# @param down_after -# Number of milliseconds the master (or any attached slave or sentinel) -# should be unreachable (as in, not acceptable reply to PING, continuously, -# for the specified period) in order to consider it in S_DOWN state. -# -# @param failover_timeout -# Specify the failover timeout in milliseconds. -# # @param init_script # Specifiy the init script that will be created for sentinel. # @@ -43,29 +67,15 @@ # Specify the name of the master redis server. # The valid charset is A-z 0-9 and the three characters ".-_". # -# @param redis_host -# Specify the bound host of the master redis server. -# -# @param redis_port -# Specify the port of the master redis server. -# # @param package_name # The name of the package that installs sentinel. # # @param package_ensure # Do we ensure this package. # -# @param parallel_sync -# How many slaves can be reconfigured at the same time to use a -# new master after a failover. -# # @param pid_file # If sentinel is daemonized it will write its pid at this location. # -# @param quorum -# Number of sentinels that must agree that a master is down to -# signal sdown state. -# # @param sentinel_bind # Allow optional sentinel server ip binding. Can help overcome # issues arising from protect-mode added Redis 3.2 @@ -89,12 +99,6 @@ # The directory into which sentinel will change to avoid mount # conflicts. # -# @param notification_script -# Path to the notification script -# -# @param client_reconfig_script -# Path to the client-reconfig script -# # @example Basic inclusion # include redis::sentinel # @@ -105,26 +109,20 @@ # } # class redis::sentinel ( - Optional[String[1]] $auth_pass = undef, Stdlib::Absolutepath $config_file = $redis::params::sentinel_config_file, Stdlib::Absolutepath $config_file_orig = $redis::params::sentinel_config_file_orig, Stdlib::Filemode $config_file_mode = '0644', String[1] $conf_template = 'redis/redis-sentinel.conf.erb', Boolean $daemonize = $redis::params::sentinel_daemonize, - Integer[1] $down_after = 30000, - Integer[1] $failover_timeout = 180000, Optional[Stdlib::Absolutepath] $init_script = $redis::params::sentinel_init_script, String[1] $init_template = 'redis/redis-sentinel.init.erb', Redis::LogLevel $log_level = 'notice', Stdlib::Absolutepath $log_file = $redis::params::sentinel_log_file, - String[1] $master_name = 'mymaster', - Stdlib::Host $redis_host = '127.0.0.1', - Stdlib::Port $redis_port = 6379, + Redis::MasterName $master_name = $redis::params::sentinel_master_name, String[1] $package_name = $redis::params::sentinel_package_name, String[1] $package_ensure = 'present', Integer[0] $parallel_sync = 1, Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, - Integer[1] $quorum = 2, Variant[Undef, Stdlib::IP::Address, Array[Stdlib::IP::Address]] $sentinel_bind = undef, Stdlib::Port $sentinel_port = 26379, String[1] $service_group = 'redis', @@ -133,8 +131,6 @@ Boolean $service_enable = true, String[1] $service_user = 'redis', Stdlib::Absolutepath $working_dir = $redis::params::sentinel_working_dir, - Optional[Stdlib::Absolutepath] $notification_script = undef, - Optional[Stdlib::Absolutepath] $client_reconfig_script = undef, ) inherits redis::params { require 'redis' @@ -150,17 +146,50 @@ } } - file { $config_file_orig: - ensure => file, - owner => $service_user, - group => $service_group, - mode => $config_file_mode, - content => template($conf_template), + Concat { + owner => $service_user, + group => $service_group, + mode => $config_file_mode, + } + + concat { $config_file_orig: + ensure => file, + } + + concat::fragment { 'sentinel_conf_header': + target => $config_file_orig, + order => 10, + content => template('redis/sentinel/redis-sentine.conf_header.erb'), + } + + $master_name.each |Hash $master| { + concat::fragment { "sentinel_conf_master_${master[0]}" : + target => $config_file_orig, + order => 20, + content => epp('redis/sentinel/redis-sentine.conf_master.epp', { + master_name => $master[0], + redis_host => $master['redis_host'], + redis_port => $master['redis_port'], + quorum => $master['quorum'], + down_after => $master['down_after'], + parallel_sync => $master['parallel_sync'], + failover_timeout => $master['failover_timeout'], + auth_pass => $master['auth_pass'], + notification_script => $master['notification_script'], + client_reconfig_script => $master['client_reconfig_script'], + }), + } + } + + concat::fragment { 'sentinel_conf_footer': + target => $config_file_orig, + order => 30, + content => template('redis/sentinel/redis-sentine.conf_footer.erb'), } exec { "cp -p ${config_file_orig} ${config_file}": path => '/usr/bin:/bin', - subscribe => File[$config_file_orig], + subscribe => Concat[$config_file_orig], notify => Service[$service_name], refreshonly => true, } diff --git a/templates/redis-sentinel.conf.erb b/templates/redis-sentinel.conf.erb deleted file mode 100644 index d11c4024..00000000 --- a/templates/redis-sentinel.conf.erb +++ /dev/null @@ -1,24 +0,0 @@ -<% if @sentinel_bind -%> -bind <%= @sentinel_bind %> -<% end -%> -port <%= @sentinel_port %> -dir <%= @working_dir %> -daemonize <%= @daemonize ? 'yes' : 'no' %> -pidfile <%= @pid_file %> - -sentinel monitor <%= @master_name %> <%= @redis_host %> <%= @redis_port %> <%= @quorum %> -sentinel down-after-milliseconds <%= @master_name %> <%= @down_after %> -sentinel parallel-syncs <%= @master_name %> <%= @parallel_sync %> -sentinel failover-timeout <%= @master_name %> <%= @failover_timeout %> -<% if @auth_pass -%> -sentinel auth-pass <%= @master_name %> <%= @auth_pass %> -<% end -%> -<% if @notification_script -%> -sentinel notification-script <%= @master_name %> <%= @notification_script %> -<% end -%> -<% if @client_reconfig_script -%> -sentinel client-reconfig-script <%= @master_name %> <%= @client_reconfig_script %> -<% end -%> - -loglevel <%= @log_level %> -logfile <%= @log_file %> diff --git a/templates/sentinal/redis-sentinel.conf_footer.erb b/templates/sentinal/redis-sentinel.conf_footer.erb new file mode 100644 index 00000000..65f1ec8e --- /dev/null +++ b/templates/sentinal/redis-sentinel.conf_footer.erb @@ -0,0 +1,3 @@ + +loglevel <%= @log_level %> +logfile <%= @log_file %> diff --git a/templates/sentinal/redis-sentinel.conf_header.erb b/templates/sentinal/redis-sentinel.conf_header.erb new file mode 100644 index 00000000..e4049baf --- /dev/null +++ b/templates/sentinal/redis-sentinel.conf_header.erb @@ -0,0 +1,7 @@ +<% if @sentinel_bind -%> +bind <%= @sentinel_bind %> +<% end -%> +port <%= @sentinel_port %> +dir <%= @working_dir %> +daemonize <%= @daemonize ? 'yes' : 'no' %> +pidfile <%= @pid_file %> diff --git a/templates/sentinal/redis-sentinel.conf_master.epp b/templates/sentinal/redis-sentinel.conf_master.epp new file mode 100644 index 00000000..71e5b07c --- /dev/null +++ b/templates/sentinal/redis-sentinel.conf_master.epp @@ -0,0 +1,27 @@ +<%- | + $master_name, + $redis_host, + $redis_port, + $quorum, + $down_after, + $parallel_sync, + $failover_timeout, + $auth_pass, + $notification_script, + $client_reconfig_script, +| -%> + + +sentinel monitor <%= $master_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> +sentinel down-after-milliseconds <%= $master_name %> <%= $down_after %> +sentinel parallel-syncs <%= $master_name %> <%= $parallel_sync %> +sentinel failover-timeout <%= $master_name %> <%= $failover_timeout %> +<% if $auth_pass { -%> +sentinel auth-pass <%= $master_name %> <%= $auth_pass %> +<% } -%> +<% if $notification_script { -%> +sentinel notification-script <%= $master_name %> <%= $notification_script %> +<% } -%> +<% if $client_reconfig_script { -%> +sentinel client-reconfig-script <%= $master_name %> <%= $client_reconfig_script %> +<% } -%> diff --git a/types/mastername.pp b/types/mastername.pp new file mode 100644 index 00000000..c6b3745c --- /dev/null +++ b/types/mastername.pp @@ -0,0 +1,12 @@ +type Redis::MasterName = Array[Hash[String, Struct[{ + auth_pass => String, + redis_host => Stdlib::Host, + redis_port => Stdlib::Port, + quorum => Integer[1], + down_after => Integer[1], + parallel_sync => Integer[0], + failover_timeout => Integer[1], + Optional[auth_pass] => String, + Optional[notification_script] => Stdlib::Absolutepath, + Optional[client_reconfig_script] => Stdlib::Absolutepat,} +],1,1]] From c87be3292777348a69df6b41480789b796a2f3ca Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 17:19:36 +0200 Subject: [PATCH 02/46] add multi instance support to sentinel --- manifests/sentinel.pp | 57 ++++++++++++------- .../sentinel/redis-sentinel.conf_footer.erb | 3 + .../sentinel/redis-sentinel.conf_header.erb | 7 +++ .../sentinel/redis-sentinel.conf_master.epp | 26 +++++++++ types/mastername.pp | 6 +- 5 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 templates/sentinel/redis-sentinel.conf_footer.erb create mode 100644 templates/sentinel/redis-sentinel.conf_header.erb create mode 100644 templates/sentinel/redis-sentinel.conf_master.epp diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 3f968cc7..f4cb7e6e 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -104,8 +104,27 @@ # # @example Configuring options # class {'redis::sentinel': -# down_after => 80000, -# log_file => '/var/log/redis/sentinel.log', +# log_file => '/var/log/redis/sentinel.log', +# master_name => { +# 'session_6381' => { +# redis_host => $redis_master_ip, +# redis_port => 6381, +# quorum => 2, +# parallel_sync => 1, +# down_after => 5000, +# failover_timeout => 12000, +# auth_pass => $redis_auth, +# }, +# 'cache_6380' => { +# redis_host => $redis_master_ip, +# redis_port => 6380, +# quorum => 2, +# parallel_sync => 1, +# down_after => 5000, +# failover_timeout => 12000, +# auth_pass => $redis_auth, +# } +# } # } # class redis::sentinel ( @@ -138,7 +157,7 @@ if $facts['os']['family'] == 'Debian' { package { $package_name: ensure => $package_ensure, - before => File[$config_file_orig], + before => Concat[$config_file_orig], } if $init_script { @@ -153,30 +172,30 @@ } concat { $config_file_orig: - ensure => file, + ensure => present, } concat::fragment { 'sentinel_conf_header': target => $config_file_orig, order => 10, - content => template('redis/sentinel/redis-sentine.conf_header.erb'), + content => template('redis/sentinel/redis-sentinel.conf_header.erb'), } - $master_name.each |Hash $master| { - concat::fragment { "sentinel_conf_master_${master[0]}" : + $master_name.each |String $master, Hash $params| { + concat::fragment { "sentinel_conf_master_${master}" : target => $config_file_orig, order => 20, - content => epp('redis/sentinel/redis-sentine.conf_master.epp', { - master_name => $master[0], - redis_host => $master['redis_host'], - redis_port => $master['redis_port'], - quorum => $master['quorum'], - down_after => $master['down_after'], - parallel_sync => $master['parallel_sync'], - failover_timeout => $master['failover_timeout'], - auth_pass => $master['auth_pass'], - notification_script => $master['notification_script'], - client_reconfig_script => $master['client_reconfig_script'], + content => epp('redis/sentinel/redis-sentinel.conf_master.epp', { + master_name => $master, + redis_host => $params['redis_host'], + redis_port => $params['redis_port'], + quorum => $params['quorum'], + down_after => $params['down_after'], + parallel_sync => $params['parallel_sync'], + failover_timeout => $params['failover_timeout'], + auth_pass => $params['auth_pass'], + notification_script => $params['notification_script'], + client_reconfig_script => $params['client_reconfig_script'], }), } } @@ -184,7 +203,7 @@ concat::fragment { 'sentinel_conf_footer': target => $config_file_orig, order => 30, - content => template('redis/sentinel/redis-sentine.conf_footer.erb'), + content => template('redis/sentinel/redis-sentinel.conf_footer.erb'), } exec { "cp -p ${config_file_orig} ${config_file}": diff --git a/templates/sentinel/redis-sentinel.conf_footer.erb b/templates/sentinel/redis-sentinel.conf_footer.erb new file mode 100644 index 00000000..65f1ec8e --- /dev/null +++ b/templates/sentinel/redis-sentinel.conf_footer.erb @@ -0,0 +1,3 @@ + +loglevel <%= @log_level %> +logfile <%= @log_file %> diff --git a/templates/sentinel/redis-sentinel.conf_header.erb b/templates/sentinel/redis-sentinel.conf_header.erb new file mode 100644 index 00000000..e4049baf --- /dev/null +++ b/templates/sentinel/redis-sentinel.conf_header.erb @@ -0,0 +1,7 @@ +<% if @sentinel_bind -%> +bind <%= @sentinel_bind %> +<% end -%> +port <%= @sentinel_port %> +dir <%= @working_dir %> +daemonize <%= @daemonize ? 'yes' : 'no' %> +pidfile <%= @pid_file %> diff --git a/templates/sentinel/redis-sentinel.conf_master.epp b/templates/sentinel/redis-sentinel.conf_master.epp new file mode 100644 index 00000000..fcc019aa --- /dev/null +++ b/templates/sentinel/redis-sentinel.conf_master.epp @@ -0,0 +1,26 @@ +<%- | + $master_name, + $redis_host, + $redis_port, + $quorum, + $down_after, + $parallel_sync, + $failover_timeout, + $auth_pass, + $notification_script, + $client_reconfig_script, +| -%> + +sentinel monitor <%= $master_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> +sentinel down-after-milliseconds <%= $master_name %> <%= $down_after %> +sentinel parallel-syncs <%= $master_name %> <%= $parallel_sync %> +sentinel failover-timeout <%= $master_name %> <%= $failover_timeout %> +<% if $auth_pass { -%> +sentinel auth-pass <%= $master_name %> <%= $auth_pass %> +<% } -%> +<% if $notification_script { -%> +sentinel notification-script <%= $master_name %> <%= $notification_script %> +<% } -%> +<% if $client_reconfig_script { -%> +sentinel client-reconfig-script <%= $master_name %> <%= $client_reconfig_script %> +<% } -%> diff --git a/types/mastername.pp b/types/mastername.pp index c6b3745c..75cba3ec 100644 --- a/types/mastername.pp +++ b/types/mastername.pp @@ -1,4 +1,4 @@ -type Redis::MasterName = Array[Hash[String, Struct[{ +type Redis::MasterName = Hash[String, Struct[{ auth_pass => String, redis_host => Stdlib::Host, redis_port => Stdlib::Port, @@ -8,5 +8,5 @@ failover_timeout => Integer[1], Optional[auth_pass] => String, Optional[notification_script] => Stdlib::Absolutepath, - Optional[client_reconfig_script] => Stdlib::Absolutepat,} -],1,1]] + Optional[client_reconfig_script] => Stdlib::Absolutepath,} +],1] From a4d1b5bb3a7b8dd4dd784ffa7e05f4d4a91200cc Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 17:36:57 +0200 Subject: [PATCH 03/46] set auth_pass to optional / spec changed --- .../suites/default/redis_sentinel_one_node_spec.rb | 12 +++++++++--- spec/classes/redis_sentinel_spec.rb | 14 ++++++++------ templates/sentinal/redis-sentinel.conf_master.epp | 1 - types/mastername.pp | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index 277242f5..97af63fd 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -11,9 +11,15 @@ it 'runs successfully' do pp = <<-EOS class { 'redis::sentinel': - master_name => 'mymaster', - redis_host => '127.0.0.1', - failover_timeout => 10000, + master_name => { + 'mymaster' => { + redis_host => '127.0.0.1', + redis_port => 6379, + quorum => 2, + parallel_sync => 1, + down_after => 30000, + failover_timeout => 180000, + }, } EOS diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index f906e4d1..57009432 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -73,15 +73,17 @@ describe 'with custom parameters' do let(:params) do { - auth_pass: 'password', + master_name: { 'cow' => { + 'auth_pass' => 'password', + 'down_after' => 6000, + 'parallel_sync' => 1, + 'failover_timeout' => 28_000, + 'notification_script' => '/path/to/bar.sh', + 'client_reconfig_script' => '/path/to/foo.sh', + } sentinel_bind: '192.0.2.10', - master_name: 'cow', - down_after: 6000, working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log', - failover_timeout: 28_000, - notification_script: '/path/to/bar.sh', - client_reconfig_script: '/path/to/foo.sh' } end diff --git a/templates/sentinal/redis-sentinel.conf_master.epp b/templates/sentinal/redis-sentinel.conf_master.epp index 71e5b07c..fcc019aa 100644 --- a/templates/sentinal/redis-sentinel.conf_master.epp +++ b/templates/sentinal/redis-sentinel.conf_master.epp @@ -11,7 +11,6 @@ $client_reconfig_script, | -%> - sentinel monitor <%= $master_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> sentinel down-after-milliseconds <%= $master_name %> <%= $down_after %> sentinel parallel-syncs <%= $master_name %> <%= $parallel_sync %> diff --git a/types/mastername.pp b/types/mastername.pp index 75cba3ec..50d2d2ed 100644 --- a/types/mastername.pp +++ b/types/mastername.pp @@ -1,5 +1,4 @@ type Redis::MasterName = Hash[String, Struct[{ - auth_pass => String, redis_host => Stdlib::Host, redis_port => Stdlib::Port, quorum => Integer[1], @@ -7,6 +6,7 @@ parallel_sync => Integer[0], failover_timeout => Integer[1], Optional[auth_pass] => String, + Optional[auth_pass] => String, Optional[notification_script] => Stdlib::Absolutepath, Optional[client_reconfig_script] => Stdlib::Absolutepath,} ],1] From dc95a1329ea7ba98abc8409f37517e4d567dc55d Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 17:47:11 +0200 Subject: [PATCH 04/46] fix sentinel spec --- spec/classes/redis_sentinel_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 57009432..e27e7536 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -80,7 +80,7 @@ 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', 'client_reconfig_script' => '/path/to/foo.sh', - } + }, sentinel_bind: '192.0.2.10', working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log', From c4230cffb9ad24d7159a377242030c3b3765d03c Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 17:50:28 +0200 Subject: [PATCH 05/46] TGTIT: Thx god there is Travis --- manifests/params.pp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 71a2c1d7..08b0547b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -201,7 +201,7 @@ } } - $sentinel_master_name = [ + $sentinel_master_name = { 'mymaster' => { redis_host => '127.0.0.1', redis_port => 6379, @@ -212,6 +212,6 @@ auth_pass => undef, notification_script => undef, client_reconfig_script => undef, - } - ] + }, + } } From 4744ae649f09a81a5179994529d6232a8ee1b295 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 17:53:39 +0200 Subject: [PATCH 06/46] delete doubled auth_pass in type --- types/mastername.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/types/mastername.pp b/types/mastername.pp index 50d2d2ed..edf35b7e 100644 --- a/types/mastername.pp +++ b/types/mastername.pp @@ -6,7 +6,6 @@ parallel_sync => Integer[0], failover_timeout => Integer[1], Optional[auth_pass] => String, - Optional[auth_pass] => String, Optional[notification_script] => Stdlib::Absolutepath, Optional[client_reconfig_script] => Stdlib::Absolutepath,} ],1] From deb40756520d04dbf68775e5b9d6669d401754e1 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 18:09:58 +0200 Subject: [PATCH 07/46] close the given hash --- spec/classes/redis_sentinel_spec.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index e27e7536..83819c5f 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -73,13 +73,15 @@ describe 'with custom parameters' do let(:params) do { - master_name: { 'cow' => { - 'auth_pass' => 'password', - 'down_after' => 6000, - 'parallel_sync' => 1, - 'failover_timeout' => 28_000, - 'notification_script' => '/path/to/bar.sh', - 'client_reconfig_script' => '/path/to/foo.sh', + master_name: { + 'cow' => { + 'auth_pass' => 'password', + 'down_after' => 6000, + 'parallel_sync' => 1, + 'failover_timeout' => 28_000, + 'notification_script' => '/path/to/bar.sh', + 'client_reconfig_script' => '/path/to/foo.sh', + }, }, sentinel_bind: '192.0.2.10', working_dir: '/tmp/redis', From 68f44c46a9d700a6332a706edf1d5389a452dc8f Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 18:11:53 +0200 Subject: [PATCH 08/46] accidently added folder with wrong name --- .../sentinal/redis-sentinel.conf_footer.erb | 3 --- .../sentinal/redis-sentinel.conf_header.erb | 7 ----- .../sentinal/redis-sentinel.conf_master.epp | 26 ------------------- 3 files changed, 36 deletions(-) delete mode 100644 templates/sentinal/redis-sentinel.conf_footer.erb delete mode 100644 templates/sentinal/redis-sentinel.conf_header.erb delete mode 100644 templates/sentinal/redis-sentinel.conf_master.epp diff --git a/templates/sentinal/redis-sentinel.conf_footer.erb b/templates/sentinal/redis-sentinel.conf_footer.erb deleted file mode 100644 index 65f1ec8e..00000000 --- a/templates/sentinal/redis-sentinel.conf_footer.erb +++ /dev/null @@ -1,3 +0,0 @@ - -loglevel <%= @log_level %> -logfile <%= @log_file %> diff --git a/templates/sentinal/redis-sentinel.conf_header.erb b/templates/sentinal/redis-sentinel.conf_header.erb deleted file mode 100644 index e4049baf..00000000 --- a/templates/sentinal/redis-sentinel.conf_header.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% if @sentinel_bind -%> -bind <%= @sentinel_bind %> -<% end -%> -port <%= @sentinel_port %> -dir <%= @working_dir %> -daemonize <%= @daemonize ? 'yes' : 'no' %> -pidfile <%= @pid_file %> diff --git a/templates/sentinal/redis-sentinel.conf_master.epp b/templates/sentinal/redis-sentinel.conf_master.epp deleted file mode 100644 index fcc019aa..00000000 --- a/templates/sentinal/redis-sentinel.conf_master.epp +++ /dev/null @@ -1,26 +0,0 @@ -<%- | - $master_name, - $redis_host, - $redis_port, - $quorum, - $down_after, - $parallel_sync, - $failover_timeout, - $auth_pass, - $notification_script, - $client_reconfig_script, -| -%> - -sentinel monitor <%= $master_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> -sentinel down-after-milliseconds <%= $master_name %> <%= $down_after %> -sentinel parallel-syncs <%= $master_name %> <%= $parallel_sync %> -sentinel failover-timeout <%= $master_name %> <%= $failover_timeout %> -<% if $auth_pass { -%> -sentinel auth-pass <%= $master_name %> <%= $auth_pass %> -<% } -%> -<% if $notification_script { -%> -sentinel notification-script <%= $master_name %> <%= $notification_script %> -<% } -%> -<% if $client_reconfig_script { -%> -sentinel client-reconfig-script <%= $master_name %> <%= $client_reconfig_script %> -<% } -%> From 1a4e9b69f6ec6eb96e346ea09c5c106419d30ce4 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 18:14:18 +0200 Subject: [PATCH 09/46] fix closing class in acceptance test --- spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index 97af63fd..3638a0b6 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -19,6 +19,7 @@ class { 'redis::sentinel': parallel_sync => 1, down_after => 30000, failover_timeout => 180000, + }, }, } EOS From 7e811fc12a849e8cdf49dbc19d2f514f136b31f4 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 18:24:29 +0200 Subject: [PATCH 10/46] add parameter to fix full cover test --- .../default/redis_sentinel_one_node_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index 3638a0b6..10a927e0 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -13,12 +13,15 @@ class { 'redis::sentinel': master_name => { 'mymaster' => { - redis_host => '127.0.0.1', - redis_port => 6379, - quorum => 2, - parallel_sync => 1, - down_after => 30000, - failover_timeout => 180000, + redis_host => '127.0.0.1', + redis_port => 6379, + quorum => 2, + parallel_sync => 1, + down_after => 30000, + failover_timeout => 180000, + auth_pass => 'mymastertest', + notification_script => '/path/to/bar.sh', + client_reconfig_script => '/path/to/foo.sh', }, }, } From dafbd47e7bbdf5b5fc9204d48282bffb8babe24e Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 18:26:14 +0200 Subject: [PATCH 11/46] fix redis_sentinel_spec --- spec/classes/redis_sentinel_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 83819c5f..8dbc35fb 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -75,11 +75,15 @@ { master_name: { 'cow' => { - 'auth_pass' => 'password', - 'down_after' => 6000, - 'parallel_sync' => 1, - 'failover_timeout' => 28_000, - 'notification_script' => '/path/to/bar.sh', + 'redis_host' => '127.0.0.1', + 'redis_port' => 6379, + 'quorum' => 2, + 'parallel_sync' => 1, + 'auth_pass' => 'password', + 'down_after' => 6000, + 'parallel_sync' => 1, + 'failover_timeout' => 28_000, + 'notification_script' => '/path/to/bar.sh', 'client_reconfig_script' => '/path/to/foo.sh', }, }, From c213e887eb6ff158f367de8941f6c7cc2be55296 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 5 May 2020 18:32:28 +0200 Subject: [PATCH 12/46] fix travis --- spec/classes/redis_sentinel_spec.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 8dbc35fb..9693b71f 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -81,15 +81,14 @@ 'parallel_sync' => 1, 'auth_pass' => 'password', 'down_after' => 6000, - 'parallel_sync' => 1, 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', - 'client_reconfig_script' => '/path/to/foo.sh', - }, + 'client_reconfig_script' => '/path/to/foo.sh' + } }, sentinel_bind: '192.0.2.10', working_dir: '/tmp/redis', - log_file: '/tmp/barn-sentinel.log', + log_file: '/tmp/barn-sentinel.log' } end From fef0597d5881e74fbba489f8f77d15c924a28492 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 6 May 2020 13:01:07 +0200 Subject: [PATCH 13/46] new variable name / puppet strings --- REFERENCE.md | 139 +++++++----------- manifests/params.pp | 6 +- manifests/sentinel.pp | 107 +++++--------- .../default/redis_sentinel_one_node_spec.rb | 16 +- spec/classes/redis_sentinel_spec.rb | 21 +-- .../sentinel/redis-sentinel.conf_master.epp | 16 +- types/mastername.pp | 11 -- types/sentinelmonitor.pp | 12 ++ 8 files changed, 121 insertions(+), 207 deletions(-) delete mode 100644 types/mastername.pp create mode 100644 types/sentinelmonitor.pp diff --git a/REFERENCE.md b/REFERENCE.md index 2ef6df25..6af46a26 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -34,6 +34,7 @@ repositories. * [`Redis::LogLevel`](#redisloglevel): Specify the server verbosity level. * [`Redis::RedisUrl`](#redisredisurl): +* [`Redis::SentinelMonitor`](#redissentinelmonitor): **Tasks** @@ -973,18 +974,31 @@ Install redis-sentinel #### Examples -##### Basic inclusion - -```puppet -include redis::sentinel -``` - ##### Configuring options ```puppet class {'redis::sentinel': - down_after => 80000, log_file => '/var/log/redis/sentinel.log', + master_name => { + 'session_6381' => { + redis_host => $redis_master_ip, + redis_port => 6381, + quorum => 2, + parallel_sync => 1, + down_after => 5000, + failover_timeout => 12000, + auth_pass => $redis_auth, + }, + 'cache_6380' => { + redis_host => $redis_master_ip, + redis_port => 6380, + quorum => 2, + parallel_sync => 1, + down_after => 5000, + failover_timeout => 12000, + auth_pass => $redis_auth, + } + } } ``` @@ -992,13 +1006,13 @@ class {'redis::sentinel': The following parameters are available in the `redis::sentinel` class. -##### `auth_pass` +##### `sentinel_monitor` -Data type: `Optional[String[1]]` +Data type: `Redis::SentinelMonitor` -The password to use to authenticate with the master and slaves. +Specify the sentinel monitor. -Default value: `undef` +Default value: $redis::params::sentinel_monitor ##### `config_file` @@ -1036,32 +1050,6 @@ Define which template to use. Default value: 'redis/redis-sentinel.conf.erb' -##### `daemonize` - -Data type: `Boolean` - -Have Redis sentinel run as a daemon. - -Default value: $redis::params::sentinel_daemonize - -##### `down_after` - -Data type: `Integer[1]` - -Number of milliseconds the master (or any attached slave or sentinel) -should be unreachable (as in, not acceptable reply to PING, continuously, -for the specified period) in order to consider it in S_DOWN state. - -Default value: 30000 - -##### `failover_timeout` - -Data type: `Integer[1]` - -Specify the failover timeout in milliseconds. - -Default value: 180000 - ##### `init_script` Data type: `Optional[Stdlib::Absolutepath]` @@ -1088,29 +1076,9 @@ Default value: 'notice' ##### `master_name` -Data type: `String[1]` - Specify the name of the master redis server. The valid charset is A-z 0-9 and the three characters ".-_". -Default value: 'mymaster' - -##### `redis_host` - -Data type: `Stdlib::Host` - -Specify the bound host of the master redis server. - -Default value: '127.0.0.1' - -##### `redis_port` - -Data type: `Stdlib::Port` - -Specify the port of the master redis server. - -Default value: 6379 - ##### `package_name` Data type: `String[1]` @@ -1127,15 +1095,6 @@ Do we ensure this package. Default value: 'present' -##### `parallel_sync` - -Data type: `Integer[0]` - -How many slaves can be reconfigured at the same time to use a -new master after a failover. - -Default value: 1 - ##### `pid_file` Data type: `Stdlib::Absolutepath` @@ -1144,15 +1103,6 @@ If sentinel is daemonized it will write its pid at this location. Default value: $redis::params::sentinel_pid_file -##### `quorum` - -Data type: `Integer[1]` - -Number of sentinels that must agree that a master is down to -signal sdown state. - -Default value: 2 - ##### `sentinel_bind` Data type: `Variant[Undef, Stdlib::IP::Address, Array[Stdlib::IP::Address]]` @@ -1211,21 +1161,13 @@ conflicts. Default value: $redis::params::sentinel_working_dir -##### `notification_script` - -Data type: `Optional[Stdlib::Absolutepath]` - -Path to the notification script - -Default value: `undef` +##### `daemonize` -##### `client_reconfig_script` +Data type: `Boolean` -Data type: `Optional[Stdlib::Absolutepath]` -Path to the client-reconfig script -Default value: `undef` +Default value: $redis::params::sentinel_daemonize ##### `init_template` @@ -1235,6 +1177,14 @@ Data type: `String[1]` Default value: 'redis/redis-sentinel.init.erb' +##### `parallel_sync` + +Data type: `Integer[0]` + + + +Default value: 1 + ##### `service_ensure` Data type: `Stdlib::Ensure::Service` @@ -2072,6 +2022,23 @@ The Redis::RedisUrl data type. Alias of `Pattern[/(^redis:\/\/)/]` +### Redis::SentinelMonitor + +The Redis::SentinelMonitor data type. + +Alias of `Hash[String, Struct[{ + redis_host => Stdlib::Host, + redis_port => Stdlib::Port, + quorum => Integer[1], + down_after => Integer[1], + parallel_sync => Integer[0], + failover_timeout => Integer[1], + monitor_name => Optional[String], + auth_pass => Optional[String], + notification_script => Optional[Stdlib::Absolutepath], + client_reconfig_script => Optional[Stdlib::Absolutepath], +}]]` + ## Tasks ### redis_cli diff --git a/manifests/params.pp b/manifests/params.pp index 08b0547b..a41b4477 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -201,7 +201,7 @@ } } - $sentinel_master_name = { + $sentinel_monitor = [ 'mymaster' => { redis_host => '127.0.0.1', redis_port => 6379, @@ -212,6 +212,6 @@ auth_pass => undef, notification_script => undef, client_reconfig_script => undef, - }, - } + } + ] } diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index f4cb7e6e..8255c914 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -1,42 +1,7 @@ # @summary Install redis-sentinel # -# @param master_name -# Specify the name of the master redis server. -# The valid charset is A-z 0-9 and the three characters ".-_". -# Hash with following Keys: -# @key auth_pass -# The password to use to authenticate with the master and slaves. -# -# @key redis_host -# Specify the bound host of the master redis server. -# -# @key redis_port -# Specify the port of the master redis server. -# -# @key daemonize -# Have Redis sentinel run as a daemon. -# -# @key down_after -# Number of milliseconds the master (or any attached slave or sentinel) -# should be unreachable (as in, not acceptable reply to PING, continuously, -# for the specified period) in order to consider it in S_DOWN state. -# -# @key failover_timeout -# Specify the failover timeout in milliseconds. -# -# @key parallel_sync -# How many slaves can be reconfigured at the same time to use a -# new master after a failover. -# -# @key quorum -# Number of sentinels that must agree that a master is down to -# signal sdown state. -# -# @key notification_script -# Path to the notification script -# -# @key client_reconfig_script -# Path to the client-reconfig script +# @param sentinel_monitor +# Specify the sentinel monitor. # # @param config_file # The location and name of the sentinel config file. @@ -99,9 +64,6 @@ # The directory into which sentinel will change to avoid mount # conflicts. # -# @example Basic inclusion -# include redis::sentinel -# # @example Configuring options # class {'redis::sentinel': # log_file => '/var/log/redis/sentinel.log', @@ -128,28 +90,28 @@ # } # class redis::sentinel ( - Stdlib::Absolutepath $config_file = $redis::params::sentinel_config_file, - Stdlib::Absolutepath $config_file_orig = $redis::params::sentinel_config_file_orig, - Stdlib::Filemode $config_file_mode = '0644', - String[1] $conf_template = 'redis/redis-sentinel.conf.erb', - Boolean $daemonize = $redis::params::sentinel_daemonize, + Stdlib::Absolutepath $config_file = $redis::params::sentinel_config_file, + Stdlib::Absolutepath $config_file_orig = $redis::params::sentinel_config_file_orig, + Stdlib::Filemode $config_file_mode = '0644', + String[1] $conf_template = 'redis/redis-sentinel.conf.erb', + Boolean $daemonize = $redis::params::sentinel_daemonize, Optional[Stdlib::Absolutepath] $init_script = $redis::params::sentinel_init_script, - String[1] $init_template = 'redis/redis-sentinel.init.erb', - Redis::LogLevel $log_level = 'notice', - Stdlib::Absolutepath $log_file = $redis::params::sentinel_log_file, - Redis::MasterName $master_name = $redis::params::sentinel_master_name, - String[1] $package_name = $redis::params::sentinel_package_name, - String[1] $package_ensure = 'present', - Integer[0] $parallel_sync = 1, - Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, + String[1] $init_template = 'redis/redis-sentinel.init.erb', + Redis::LogLevel $log_level = 'notice', + Stdlib::Absolutepath $log_file = $redis::params::sentinel_log_file, + Redis::SentinelMonitor $sentinel_monitor = $redis::params::sentinel_monitor, + String[1] $package_name = $redis::params::sentinel_package_name, + String[1] $package_ensure = 'present', + Integer[0] $parallel_sync = 1, + Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, + Stdlib::Port $sentinel_port = 26379, + String[1] $service_group = 'redis', + String[1] $service_name = $redis::params::sentinel_service_name, + Stdlib::Ensure::Service $service_ensure = 'running', + Boolean $service_enable = true, + String[1] $service_user = 'redis', + Stdlib::Absolutepath $working_dir = $redis::params::sentinel_working_dir, Variant[Undef, Stdlib::IP::Address, Array[Stdlib::IP::Address]] $sentinel_bind = undef, - Stdlib::Port $sentinel_port = 26379, - String[1] $service_group = 'redis', - String[1] $service_name = $redis::params::sentinel_service_name, - Stdlib::Ensure::Service $service_ensure = 'running', - Boolean $service_enable = true, - String[1] $service_user = 'redis', - Stdlib::Absolutepath $working_dir = $redis::params::sentinel_working_dir, ) inherits redis::params { require 'redis' @@ -181,21 +143,22 @@ content => template('redis/sentinel/redis-sentinel.conf_header.erb'), } - $master_name.each |String $master, Hash $params| { - concat::fragment { "sentinel_conf_master_${master}" : + $sentinel_monitor.each |$monitor,$values| { + $redis_values = merge($values,{'monitor_name' => $monitor}) + concat::fragment { "sentinel_conf_master_${monitor}" : target => $config_file_orig, order => 20, content => epp('redis/sentinel/redis-sentinel.conf_master.epp', { - master_name => $master, - redis_host => $params['redis_host'], - redis_port => $params['redis_port'], - quorum => $params['quorum'], - down_after => $params['down_after'], - parallel_sync => $params['parallel_sync'], - failover_timeout => $params['failover_timeout'], - auth_pass => $params['auth_pass'], - notification_script => $params['notification_script'], - client_reconfig_script => $params['client_reconfig_script'], + monitor_name => $redis_values['monitor_name'], + redis_host => $redis_values['redis_host'], + redis_port => $redis_values['redis_port'], + quorum => $redis_values['quorum'], + down_after => $redis_values['down_after'], + parallel_sync => $redis_values['parallel_sync'], + failover_timeout => $redis_values['failover_timeout'], + auth_pass => $redis_values['auth_pass'], + notification_script => $redis_values['notification_script'], + client_reconfig_script => $redis_values['client_reconfig_script'], }), } } diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index 10a927e0..277242f5 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -11,19 +11,9 @@ it 'runs successfully' do pp = <<-EOS class { 'redis::sentinel': - master_name => { - 'mymaster' => { - redis_host => '127.0.0.1', - redis_port => 6379, - quorum => 2, - parallel_sync => 1, - down_after => 30000, - failover_timeout => 180000, - auth_pass => 'mymastertest', - notification_script => '/path/to/bar.sh', - client_reconfig_script => '/path/to/foo.sh', - }, - }, + master_name => 'mymaster', + redis_host => '127.0.0.1', + failover_timeout => 10000, } EOS diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 9693b71f..f906e4d1 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -73,22 +73,15 @@ describe 'with custom parameters' do let(:params) do { - master_name: { - 'cow' => { - 'redis_host' => '127.0.0.1', - 'redis_port' => 6379, - 'quorum' => 2, - 'parallel_sync' => 1, - 'auth_pass' => 'password', - 'down_after' => 6000, - 'failover_timeout' => 28_000, - 'notification_script' => '/path/to/bar.sh', - 'client_reconfig_script' => '/path/to/foo.sh' - } - }, + auth_pass: 'password', sentinel_bind: '192.0.2.10', + master_name: 'cow', + down_after: 6000, working_dir: '/tmp/redis', - log_file: '/tmp/barn-sentinel.log' + log_file: '/tmp/barn-sentinel.log', + failover_timeout: 28_000, + notification_script: '/path/to/bar.sh', + client_reconfig_script: '/path/to/foo.sh' } end diff --git a/templates/sentinel/redis-sentinel.conf_master.epp b/templates/sentinel/redis-sentinel.conf_master.epp index fcc019aa..3996bafd 100644 --- a/templates/sentinel/redis-sentinel.conf_master.epp +++ b/templates/sentinel/redis-sentinel.conf_master.epp @@ -1,5 +1,5 @@ <%- | - $master_name, + $monitor_name, $redis_host, $redis_port, $quorum, @@ -11,16 +11,16 @@ $client_reconfig_script, | -%> -sentinel monitor <%= $master_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> -sentinel down-after-milliseconds <%= $master_name %> <%= $down_after %> -sentinel parallel-syncs <%= $master_name %> <%= $parallel_sync %> -sentinel failover-timeout <%= $master_name %> <%= $failover_timeout %> +sentinel monitor <%= $monitor_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> +sentinel down-after-milliseconds <%= $monitor_name %> <%= $down_after %> +sentinel parallel-syncs <%= $monitor_name %> <%= $parallel_sync %> +sentinel failover-timeout <%= $monitor_name %> <%= $failover_timeout %> <% if $auth_pass { -%> -sentinel auth-pass <%= $master_name %> <%= $auth_pass %> +sentinel auth-pass <%= $monitor_name %> <%= $auth_pass %> <% } -%> <% if $notification_script { -%> -sentinel notification-script <%= $master_name %> <%= $notification_script %> +sentinel notification-script <%= $monitor_name %> <%= $notification_script %> <% } -%> <% if $client_reconfig_script { -%> -sentinel client-reconfig-script <%= $master_name %> <%= $client_reconfig_script %> +sentinel client-reconfig-script <%= $monitor_name %> <%= $client_reconfig_script %> <% } -%> diff --git a/types/mastername.pp b/types/mastername.pp deleted file mode 100644 index edf35b7e..00000000 --- a/types/mastername.pp +++ /dev/null @@ -1,11 +0,0 @@ -type Redis::MasterName = Hash[String, Struct[{ - redis_host => Stdlib::Host, - redis_port => Stdlib::Port, - quorum => Integer[1], - down_after => Integer[1], - parallel_sync => Integer[0], - failover_timeout => Integer[1], - Optional[auth_pass] => String, - Optional[notification_script] => Stdlib::Absolutepath, - Optional[client_reconfig_script] => Stdlib::Absolutepath,} -],1] diff --git a/types/sentinelmonitor.pp b/types/sentinelmonitor.pp new file mode 100644 index 00000000..1f66d9d6 --- /dev/null +++ b/types/sentinelmonitor.pp @@ -0,0 +1,12 @@ +type Redis::SentinelMonitor = Hash[String,Struct[{ + redis_host => Stdlib::Host, + redis_port => Stdlib::Port, + quorum => Integer[1], + down_after => Integer[1], + parallel_sync => Integer[0], + failover_timeout => Integer[1], + monitor_name => Optional[String], + auth_pass => Optional[String], + notification_script => Optional[Stdlib::Absolutepath], + client_reconfig_script => Optional[Stdlib::Absolutepath], +}]] From c09d1ff1f5eef447b2366b994187490b8eeceb00 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 6 May 2020 13:05:06 +0200 Subject: [PATCH 14/46] catch basic inclusion, dunno why it was run away --- REFERENCE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index 6af46a26..8bba595e 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -974,6 +974,12 @@ Install redis-sentinel #### Examples +##### Basic inclusion + +```puppet +include redis::sentinel +``` + ##### Configuring options ```puppet From d5482b4dfa9e78be76c3f804eb47d64b5a52db64 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 6 May 2020 13:27:00 +0200 Subject: [PATCH 15/46] confused about puppet strings --- README.md | 13 ++++-- REFERENCE.md | 18 ++------ manifests/params.pp | 6 +-- manifests/sentinel.pp | 13 ++---- .../default/redis_sentinel_one_node_spec.rb | 16 +++++-- spec/classes/redis_sentinel_spec.rb | 45 ++++++++++++++++--- 6 files changed, 72 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 77fecab4..9884b114 100644 --- a/README.md +++ b/README.md @@ -125,9 +125,16 @@ With adjustments: ```puppet class { '::redis::sentinel': - master_name => 'cow', - redis_host => '192.168.1.5', - failover_timeout => 30000, + sentinel_monitor => { + 'cow' => { + 'redis_host' => '192.168.1.5', + 'redis_port' => 6379, + 'quorum' => 2, + 'parallel_sync' => 1, + 'down_after' => 6000, + 'failover_timeout' => 30000, + }, + }, } ``` diff --git a/REFERENCE.md b/REFERENCE.md index 8bba595e..3407b7dc 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -974,19 +974,13 @@ Install redis-sentinel #### Examples -##### Basic inclusion - -```puppet -include redis::sentinel -``` - ##### Configuring options ```puppet class {'redis::sentinel': log_file => '/var/log/redis/sentinel.log', - master_name => { - 'session_6381' => { + sentinel_monitor => { + 'session' => { redis_host => $redis_master_ip, redis_port => 6381, quorum => 2, @@ -995,7 +989,7 @@ class {'redis::sentinel': failover_timeout => 12000, auth_pass => $redis_auth, }, - 'cache_6380' => { + 'cache' => { redis_host => $redis_master_ip, redis_port => 6380, quorum => 2, @@ -1005,7 +999,6 @@ class {'redis::sentinel': auth_pass => $redis_auth, } } -} ``` #### Parameters @@ -1080,11 +1073,6 @@ Specify how much we should log. Default value: 'notice' -##### `master_name` - -Specify the name of the master redis server. -The valid charset is A-z 0-9 and the three characters ".-_". - ##### `package_name` Data type: `String[1]` diff --git a/manifests/params.pp b/manifests/params.pp index a41b4477..87c97a4c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -201,7 +201,7 @@ } } - $sentinel_monitor = [ + $sentinel_monitor = { 'mymaster' => { redis_host => '127.0.0.1', redis_port => 6379, @@ -212,6 +212,6 @@ auth_pass => undef, notification_script => undef, client_reconfig_script => undef, - } - ] + }, + } } diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 8255c914..3299ea65 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -28,10 +28,6 @@ # @param log_level # Specify how much we should log. # -# @param master_name -# Specify the name of the master redis server. -# The valid charset is A-z 0-9 and the three characters ".-_". -# # @param package_name # The name of the package that installs sentinel. # @@ -67,8 +63,8 @@ # @example Configuring options # class {'redis::sentinel': # log_file => '/var/log/redis/sentinel.log', -# master_name => { -# 'session_6381' => { +# sentinel_monitor => { +# 'session' => { # redis_host => $redis_master_ip, # redis_port => 6381, # quorum => 2, @@ -77,7 +73,7 @@ # failover_timeout => 12000, # auth_pass => $redis_auth, # }, -# 'cache_6380' => { +# 'cache' => { # redis_host => $redis_master_ip, # redis_port => 6380, # quorum => 2, @@ -85,9 +81,8 @@ # down_after => 5000, # failover_timeout => 12000, # auth_pass => $redis_auth, -# } +# }, # } -# } # class redis::sentinel ( Stdlib::Absolutepath $config_file = $redis::params::sentinel_config_file, diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index 277242f5..7c2e0c51 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -11,9 +11,19 @@ it 'runs successfully' do pp = <<-EOS class { 'redis::sentinel': - master_name => 'mymaster', - redis_host => '127.0.0.1', - failover_timeout => 10000, + sentinel_monitor => { + 'mymaster' => { + redis_host => '127.0.0.1', + redis_port => 6379, + quorum => 2, + parallel_sync => 1, + down_after => 30000, + failover_timeout => 180000, + auth_pass => 'mymastertest', + notification_script => '/path/to/bar.sh', + client_reconfig_script => '/path/to/foo.sh', + }, + }, } EOS diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index f906e4d1..c12115ba 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -73,18 +73,51 @@ describe 'with custom parameters' do let(:params) do { - auth_pass: 'password', + sentinel_monitor: { + 'cow' => { + 'redis_host' => '127.0.0.1', + 'redis_port' => 6379, + 'quorum' => 2, + 'parallel_sync' => 1, + 'auth_pass' => 'password', + 'down_after' => 6000, + 'failover_timeout' => 28_000, + 'notification_script' => '/path/to/bar.sh', + 'client_reconfig_script' => '/path/to/foo.sh' + }, + }, sentinel_bind: '192.0.2.10', - master_name: 'cow', - down_after: 6000, working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log', - failover_timeout: 28_000, - notification_script: '/path/to/bar.sh', - client_reconfig_script: '/path/to/foo.sh' } end + +# @example Configuring options +# class {'redis::sentinel': +# log_file => '/var/log/redis/sentinel.log', +# sentinel_monitor => { +# 'session' => { +# redis_host => $redis_master_ip, +# redis_port => 6381, +# quorum => 2, +# parallel_sync => 1, +# down_after => 5000, +# failover_timeout => 12000, +# auth_pass => $redis_auth, +# }, +# 'cache' => { +# redis_host => $redis_master_ip, +# redis_port => 6380, +# quorum => 2, +# parallel_sync => 1, +# down_after => 5000, +# failover_timeout => 12000, +# auth_pass => $redis_auth, +# }, +# } + + let(:expected_content) do < Date: Wed, 6 May 2020 17:40:46 +0200 Subject: [PATCH 16/46] finishing sentinel instance monitor adding dependencies / update rspec / new variable name / !!!BREAKING CHANGE --- .fixtures.yml | 1 + manifests/params.pp | 3 - manifests/sentinel.pp | 4 +- metadata.json | 4 + spec/classes/redis_sentinel_spec.rb | 85 +++++++++---------- .../sentinel/redis-sentinel.conf_monitor.epp | 26 ++++++ 6 files changed, 71 insertions(+), 52 deletions(-) create mode 100644 templates/sentinel/redis-sentinel.conf_monitor.epp diff --git a/.fixtures.yml b/.fixtures.yml index cd920aa8..ee9a025e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,6 +5,7 @@ fixtures: epel: 'https://github.com/voxpupuli/puppet-epel.git' augeasproviders_sysctl: 'https://github.com/hercules-team/augeasproviders_sysctl.git' augeasproviders_core: 'https://github.com/hercules-team/augeasproviders_core.git' + concat: 'https://github.com/puppetlabs/puppetlabs-concat' augeas_core: repo: "https://github.com/puppetlabs/puppetlabs-augeas_core" puppet_version: ">= 6.0.0" diff --git a/manifests/params.pp b/manifests/params.pp index 87c97a4c..af18d335 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -209,9 +209,6 @@ down_after => 30000, parallel_sync => 1, failover_timeout => 180000, - auth_pass => undef, - notification_script => undef, - client_reconfig_script => undef, }, } } diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 3299ea65..556220d3 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -140,10 +140,10 @@ $sentinel_monitor.each |$monitor,$values| { $redis_values = merge($values,{'monitor_name' => $monitor}) - concat::fragment { "sentinel_conf_master_${monitor}" : + concat::fragment { "sentinel_conf_monitor_${monitor}" : target => $config_file_orig, order => 20, - content => epp('redis/sentinel/redis-sentinel.conf_master.epp', { + content => epp('redis/sentinel/redis-sentinel.conf_monitor.epp', { monitor_name => $redis_values['monitor_name'], redis_host => $redis_values['redis_host'], redis_port => $redis_values['redis_port'], diff --git a/metadata.json b/metadata.json index 827949d4..59272b1f 100644 --- a/metadata.json +++ b/metadata.json @@ -27,6 +27,10 @@ { "name": "herculesteam/augeasproviders_core", "version_requirement": ">= 2.1.0 < 3.0.0" + }, + { + "name": "puppetlabs/concat", + "version_requirement": ">= 5.0.0 < 6.2.0" } ], "description": "Redis module with cluster support", diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index c12115ba..3b78b792 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -30,17 +30,27 @@ end describe 'without parameters' do - let(:expected_content) do + let(:expected_content_header) do < { + 'mymaster' => { 'redis_host' => '127.0.0.1', 'redis_port' => 6379, 'quorum' => 2, @@ -84,55 +89,39 @@ 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', 'client_reconfig_script' => '/path/to/foo.sh' - }, + } }, sentinel_bind: '192.0.2.10', working_dir: '/tmp/redis', - log_file: '/tmp/barn-sentinel.log', + log_file: '/tmp/barn-sentinel.log' } end - -# @example Configuring options -# class {'redis::sentinel': -# log_file => '/var/log/redis/sentinel.log', -# sentinel_monitor => { -# 'session' => { -# redis_host => $redis_master_ip, -# redis_port => 6381, -# quorum => 2, -# parallel_sync => 1, -# down_after => 5000, -# failover_timeout => 12000, -# auth_pass => $redis_auth, -# }, -# 'cache' => { -# redis_host => $redis_master_ip, -# redis_port => 6380, -# quorum => 2, -# parallel_sync => 1, -# down_after => 5000, -# failover_timeout => 12000, -# auth_pass => $redis_auth, -# }, -# } - - - let(:expected_content) do + let(:expected_content_header) do < + +sentinel monitor <%= $monitor_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> +sentinel down-after-milliseconds <%= $monitor_name %> <%= $down_after %> +sentinel parallel-syncs <%= $monitor_name %> <%= $parallel_sync %> +sentinel failover-timeout <%= $monitor_name %> <%= $failover_timeout %> +<% if $auth_pass { -%> +sentinel auth-pass <%= $monitor_name %> <%= $auth_pass %> +<% } -%> +<% if $notification_script { -%> +sentinel notification-script <%= $monitor_name %> <%= $notification_script %> +<% } -%> +<% if $client_reconfig_script { -%> +sentinel client-reconfig-script <%= $monitor_name %> <%= $client_reconfig_script %> +<% } -%> From 784685661a714f0f32d462ed9fa8e938acdf7b7b Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 6 May 2020 17:42:45 +0200 Subject: [PATCH 17/46] fix intending --- manifests/params.pp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index af18d335..69bc88be 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -202,13 +202,13 @@ } $sentinel_monitor = { - 'mymaster' => { - redis_host => '127.0.0.1', - redis_port => 6379, - quorum => 2, - down_after => 30000, - parallel_sync => 1, - failover_timeout => 180000, - }, - } + 'mymaster' => { + redis_host => '127.0.0.1', + redis_port => 6379, + quorum => 2, + down_after => 30000, + parallel_sync => 1, + failover_timeout => 180000, + }, + } } From 7f53eb9a7cc733f44f06b661de002ea932e86ba0 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 6 May 2020 17:58:23 +0200 Subject: [PATCH 18/46] Delete redis-sentinel.conf_master.epp --- .../sentinel/redis-sentinel.conf_master.epp | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 templates/sentinel/redis-sentinel.conf_master.epp diff --git a/templates/sentinel/redis-sentinel.conf_master.epp b/templates/sentinel/redis-sentinel.conf_master.epp deleted file mode 100644 index 3996bafd..00000000 --- a/templates/sentinel/redis-sentinel.conf_master.epp +++ /dev/null @@ -1,26 +0,0 @@ -<%- | - $monitor_name, - $redis_host, - $redis_port, - $quorum, - $down_after, - $parallel_sync, - $failover_timeout, - $auth_pass, - $notification_script, - $client_reconfig_script, -| -%> - -sentinel monitor <%= $monitor_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> -sentinel down-after-milliseconds <%= $monitor_name %> <%= $down_after %> -sentinel parallel-syncs <%= $monitor_name %> <%= $parallel_sync %> -sentinel failover-timeout <%= $monitor_name %> <%= $failover_timeout %> -<% if $auth_pass { -%> -sentinel auth-pass <%= $monitor_name %> <%= $auth_pass %> -<% } -%> -<% if $notification_script { -%> -sentinel notification-script <%= $monitor_name %> <%= $notification_script %> -<% } -%> -<% if $client_reconfig_script { -%> -sentinel client-reconfig-script <%= $monitor_name %> <%= $client_reconfig_script %> -<% } -%> From 2bc9ccffccb7c1119a09709b25a58301cf2af27c Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 6 May 2020 18:24:30 +0200 Subject: [PATCH 19/46] fix acceptance check --- .../suites/default/redis_sentinel_one_node_spec.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index 7c2e0c51..62496358 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -18,10 +18,7 @@ class { 'redis::sentinel': quorum => 2, parallel_sync => 1, down_after => 30000, - failover_timeout => 180000, - auth_pass => 'mymastertest', - notification_script => '/path/to/bar.sh', - client_reconfig_script => '/path/to/foo.sh', + failover_timeout => 10000, }, }, } From 041ba164a941239944c85458b2442de0a8f7b46a Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Thu, 7 May 2020 15:25:18 +0200 Subject: [PATCH 20/46] defaults, merge fix create monitor defaults, default values should be overriden by fiven values --- manifests/params.pp | 19 ++++++++++--------- manifests/sentinel.pp | 11 ++++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 69bc88be..4cd7c462 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -201,14 +201,15 @@ } } - $sentinel_monitor = { - 'mymaster' => { - redis_host => '127.0.0.1', - redis_port => 6379, - quorum => 2, - down_after => 30000, - parallel_sync => 1, - failover_timeout => 180000, - }, + $sentinel_monitor_defaults = { + redis_host => '127.0.0.1', + redis_port => 6379, + quorum => 2, + down_after => 30000, + parallel_sync => 1, + failover_timeout => 180000, + } + $sentinel_default_monitor = { + 'mymaster' => $sentinel_monitor_defaults } } diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 556220d3..b30e6e87 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -3,6 +3,9 @@ # @param sentinel_monitor # Specify the sentinel monitor. # +# @param monitor_defaults +# Override the monitor defaults +# # @param config_file # The location and name of the sentinel config file. # @@ -81,7 +84,7 @@ # down_after => 5000, # failover_timeout => 12000, # auth_pass => $redis_auth, -# }, +# } # } # class redis::sentinel ( @@ -94,7 +97,8 @@ String[1] $init_template = 'redis/redis-sentinel.init.erb', Redis::LogLevel $log_level = 'notice', Stdlib::Absolutepath $log_file = $redis::params::sentinel_log_file, - Redis::SentinelMonitor $sentinel_monitor = $redis::params::sentinel_monitor, + Redis::SentinelMonitor $sentinel_monitor = $redis::params::sentinel_default_monitor, + $monitor_defaults = $redis::params::sentinel_monitor_defaults, String[1] $package_name = $redis::params::sentinel_package_name, String[1] $package_ensure = 'present', Integer[0] $parallel_sync = 1, @@ -139,7 +143,8 @@ } $sentinel_monitor.each |$monitor,$values| { - $redis_values = merge($values,{'monitor_name' => $monitor}) + $_monitor = merge($monitor_defaults,$values) + $redis_values = merge({'monitor_name' => $monitor},$_monitor) concat::fragment { "sentinel_conf_monitor_${monitor}" : target => $config_file_orig, order => 20, From b368f80d4e2e7b181b81601b63b5938e07742398 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Thu, 7 May 2020 15:29:34 +0200 Subject: [PATCH 21/46] fix trailing comma manifests/params.pp:213:trailing_comma:WARNING:missing trailing comma after last element --- manifests/params.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/params.pp b/manifests/params.pp index 4cd7c462..a2d1382d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -210,6 +210,6 @@ failover_timeout => 180000, } $sentinel_default_monitor = { - 'mymaster' => $sentinel_monitor_defaults + 'mymaster' => $sentinel_monitor_defaults, } } From 38d19eb80caa2c007feb2b1836993fa9f062063a Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Thu, 4 Jun 2020 19:41:32 +0200 Subject: [PATCH 22/46] some improvements suggested from ekohl --- manifests/params.pp | 3 +++ manifests/sentinel.pp | 24 +++++------------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index a2d1382d..e784c65d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -208,6 +208,9 @@ down_after => 30000, parallel_sync => 1, failover_timeout => 180000, + auth_pass => false, + notification_script => false, + client_reconfig_script => false, } $sentinel_default_monitor = { 'mymaster' => $sentinel_monitor_defaults, diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index b30e6e87..fe9659a0 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -65,7 +65,7 @@ # # @example Configuring options # class {'redis::sentinel': -# log_file => '/var/log/redis/sentinel.log', +# log_file => '/var/log/redis/sentinel.log', # sentinel_monitor => { # 'session' => { # redis_host => $redis_master_ip, @@ -126,14 +126,11 @@ } } - Concat { - owner => $service_user, - group => $service_group, - mode => $config_file_mode, - } - concat { $config_file_orig: ensure => present, + owner => $service_user, + group => $service_group, + mode => $config_file_mode, } concat::fragment { 'sentinel_conf_header': @@ -148,18 +145,7 @@ concat::fragment { "sentinel_conf_monitor_${monitor}" : target => $config_file_orig, order => 20, - content => epp('redis/sentinel/redis-sentinel.conf_monitor.epp', { - monitor_name => $redis_values['monitor_name'], - redis_host => $redis_values['redis_host'], - redis_port => $redis_values['redis_port'], - quorum => $redis_values['quorum'], - down_after => $redis_values['down_after'], - parallel_sync => $redis_values['parallel_sync'], - failover_timeout => $redis_values['failover_timeout'], - auth_pass => $redis_values['auth_pass'], - notification_script => $redis_values['notification_script'], - client_reconfig_script => $redis_values['client_reconfig_script'], - }), + content => epp('redis/sentinel/redis-sentinel.conf_monitor.epp', $redis_values) } } From b2e1a9e8ddef3cf2559beb5a7cb8d6562a934ae7 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Thu, 4 Jun 2020 19:50:56 +0200 Subject: [PATCH 23/46] fix trailing comma --- manifests/sentinel.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index fe9659a0..59b80588 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -145,7 +145,7 @@ concat::fragment { "sentinel_conf_monitor_${monitor}" : target => $config_file_orig, order => 20, - content => epp('redis/sentinel/redis-sentinel.conf_monitor.epp', $redis_values) + content => epp('redis/sentinel/redis-sentinel.conf_monitor.epp', $redis_values), } } From 9d601847b94928321fd087efda7e6e2d9234e7c0 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Thu, 4 Jun 2020 20:05:34 +0200 Subject: [PATCH 24/46] fix defaults gett'n late over here --- manifests/params.pp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index e784c65d..7200fa0a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -208,9 +208,9 @@ down_after => 30000, parallel_sync => 1, failover_timeout => 180000, - auth_pass => false, - notification_script => false, - client_reconfig_script => false, + auth_pass => undef, + notification_script => undef, + client_reconfig_script => undef, } $sentinel_default_monitor = { 'mymaster' => $sentinel_monitor_defaults, From b36cc117af8900551e003fd4418113202b1b6f5b Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 17:50:22 +0100 Subject: [PATCH 25/46] remove concat --- manifests/sentinel.pp | 37 +++++-------------- templates/redis-sentinel.conf.erb | 26 +++++++++++++ .../sentinel/redis-sentinel.conf_footer.erb | 3 -- .../sentinel/redis-sentinel.conf_header.erb | 7 ---- .../sentinel/redis-sentinel.conf_monitor.epp | 26 ------------- 5 files changed, 36 insertions(+), 63 deletions(-) create mode 100644 templates/redis-sentinel.conf.erb delete mode 100644 templates/sentinel/redis-sentinel.conf_footer.erb delete mode 100644 templates/sentinel/redis-sentinel.conf_header.erb delete mode 100644 templates/sentinel/redis-sentinel.conf_monitor.epp diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 59b80588..34b0140a 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -118,7 +118,7 @@ if $facts['os']['family'] == 'Debian' { package { $package_name: ensure => $package_ensure, - before => Concat[$config_file_orig], + before => File[$config_file_orig], } if $init_script { @@ -126,38 +126,21 @@ } } - concat { $config_file_orig: - ensure => present, - owner => $service_user, - group => $service_group, - mode => $config_file_mode, + $_monitor = $sentinel_monitor.map |$monitor,$values| { + $redis_values = $monitor_defaults + {'monitor_name' => $monitor} + $values } - concat::fragment { 'sentinel_conf_header': - target => $config_file_orig, - order => 10, - content => template('redis/sentinel/redis-sentinel.conf_header.erb'), - } - - $sentinel_monitor.each |$monitor,$values| { - $_monitor = merge($monitor_defaults,$values) - $redis_values = merge({'monitor_name' => $monitor},$_monitor) - concat::fragment { "sentinel_conf_monitor_${monitor}" : - target => $config_file_orig, - order => 20, - content => epp('redis/sentinel/redis-sentinel.conf_monitor.epp', $redis_values), - } - } - - concat::fragment { 'sentinel_conf_footer': - target => $config_file_orig, - order => 30, - content => template('redis/sentinel/redis-sentinel.conf_footer.erb'), + file { $config_file_orig: + ensure => present, + owner => $service_user, + group => $service_group, + mode => $config_file_mode, + content => template('redis/redis-sentinel.conf.erb'), } exec { "cp -p ${config_file_orig} ${config_file}": path => '/usr/bin:/bin', - subscribe => Concat[$config_file_orig], + subscribe => File[$config_file_orig], notify => Service[$service_name], refreshonly => true, } diff --git a/templates/redis-sentinel.conf.erb b/templates/redis-sentinel.conf.erb new file mode 100644 index 00000000..236898f8 --- /dev/null +++ b/templates/redis-sentinel.conf.erb @@ -0,0 +1,26 @@ +<% if @sentinel_bind -%> +bind <%= @sentinel_bind %> +<% end -%> +port <%= @sentinel_port %> +dir <%= @working_dir %> +daemonize <%= @daemonize ? 'yes' : 'no' %> +pidfile <%= @pid_file %> + +<% @_monitor.each do |values| -%> +sentinel monitor <%= values['monitor_name'] %> <%= values['redis_host'] %> <%= values['redis_port'] %> <%= values['quorum'] %> +sentinel down-after-milliseconds <%= values['monitor_name'] %> <%= values['down_after'] %> +sentinel parallel-syncs <%= values['monitor_name'] %> <%= values['parallel_sync'] %> +sentinel failover-timeout <%= values['monitor_name'] %> <%= values['failover_timeout'] %> +<% if values['auth_pass'] -%> +sentinel auth-pass <%= values['monitor_name'] %> <%= values['auth_pass'] %> +<% end -%> +<% if values['notification_script'] -%> +sentinel notification-script <%= values['monitor_name'] %> <%= values['notification_script'] %> +<% end -%> +<% if values['client_reconfig_script'] -%> +sentinel client-reconfig-script <%= values['monitor_name'] %> <%= values['client_reconfig_script'] %> +<% end %> +<% end -%> + +loglevel <%= @log_level %> +logfile <%= @log_file %> diff --git a/templates/sentinel/redis-sentinel.conf_footer.erb b/templates/sentinel/redis-sentinel.conf_footer.erb deleted file mode 100644 index 65f1ec8e..00000000 --- a/templates/sentinel/redis-sentinel.conf_footer.erb +++ /dev/null @@ -1,3 +0,0 @@ - -loglevel <%= @log_level %> -logfile <%= @log_file %> diff --git a/templates/sentinel/redis-sentinel.conf_header.erb b/templates/sentinel/redis-sentinel.conf_header.erb deleted file mode 100644 index e4049baf..00000000 --- a/templates/sentinel/redis-sentinel.conf_header.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% if @sentinel_bind -%> -bind <%= @sentinel_bind %> -<% end -%> -port <%= @sentinel_port %> -dir <%= @working_dir %> -daemonize <%= @daemonize ? 'yes' : 'no' %> -pidfile <%= @pid_file %> diff --git a/templates/sentinel/redis-sentinel.conf_monitor.epp b/templates/sentinel/redis-sentinel.conf_monitor.epp deleted file mode 100644 index 3996bafd..00000000 --- a/templates/sentinel/redis-sentinel.conf_monitor.epp +++ /dev/null @@ -1,26 +0,0 @@ -<%- | - $monitor_name, - $redis_host, - $redis_port, - $quorum, - $down_after, - $parallel_sync, - $failover_timeout, - $auth_pass, - $notification_script, - $client_reconfig_script, -| -%> - -sentinel monitor <%= $monitor_name %> <%= $redis_host %> <%= $redis_port %> <%= $quorum %> -sentinel down-after-milliseconds <%= $monitor_name %> <%= $down_after %> -sentinel parallel-syncs <%= $monitor_name %> <%= $parallel_sync %> -sentinel failover-timeout <%= $monitor_name %> <%= $failover_timeout %> -<% if $auth_pass { -%> -sentinel auth-pass <%= $monitor_name %> <%= $auth_pass %> -<% } -%> -<% if $notification_script { -%> -sentinel notification-script <%= $monitor_name %> <%= $notification_script %> -<% } -%> -<% if $client_reconfig_script { -%> -sentinel client-reconfig-script <%= $monitor_name %> <%= $client_reconfig_script %> -<% } -%> From 444933edfa2f5b3da4da74ea37282137061050b5 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 18:14:54 +0100 Subject: [PATCH 26/46] adding diffs from master --- manifests/params.pp | 25 +++++---- manifests/sentinel.pp | 6 +++ spec/classes/redis_sentinel_spec.rb | 83 ++++++++++++++++++----------- templates/redis-sentinel.conf.erb | 5 +- 4 files changed, 77 insertions(+), 42 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 7200fa0a..ec93df74 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -25,6 +25,7 @@ $sentinel_package_name = 'redis-sentinel' $sentinel_log_file = '/var/log/redis/redis-sentinel.log' $sentinel_working_dir = '/var/lib/redis' + $sentinel_protected_mode = true case $facts['os']['name'] { 'Ubuntu': { @@ -52,16 +53,17 @@ } 'RedHat': { - $ppa_repo = undef - $daemonize = false - $config_owner = 'redis' - $config_group = 'root' - $config_dir_mode = '0755' - $log_dir_mode = '0750' - - $sentinel_daemonize = false - $sentinel_init_script = undef - $sentinel_working_dir = '/tmp' + $ppa_repo = undef + $daemonize = false + $config_owner = 'redis' + $config_group = 'root' + $config_dir_mode = '0755' + $log_dir_mode = '0750' + + $sentinel_daemonize = false + $sentinel_init_script = undef + $sentinel_working_dir = '/tmp' + $sentinel_protected_mode = true $scl = $redis::globals::scl if $scl { @@ -133,6 +135,7 @@ $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' $sentinel_log_file = '/var/log/redis/sentinel.log' $sentinel_working_dir = '/tmp' + $sentinel_protected_mode = true # pkg version $minimum_version = '3.2.4' @@ -162,6 +165,7 @@ $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' $sentinel_log_file = '/var/log/redis/sentinel.log' $sentinel_working_dir = '/tmp' + $sentinel_protected_mode = true # suse package version $minimum_version = '3.0.5' @@ -192,6 +196,7 @@ $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' $sentinel_log_file = '/var/log/redis/sentinel.log' $sentinel_working_dir = '/tmp' + $sentinel_protected_mode = true # pkg version $minimum_version = '3.2.4' diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 34b0140a..ffcabcdf 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -47,6 +47,9 @@ # @param sentinel_port # The port of sentinel server. # +# @param protected_mode +# Whether protected mode is enabled or not. Only applicable when no bind is set. +# # @param service_group # The group of the config file. # @@ -93,6 +96,7 @@ Stdlib::Filemode $config_file_mode = '0644', String[1] $conf_template = 'redis/redis-sentinel.conf.erb', Boolean $daemonize = $redis::params::sentinel_daemonize, + Boolean $protected_mode = $redis::params::sentinel_protected_mode, Optional[Stdlib::Absolutepath] $init_script = $redis::params::sentinel_init_script, String[1] $init_template = 'redis/redis-sentinel.init.erb', Redis::LogLevel $log_level = 'notice', @@ -126,6 +130,8 @@ } } + $sentinel_bind_arr = delete_undef_values([$sentinel_bind].flatten) + $_monitor = $sentinel_monitor.map |$monitor,$values| { $redis_values = $monitor_defaults + {'monitor_name' => $monitor} + $values } diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 3b78b792..64b151ff 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -30,37 +30,31 @@ end describe 'without parameters' do - let(:expected_content_header) do + let(:expected_content) do < 6000, 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', - 'client_reconfig_script' => '/path/to/foo.sh' + 'client_reconfig_script' => '/path/to/foo.sh', + 'auth_pass' => 'password', } - }, sentinel_bind: '192.0.2.10', + protected_mode: false, working_dir: '/tmp/redis', - log_file: '/tmp/barn-sentinel.log' + log_file: '/tmp/barn-sentinel.log', } end - let(:expected_content_header) do + let(:expected_content) do < -bind <%= @sentinel_bind %> +<% unless @sentinel_bind_arr.empty? -%> +bind <%= @sentinel_bind_arr.join(' ') %> <% end -%> port <%= @sentinel_port %> dir <%= @working_dir %> daemonize <%= @daemonize ? 'yes' : 'no' %> pidfile <%= @pid_file %> +protected-mode <%= @protected_mode ? 'yes' : 'no' %> <% @_monitor.each do |values| -%> sentinel monitor <%= values['monitor_name'] %> <%= values['redis_host'] %> <%= values['redis_port'] %> <%= values['quorum'] %> From e31e45724c0e81c08499fa28803d1653f9f0026f Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 18:22:04 +0100 Subject: [PATCH 27/46] fixing spec --- spec/classes/redis_sentinel_spec.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 64b151ff..928b37dc 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -122,15 +122,22 @@ describe 'with array sentinel bind' do let(:params) do { - auth_pass: 'password', + sentinel_monitor: { + 'cow' => { + 'redis_host' => '127.0.0.1', + 'redis_port' => 6379, + 'quorum' => 2, + 'parallel_sync' => 1, + 'auth_pass' => 'password', + 'down_after' => 6000, + 'failover_timeout' => 28_000, + 'notification_script' => '/path/to/bar.sh', + 'client_reconfig_script' => '/path/to/foo.sh', + 'auth_pass' => 'password', + } sentinel_bind: ['192.0.2.10', '192.168.1.1'], - master_name: 'cow', - down_after: 6000, working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log', - failover_timeout: 28_000, - notification_script: '/path/to/bar.sh', - client_reconfig_script: '/path/to/foo.sh' } end @@ -141,6 +148,7 @@ dir /tmp/redis daemonize #{facts[:osfamily] == 'RedHat' ? 'no' : 'yes'} pidfile #{pidfile} + sentinel monitor cow 127.0.0.1 6379 2 sentinel down-after-milliseconds cow 6000 sentinel parallel-syncs cow 1 @@ -148,6 +156,7 @@ sentinel auth-pass cow password sentinel notification-script cow /path/to/bar.sh sentinel client-reconfig-script cow /path/to/foo.sh + loglevel notice logfile /tmp/barn-sentinel.log CONFIG From bd0ae2ed3def3469d46688b7e00c267fa208276b Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 18:38:38 +0100 Subject: [PATCH 28/46] remove remaining concat code --- .fixtures.yml | 1 - metadata.json | 4 ---- 2 files changed, 5 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index ee9a025e..cd920aa8 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,7 +5,6 @@ fixtures: epel: 'https://github.com/voxpupuli/puppet-epel.git' augeasproviders_sysctl: 'https://github.com/hercules-team/augeasproviders_sysctl.git' augeasproviders_core: 'https://github.com/hercules-team/augeasproviders_core.git' - concat: 'https://github.com/puppetlabs/puppetlabs-concat' augeas_core: repo: "https://github.com/puppetlabs/puppetlabs-augeas_core" puppet_version: ">= 6.0.0" diff --git a/metadata.json b/metadata.json index 20b7c4a4..3bc556db 100644 --- a/metadata.json +++ b/metadata.json @@ -19,10 +19,6 @@ { "name": "herculesteam/augeasproviders_core", "version_requirement": ">= 2.1.0 < 3.0.0" - }, - { - "name": "puppetlabs/concat", - "version_requirement": ">= 5.0.0 < 6.2.0" } ], "description": "Redis module with cluster support", From ad146c9cea378044ee63168ed9be00e232d76fc9 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 19:11:10 +0100 Subject: [PATCH 29/46] readd comments --- manifests/sentinel.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index b090806c..ace9a9c0 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -22,6 +22,9 @@ # @param conf_template # Define which template to use. # +# @param daemonize +# Have Redis sentinel run as a daemon. +# # @param init_script # Specifiy the init script that will be created for sentinel. # @@ -72,6 +75,9 @@ # The directory into which sentinel will change to avoid mount # conflicts. # +# @example Basic inclusion +# include redis::sentinel +# # @example Configuring options # class {'redis::sentinel': # log_file => '/var/log/redis/sentinel.log', From 0bf57f0085fb10675eac94a3fe630f199e2b5c0d Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 19:12:30 +0100 Subject: [PATCH 30/46] double param comment removed --- manifests/sentinel.pp | 3 --- 1 file changed, 3 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index ace9a9c0..2635f4fd 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -56,9 +56,6 @@ # @param sentinel_port # The port of sentinel server. # -# @param protected_mode -# Whether protected mode is enabled or not. Only applicable when no bind is set. -# # @param service_group # The group of the config file. # From dc15fb9e7230cf9ae17d0b02f8de2cdff6eb0fea Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 19:15:30 +0100 Subject: [PATCH 31/46] remove dead parameter --- manifests/sentinel.pp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 2635f4fd..c838392a 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -34,9 +34,6 @@ # @param log_level # Specify how much we should log. # -# @param redis_host -# Specify the bound host of the master redis server. -# # @param protected_mode # Whether protected mode is enabled or not. Only applicable when no bind is set. # @@ -114,7 +111,6 @@ $monitor_defaults = $redis::params::sentinel_monitor_defaults, String[1] $package_name = $redis::params::sentinel_package_name, String[1] $package_ensure = 'present', - Integer[0] $parallel_sync = 1, Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, Stdlib::Port $sentinel_port = 26379, String[1] $service_group = 'redis', From a688036be2215683385dd2933f37ba2941315221 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 19:16:20 +0100 Subject: [PATCH 32/46] revert from ensure => present to file --- manifests/sentinel.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index c838392a..70271e15 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -142,7 +142,7 @@ } file { $config_file_orig: - ensure => present, + ensure => file, owner => $service_user, group => $service_group, mode => $config_file_mode, From 184ccddf2b989ec07dc94f4222225a0539f4b102 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 19:16:44 +0100 Subject: [PATCH 33/46] remove empty row --- manifests/sentinel.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 70271e15..67c98884 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -136,7 +136,6 @@ $sentinel_bind_arr = delete_undef_values([$sentinel_bind].flatten) - $_monitor = $sentinel_monitor.map |$monitor,$values| { $redis_values = $monitor_defaults + {'monitor_name' => $monitor} + $values } From 88434c145b58f209df6ec46d2766ec8e99f5fa4c Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 19:17:54 +0100 Subject: [PATCH 34/46] revert content to $conf_template --- manifests/sentinel.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 67c98884..cb921187 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -145,7 +145,7 @@ owner => $service_user, group => $service_group, mode => $config_file_mode, - content => template('redis/redis-sentinel.conf.erb'), + content => template($conf_template), } exec { "cp -p ${config_file_orig} ${config_file}": From 170269a0d9de7def57fa19b3d4e1e6609c9dfafc Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Mon, 9 Nov 2020 23:47:10 +0100 Subject: [PATCH 35/46] there should be a single space or newline before a closing brace --- manifests/params.pp | 6 +++--- manifests/sentinel.pp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 2237a559..badc37a7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -213,9 +213,9 @@ down_after => 30000, parallel_sync => 1, failover_timeout => 180000, - auth_pass => undef, - notification_script => undef, - client_reconfig_script => undef, + # auth_pass => undef, + # notification_script => undef, + # client_reconfig_script => undef, } $sentinel_default_monitor = { 'mymaster' => $sentinel_monitor_defaults, diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index cb921187..db96a792 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -137,7 +137,7 @@ $sentinel_bind_arr = delete_undef_values([$sentinel_bind].flatten) $_monitor = $sentinel_monitor.map |$monitor,$values| { - $redis_values = $monitor_defaults + {'monitor_name' => $monitor} + $values + $redis_values = $monitor_defaults + { 'monitor_name' => $monitor } + $values } file { $config_file_orig: From 7298967a988a14d01981f484840c0b196df0db27 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 10 Nov 2020 12:12:42 +0100 Subject: [PATCH 36/46] fix unit tests --- .../default/redis_sentinel_one_node_spec.rb | 15 ++++++++------- spec/classes/redis_sentinel_spec.rb | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index 62496358..ef2bbd16 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -12,15 +12,16 @@ pp = <<-EOS class { 'redis::sentinel': sentinel_monitor => { - 'mymaster' => { - redis_host => '127.0.0.1', - redis_port => 6379, - quorum => 2, - parallel_sync => 1, - down_after => 30000, - failover_timeout => 10000, + 'mymaster' => { + redis_host => '127.0.0.1', + redis_port => 6379, + quorum => 2, + parallel_sync => 1, + down_after => 30000, + failover_timeout => 10000, }, }, + protected_mode => false, } EOS diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index e9bb5a5d..a11c88fe 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -136,7 +136,7 @@ 'notification_script' => '/path/to/bar.sh', 'client_reconfig_script' => '/path/to/foo.sh', 'auth_pass' => 'password', - } + }, sentinel_bind: ['192.0.2.10', '192.168.1.1'], working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log', @@ -150,6 +150,7 @@ dir /tmp/redis daemonize #{facts[:osfamily] == 'RedHat' ? 'no' : 'yes'} pidfile #{pidfile} +protected-mode yes sentinel monitor cow 127.0.0.1 6379 2 sentinel down-after-milliseconds cow 6000 From 1e1e552a60de02c0b508f325058b72f596a423d5 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 10 Nov 2020 12:58:48 +0100 Subject: [PATCH 37/46] delete comma at the end of hash --- spec/classes/redis_sentinel_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index a11c88fe..1304f458 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -85,12 +85,12 @@ 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', 'client_reconfig_script' => '/path/to/foo.sh', - 'auth_pass' => 'password', + 'auth_pass' => 'password' } sentinel_bind: '192.0.2.10', protected_mode: false, working_dir: '/tmp/redis', - log_file: '/tmp/barn-sentinel.log', + log_file: '/tmp/barn-sentinel.log' } end @@ -135,11 +135,11 @@ 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', 'client_reconfig_script' => '/path/to/foo.sh', - 'auth_pass' => 'password', + 'auth_pass' => 'password' }, sentinel_bind: ['192.0.2.10', '192.168.1.1'], working_dir: '/tmp/redis', - log_file: '/tmp/barn-sentinel.log', + log_file: '/tmp/barn-sentinel.log' } end From a8a20b7d607f15c5dcd97c3293de6ad11b457a39 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 10 Nov 2020 13:19:20 +0100 Subject: [PATCH 38/46] protected mode failure workaround --- spec/classes/redis_sentinel_spec.rb | 1 + templates/redis-sentinel.conf.erb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 1304f458..f0a380a4 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -138,6 +138,7 @@ 'auth_pass' => 'password' }, sentinel_bind: ['192.0.2.10', '192.168.1.1'], + protected_mode: false, working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log' } diff --git a/templates/redis-sentinel.conf.erb b/templates/redis-sentinel.conf.erb index 9680729b..04170a44 100644 --- a/templates/redis-sentinel.conf.erb +++ b/templates/redis-sentinel.conf.erb @@ -5,7 +5,9 @@ port <%= @sentinel_port %> dir <%= @working_dir %> daemonize <%= @daemonize ? 'yes' : 'no' %> pidfile <%= @pid_file %> +<% if @protected_mode -%> protected-mode <%= @protected_mode ? 'yes' : 'no' %> +<% end -%> <% @_monitor.each do |values| -%> sentinel monitor <%= values['monitor_name'] %> <%= values['redis_host'] %> <%= values['redis_port'] %> <%= values['quorum'] %> From 484ce19bc02d3182280ebc08df4b47418bc23847 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 10 Nov 2020 14:03:43 +0100 Subject: [PATCH 39/46] fix syntax error in spec --- spec/classes/redis_sentinel_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index f0a380a4..06d0cbec 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -87,6 +87,7 @@ 'client_reconfig_script' => '/path/to/foo.sh', 'auth_pass' => 'password' } + }, sentinel_bind: '192.0.2.10', protected_mode: false, working_dir: '/tmp/redis', @@ -136,7 +137,8 @@ 'notification_script' => '/path/to/bar.sh', 'client_reconfig_script' => '/path/to/foo.sh', 'auth_pass' => 'password' - }, + } + }, sentinel_bind: ['192.0.2.10', '192.168.1.1'], protected_mode: false, working_dir: '/tmp/redis', From 0fa088952fb3b28bed23652e6a3f58c3a6482f06 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 10 Nov 2020 14:51:58 +0100 Subject: [PATCH 40/46] fix template and spec test --- spec/classes/redis_sentinel_spec.rb | 2 -- templates/redis-sentinel.conf.erb | 1 - 2 files changed, 3 deletions(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 06d0cbec..851f2d48 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -102,7 +102,6 @@ dir /tmp/redis daemonize #{facts[:osfamily] == 'RedHat' ? 'no' : 'yes'} pidfile #{pidfile} -protected-mode no sentinel monitor mymaster 127.0.0.1 6379 2 sentinel down-after-milliseconds mymaster 6000 @@ -153,7 +152,6 @@ dir /tmp/redis daemonize #{facts[:osfamily] == 'RedHat' ? 'no' : 'yes'} pidfile #{pidfile} -protected-mode yes sentinel monitor cow 127.0.0.1 6379 2 sentinel down-after-milliseconds cow 6000 diff --git a/templates/redis-sentinel.conf.erb b/templates/redis-sentinel.conf.erb index 04170a44..4f8f7f38 100644 --- a/templates/redis-sentinel.conf.erb +++ b/templates/redis-sentinel.conf.erb @@ -24,6 +24,5 @@ sentinel notification-script <%= values['monitor_name'] %> <%= values['notificat sentinel client-reconfig-script <%= values['monitor_name'] %> <%= values['client_reconfig_script'] %> <% end %> <% end -%> - loglevel <%= @log_level %> logfile <%= @log_file %> From 3894fa4833a52097482614e5592f3a6fef4f9bed Mon Sep 17 00:00:00 2001 From: basti-nis Date: Tue, 10 Nov 2020 15:46:37 +0100 Subject: [PATCH 41/46] fix duplicate entrys --- spec/classes/redis_sentinel_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 851f2d48..68d97c51 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -84,8 +84,7 @@ 'down_after' => 6000, 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', - 'client_reconfig_script' => '/path/to/foo.sh', - 'auth_pass' => 'password' + 'client_reconfig_script' => '/path/to/foo.sh' } }, sentinel_bind: '192.0.2.10', @@ -134,8 +133,7 @@ 'down_after' => 6000, 'failover_timeout' => 28_000, 'notification_script' => '/path/to/bar.sh', - 'client_reconfig_script' => '/path/to/foo.sh', - 'auth_pass' => 'password' + 'client_reconfig_script' => '/path/to/foo.sh' } }, sentinel_bind: ['192.0.2.10', '192.168.1.1'], From f417d65e198245139b12e87a6ee7e334762be0a5 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 10 Nov 2020 22:40:06 +0100 Subject: [PATCH 42/46] add protected mode support --- manifests/sentinel.pp | 16 +++++++++++++++- .../default/redis_sentinel_one_node_spec.rb | 1 - spec/classes/redis_sentinel_spec.rb | 2 -- templates/redis-sentinel.conf.erb | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index db96a792..c3d887b6 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -110,7 +110,8 @@ Redis::SentinelMonitor $sentinel_monitor = $redis::params::sentinel_default_monitor, $monitor_defaults = $redis::params::sentinel_monitor_defaults, String[1] $package_name = $redis::params::sentinel_package_name, - String[1] $package_ensure = 'present', + String[1] $package_ensure = $redis::package_ensure, + String[1] $minimum_version = $redis::minimum_version, Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, Stdlib::Port $sentinel_port = 26379, String[1] $service_group = 'redis', @@ -134,6 +135,19 @@ } } + if $package_ensure =~ /^([0-9]+:)?[0-9]+\.[0-9]/ { + if ':' in $package_ensure { + $_redis_version_real = split($package_ensure, ':') + $redis_version_real = $_redis_version_real[1] + } else { + $redis_version_real = $package_ensure + } + } else { + $redis_version_real = pick(getvar('redis_server_version'), $minimum_version) + } + + $supports_protected_mode = !$redis_version_real or versioncmp($redis_version_real, '3.2.0') >= 0 + $sentinel_bind_arr = delete_undef_values([$sentinel_bind].flatten) $_monitor = $sentinel_monitor.map |$monitor,$values| { diff --git a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb index ef2bbd16..dce7b847 100644 --- a/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb +++ b/spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb @@ -21,7 +21,6 @@ class { 'redis::sentinel': failover_timeout => 10000, }, }, - protected_mode => false, } EOS diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 68d97c51..29931d5a 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -88,7 +88,6 @@ } }, sentinel_bind: '192.0.2.10', - protected_mode: false, working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log' } @@ -137,7 +136,6 @@ } }, sentinel_bind: ['192.0.2.10', '192.168.1.1'], - protected_mode: false, working_dir: '/tmp/redis', log_file: '/tmp/barn-sentinel.log' } diff --git a/templates/redis-sentinel.conf.erb b/templates/redis-sentinel.conf.erb index 4f8f7f38..33d80d91 100644 --- a/templates/redis-sentinel.conf.erb +++ b/templates/redis-sentinel.conf.erb @@ -5,7 +5,7 @@ port <%= @sentinel_port %> dir <%= @working_dir %> daemonize <%= @daemonize ? 'yes' : 'no' %> pidfile <%= @pid_file %> -<% if @protected_mode -%> +<% if @supports_protected_mode -%> protected-mode <%= @protected_mode ? 'yes' : 'no' %> <% end -%> From 204b8442e563b68201c35f0dd051734cd76c20b7 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Tue, 10 Nov 2020 23:54:01 +0100 Subject: [PATCH 43/46] fix spec test and protected mode --- manifests/sentinel.pp | 17 ++---- spec/classes/redis_sentinel_spec.rb | 85 +++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 19 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index c3d887b6..7aa0183b 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -110,8 +110,8 @@ Redis::SentinelMonitor $sentinel_monitor = $redis::params::sentinel_default_monitor, $monitor_defaults = $redis::params::sentinel_monitor_defaults, String[1] $package_name = $redis::params::sentinel_package_name, - String[1] $package_ensure = $redis::package_ensure, - String[1] $minimum_version = $redis::minimum_version, + String[1] $package_ensure = 'present', + String[1] $minimum_version = $redis::params::minimum_version, Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, Stdlib::Port $sentinel_port = 26379, String[1] $service_group = 'redis', @@ -135,18 +135,9 @@ } } - if $package_ensure =~ /^([0-9]+:)?[0-9]+\.[0-9]/ { - if ':' in $package_ensure { - $_redis_version_real = split($package_ensure, ':') - $redis_version_real = $_redis_version_real[1] - } else { - $redis_version_real = $package_ensure - } - } else { - $redis_version_real = pick(getvar('redis_server_version'), $minimum_version) - } + $redis_version_real = pick(getvar('redis_server_version'), $minimum_version) - $supports_protected_mode = !$redis_version_real or versioncmp($redis_version_real, '3.2.0') >= 0 + $supports_protected_mode = versioncmp($redis_version_real, '3.2.0') >= 0 $sentinel_bind_arr = delete_undef_values([$sentinel_bind].flatten) diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 29931d5a..56b254b4 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -29,9 +29,33 @@ end end + let(:protected_mode) do + if facts[:operatingsystem] == 'Ubuntu' + facts[:operatingsystemmajrelease] != '16.04' ? "protected-mode yes\n" : '' + end + end + describe 'without parameters' do - let(:expected_content) do - < Date: Wed, 11 Nov 2020 00:01:23 +0100 Subject: [PATCH 44/46] minimum_version should be private --- manifests/sentinel.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 7aa0183b..c965e161 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -111,7 +111,6 @@ $monitor_defaults = $redis::params::sentinel_monitor_defaults, String[1] $package_name = $redis::params::sentinel_package_name, String[1] $package_ensure = 'present', - String[1] $minimum_version = $redis::params::minimum_version, Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, Stdlib::Port $sentinel_port = 26379, String[1] $service_group = 'redis', @@ -135,6 +134,7 @@ } } + $minimum_version = $redis::params::minimum_version $redis_version_real = pick(getvar('redis_server_version'), $minimum_version) $supports_protected_mode = versioncmp($redis_version_real, '3.2.0') >= 0 From d2d9bcce891ac8c571de1992cef1c0b910253257 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 11 Nov 2020 00:20:46 +0100 Subject: [PATCH 45/46] remove comments --- manifests/params.pp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index badc37a7..fe795cef 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -212,10 +212,7 @@ quorum => 2, down_after => 30000, parallel_sync => 1, - failover_timeout => 180000, - # auth_pass => undef, - # notification_script => undef, - # client_reconfig_script => undef, + failover_timeout => 180000 } $sentinel_default_monitor = { 'mymaster' => $sentinel_monitor_defaults, From eed6b768c552baec161563e1a3334de7362d0319 Mon Sep 17 00:00:00 2001 From: Sebastian Treu Date: Wed, 11 Nov 2020 01:36:14 +0100 Subject: [PATCH 46/46] add missing traling comma after last element --- manifests/params.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/params.pp b/manifests/params.pp index fe795cef..3d25b5df 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -212,7 +212,7 @@ quorum => 2, down_after => 30000, parallel_sync => 1, - failover_timeout => 180000 + failover_timeout => 180000, } $sentinel_default_monitor = { 'mymaster' => $sentinel_monitor_defaults,