diff --git a/README.md b/README.md index 373e4431..46d443a0 100644 --- a/README.md +++ b/README.md @@ -586,6 +586,11 @@ Finished on controller-0: } ``` +## Deprecation Notices + +The type `systemd::service_limits` is deprecated and `systemd::manage_dropin` or `systemd::dropin_file` should +be used instead. + ## Transfer Notice This plugin was originally authored by [Camptocamp](http://www.camptocamp.com). diff --git a/REFERENCE.md b/REFERENCE.md index 4c58eccb..1b56c9ae 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -34,7 +34,7 @@ * [`systemd::manage_unit`](#systemd--manage_unit): Generate unit file from template * [`systemd::modules_load`](#systemd--modules_load): Creates a modules-load.d drop file * [`systemd::network`](#systemd--network): Creates network config for systemd-networkd -* [`systemd::service_limits`](#systemd--service_limits): Adds a set of custom limits to the service +* [`systemd::service_limits`](#systemd--service_limits): Deprecated - Adds a set of custom limits to the service * [`systemd::timer`](#systemd--timer): Create a timer and optionally a service unit to execute with the timer unit * [`systemd::timer_wrapper`](#systemd--timer_wrapper): Helper to define timer and accompanying services for a given task (cron like interface). * [`systemd::tmpfile`](#systemd--tmpfile): Creates a systemd tmpfile @@ -60,7 +60,7 @@ * [`Systemd::LogindSettings::Ensure`](#Systemd--LogindSettings--Ensure): defines allowed ensure states for systemd-logind settings * [`Systemd::MachineInfoSettings`](#Systemd--MachineInfoSettings): Matches Systemd machine-info (hostnamectl) file Struct * [`Systemd::OomdSettings`](#Systemd--OomdSettings): Configurations for oomd.conf -* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Matches Systemd Service Limit Struct +* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Deprecated - Matches Systemd Service Limit Struct * [`Systemd::Unit`](#Systemd--Unit): custom datatype that validates different filenames for systemd units and unit templates * [`Systemd::Unit::Amount`](#Systemd--Unit--Amount): Systemd definition of amount, often bytes or united bytes * [`Systemd::Unit::AmountOrPercent`](#Systemd--Unit--AmountOrPercent): Systemd definition of amount, often bytes or united bytes @@ -160,7 +160,7 @@ Default value: `undef` Data type: `Stdlib::CreateResources` -Hash of `systemd::service_limits` resources +Deprecated, use dropin_files - Hash of `systemd::service_limits` resources Default value: `{}` @@ -1533,7 +1533,7 @@ Default value: `true` ### `systemd::service_limits` -Adds a set of custom limits to the service +Deprecated - Adds a set of custom limits to the service * **See also** * systemd.exec(5) @@ -2501,7 +2501,7 @@ Struct[{ ### `Systemd::ServiceLimits` -Matches Systemd Service Limit Struct +Deprecated - Matches Systemd Service Limit Struct Alias of diff --git a/manifests/init.pp b/manifests/init.pp index 2d6de190..1100a9dc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,7 +6,7 @@ # The default systemd boot target, unmanaged if set to undef. # # @param service_limits -# Hash of `systemd::service_limits` resources +# Deprecated, use dropin_files - Hash of `systemd::service_limits` resources # # @param networks # Hash of `systemd::network` resources diff --git a/manifests/service_limits.pp b/manifests/service_limits.pp index 49d1052e..6aa5ed6b 100644 --- a/manifests/service_limits.pp +++ b/manifests/service_limits.pp @@ -1,4 +1,4 @@ -# Adds a set of custom limits to the service +# Deprecated - Adds a set of custom limits to the service # # @api public # @@ -47,13 +47,6 @@ fail('$name must match Pattern["^.+\.(service|socket|mount|swap)$"]') } - if $limits and !empty($limits) { - $_content = template("${module_name}/limits.erb") - } - else { - $_content = undef - } - if $ensure != 'absent' { if ($limits and !empty($limits)) and $source { fail('You may not supply both limits and source parameters to systemd::service_limits') @@ -63,14 +56,44 @@ } } - systemd::dropin_file { "${name}-90-limits.conf": - ensure => $ensure, - unit => $name, - filename => '90-limits.conf', - path => $path, - selinux_ignore_defaults => $selinux_ignore_defaults, - content => $_content, - source => $source, - notify_service => true, + if $limits { + # Some typing changed between Systemd::ServiceLimits and Systemd::Unit::Service + $_now_tupled = [ + 'IODeviceWeight', + 'IOReadBandwidthMax', + 'IOWriteBandwidthMax', + 'IOReadIOPSMax', + 'IOWriteIOPSMax', + ] + + $_my_limits = $limits.map | $_directive, $_value | { + if $_directive in $_now_tupled { + { $_directive => $_value.map | $_pair | { Array($_pair).flatten } } # Convert { 'a' => 'b' } to ['a', b'] + } else { + { $_directive => $_value } + } + }.reduce | $_memo, $_value | { $_memo + $_value } + + deprecation("systemd::servicelimits - ${title}",'systemd::servicelimits is deprecated, use systemd::manage_dropin') + systemd::manage_dropin { '#{name}-90-limits.conf': + ensure => $ensure, + unit => $name, + filename => '90-limits.conf', + path => $path, + selinux_ignore_defaults => $selinux_ignore_defaults, + service_entry => $_my_limits, + notify_service => true, + } + } else { + deprecation("systemd::servicelimits ${title}",'systemd::servicelimits is deprecated, use systemd::dropin_file or systemd::manage_dropin') + systemd::dropin_file { '#{name}-90-limits.conf': + ensure => $ensure, + unit => $name, + filename => '90-limits.conf', + path => $path, + selinux_ignore_defaults => $selinux_ignore_defaults, + source => $source, + notify_service => true, + } } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 87edddf2..c0d0ca58 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -335,6 +335,11 @@ } end + # systemd::service_limits is deprecated + before do + Puppet.settings[:strict] = :warning + end + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_systemd__service_limits('openstack-nova-compute.service').with_limits('LimitNOFILE' => 32_768) } end diff --git a/spec/defines/service_limits_spec.rb b/spec/defines/service_limits_spec.rb index d6c9cc14..89284b97 100644 --- a/spec/defines/service_limits_spec.rb +++ b/spec/defines/service_limits_spec.rb @@ -10,6 +10,11 @@ let(:title) { 'test.service' } + # Whole type is deprecated but check it still works. + before do + Puppet.settings[:strict] = :warning + end + describe 'with limits and present' do let(:params) do { diff --git a/templates/limits.erb b/templates/limits.erb deleted file mode 100644 index f51d756b..00000000 --- a/templates/limits.erb +++ /dev/null @@ -1,16 +0,0 @@ -# This file managed by Puppet - DO NOT EDIT -[Service] -<% - @limits.keys.sort.each do |k| - - # Handles the Path and Option entries - if @limits[k].is_a?(Array) - output = @limits[k].map{|x| - x = %(#{k}=#{x.to_a.flatten.join(' ')}) - }.join("\n") - else - output = %(#{k}=#{@limits[k]}) - end --%> -<%= output %> -<% end -%> diff --git a/types/servicelimits.pp b/types/servicelimits.pp index 9c111096..62af55a0 100644 --- a/types/servicelimits.pp +++ b/types/servicelimits.pp @@ -1,4 +1,5 @@ -# Matches Systemd Service Limit Struct +# @summary Deprecated - Matches Systemd Service Limit Struct +# type Systemd::ServiceLimits = Struct[ { Optional['LimitCPU'] => Pattern['^\d+(s|m|h|d|w|M|y)?(:\d+(s|m|h|d|w|M|y)?)?$'],