Browse Source

Add support for promoted-max meta attribute

Master/Slave bundles used to have an attribute "masters" to
specify how many replicas can be promoted to Master state. That
attribute has been deprecated and renamed "promoted-max".

Expose the new attribute in the puppet resource bundle, and use
it automatically if an instantiated resource is configured with
deprecated attribute "masters" with pacemaker 2.

Closes-Bug: #1884108
Change-Id: I3033563ba8a28298d63db42dfa2df1960b685e45
changes/77/736277/4
Damien Ciabrini 3 weeks ago
parent
commit
bb6709c19a
3 changed files with 57 additions and 1 deletions
  1. +14
    -0
      lib/puppet/provider/pcmk_bundle/default.rb
  2. +15
    -0
      lib/puppet/type/pcmk_bundle.rb
  3. +28
    -1
      manifests/resource/bundle.pp

+ 14
- 0
lib/puppet/provider/pcmk_bundle/default.rb View File

@@ -27,6 +27,7 @@ Puppet::Type.type(:pcmk_bundle).provide(:default) do
image = @resource[:image]
replicas = @resource[:replicas]
masters = @resource[:masters]
promoted_max = @resource[:promoted_max]
container_options = @resource[:container_options]
options = @resource[:options]
run_command = @resource[:run_command]
@@ -56,6 +57,12 @@ Puppet::Type.type(:pcmk_bundle).provide(:default) do
if masters
cmd += " masters=#{masters}"
end
if promoted_max
if update
cmd += " masters="
end
cmd += " promoted-max=#{promoted_max}"
end
if options
cmd += ' options="' + options + '"'
end
@@ -230,6 +237,13 @@ Puppet::Type.type(:pcmk_bundle).provide(:default) do
def masters=(value)
end

def promoted_max
@resource[:promoted_max]
end

def promoted_max=(value)
end

def options
@resource[:options]
end


+ 15
- 0
lib/puppet/type/pcmk_bundle.rb View File

@@ -116,6 +116,21 @@ Puppet::Type.newtype(:pcmk_bundle) do
end
end

newproperty(:promoted_max) do
desc "number of clones promotable to master"

munge do |value|
if value.is_a?(String)
unless value =~ /^[\d]+$/
raise ArgumentError, "promoted_max must be an integer"
end
value = Integer(value)
end
raise ArgumentError, "promoted_max must be an integer >= 1" if value < 1
value
end
end

newproperty(:options) do
desc "docker options"
end


+ 28
- 1
manifests/resource/bundle.pp View File

@@ -25,6 +25,11 @@
# (optional) Number of masters to be set in the bundle
# Defaults to undef
#
# [*promoted_max*]
# (optional) Number of masters to be set in the bundle. Supersedes
# deprecated option 'masters' in pacemaker 2
# Defaults to undef
#
# [*options*]
# (optional) Options to be passed to the docker run command
# Defaults to undef
@@ -126,6 +131,7 @@ define pacemaker::resource::bundle(
$container_options = undef,
$replicas = undef,
$masters = undef,
$promoted_max = undef,
$options = undef,
$run_command = undef,
$storage_maps = undef,
@@ -150,12 +156,33 @@ define pacemaker::resource::bundle(
# target-dir=/var/log options=ro storage-map id=bar-storage-test
# source-dir=/foo target-dir=/bar options=wr

if $promoted_max {
if !$::pacemaker::pcs_010 {
fail('Cannot use \'promoted_max\' without pacemaker 2 and pcs >= 0.10')
} else {
$used_promoted_max = $promoted_max
}
}

# promoted_max supersedes masters in pacemaker 2 (pcs >= 0.10)
if $masters and $::pacemaker::pcs_010 {
if $promoted_max {
warning('Both \'masters\' and \'promoted_max\' specified, using option \'promoted_max\'')
} else {
$used_promoted_max = $masters
}
$used_masters = undef
} else {
$used_masters = $masters
}

pcmk_bundle { $name:
ensure => $ensure,
image => $image,
container_options => $container_options,
replicas => $replicas,
masters => $masters,
masters => $used_masters,
promoted_max => $used_promoted_max,
options => $options,
run_command => $run_command,
storage_maps => $storage_maps,


Loading…
Cancel
Save