Skip to content

Commit 988d2c7

Browse files
committed
Deprecate systemd::service_limits
The `systemd::service_limts` and corresponding type `Systemd::Servicelimits` is deprecated. Switch to `systemd::dropin_file` for a source attributed `systemd::service_limits` or `systemd::manage_unit` for a `limits` attributed `systemd::service_limits`.
1 parent 48e0752 commit 988d2c7

File tree

8 files changed

+63
-40
lines changed

8 files changed

+63
-40
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ Finished on controller-0:
586586
}
587587
```
588588

589+
## Deprecation Notices
590+
591+
The type `systemd::service_limits` is deprecated and `systemd::manage_dropin` or `systemd::dropin_file` should
592+
be used instead.
593+
589594
## Transfer Notice
590595

591596
This plugin was originally authored by [Camptocamp](http://www.camptocamp.com).

REFERENCE.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* [`systemd::manage_unit`](#systemd--manage_unit): Generate unit file from template
3535
* [`systemd::modules_load`](#systemd--modules_load): Creates a modules-load.d drop file
3636
* [`systemd::network`](#systemd--network): Creates network config for systemd-networkd
37-
* [`systemd::service_limits`](#systemd--service_limits): Adds a set of custom limits to the service
37+
* [`systemd::service_limits`](#systemd--service_limits): Deprecated - Adds a set of custom limits to the service
3838
* [`systemd::timer`](#systemd--timer): Create a timer and optionally a service unit to execute with the timer unit
3939
* [`systemd::timer_wrapper`](#systemd--timer_wrapper): Helper to define timer and accompanying services for a given task (cron like interface).
4040
* [`systemd::tmpfile`](#systemd--tmpfile): Creates a systemd tmpfile
@@ -60,7 +60,7 @@
6060
* [`Systemd::LogindSettings::Ensure`](#Systemd--LogindSettings--Ensure): defines allowed ensure states for systemd-logind settings
6161
* [`Systemd::MachineInfoSettings`](#Systemd--MachineInfoSettings): Matches Systemd machine-info (hostnamectl) file Struct
6262
* [`Systemd::OomdSettings`](#Systemd--OomdSettings): Configurations for oomd.conf
63-
* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Matches Systemd Service Limit Struct
63+
* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Deprecated - Matches Systemd Service Limit Struct
6464
* [`Systemd::Unit`](#Systemd--Unit): custom datatype that validates different filenames for systemd units and unit templates
6565
* [`Systemd::Unit::Amount`](#Systemd--Unit--Amount): Systemd definition of amount, often bytes or united bytes
6666
* [`Systemd::Unit::AmountOrPercent`](#Systemd--Unit--AmountOrPercent): Systemd definition of amount, often bytes or united bytes
@@ -160,7 +160,7 @@ Default value: `undef`
160160

161161
Data type: `Stdlib::CreateResources`
162162

163-
Hash of `systemd::service_limits` resources
163+
Deprecated, use dropin_files - Hash of `systemd::service_limits` resources
164164

165165
Default value: `{}`
166166

@@ -1533,7 +1533,7 @@ Default value: `true`
15331533

15341534
### <a name="systemd--service_limits"></a>`systemd::service_limits`
15351535

1536-
Adds a set of custom limits to the service
1536+
Deprecated - Adds a set of custom limits to the service
15371537

15381538
* **See also**
15391539
* systemd.exec(5)
@@ -2501,7 +2501,7 @@ Struct[{
25012501

25022502
### <a name="Systemd--ServiceLimits"></a>`Systemd::ServiceLimits`
25032503

2504-
Matches Systemd Service Limit Struct
2504+
Deprecated - Matches Systemd Service Limit Struct
25052505

25062506
Alias of
25072507

manifests/init.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# The default systemd boot target, unmanaged if set to undef.
77
#
88
# @param service_limits
9-
# Hash of `systemd::service_limits` resources
9+
# Deprecated, use dropin_files - Hash of `systemd::service_limits` resources
1010
#
1111
# @param networks
1212
# Hash of `systemd::network` resources

manifests/service_limits.pp

+40-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adds a set of custom limits to the service
1+
# Deprecated - Adds a set of custom limits to the service
22
#
33
# @api public
44
#
@@ -47,13 +47,6 @@
4747
fail('$name must match Pattern["^.+\.(service|socket|mount|swap)$"]')
4848
}
4949

50-
if $limits and !empty($limits) {
51-
$_content = template("${module_name}/limits.erb")
52-
}
53-
else {
54-
$_content = undef
55-
}
56-
5750
if $ensure != 'absent' {
5851
if ($limits and !empty($limits)) and $source {
5952
fail('You may not supply both limits and source parameters to systemd::service_limits')
@@ -63,14 +56,44 @@
6356
}
6457
}
6558

66-
systemd::dropin_file { "${name}-90-limits.conf":
67-
ensure => $ensure,
68-
unit => $name,
69-
filename => '90-limits.conf',
70-
path => $path,
71-
selinux_ignore_defaults => $selinux_ignore_defaults,
72-
content => $_content,
73-
source => $source,
74-
notify_service => true,
59+
if $limits {
60+
# Some typing changed between Systemd::ServiceLimits and Systemd::Unit::Service
61+
$_now_tupled = [
62+
'IODeviceWeight',
63+
'IOReadBandwidthMax',
64+
'IOWriteBandwidthMax',
65+
'IOReadIOPSMax',
66+
'IOWriteIOPSMax',
67+
]
68+
69+
$_my_limits = $limits.map | $_directive, $_value | {
70+
if $_directive in $_now_tupled {
71+
{ $_directive => $_value.map | $_pair | { Array($_pair).flatten } } # Convert { 'a' => 'b' } to ['a', b']
72+
} else {
73+
{ $_directive => $_value }
74+
}
75+
}.reduce | $_memo, $_value | { $_memo + $_value }
76+
77+
deprecation("systemd::servicelimits - ${title}",'systemd::servicelimits is deprecated, use systemd::manage_dropin')
78+
systemd::manage_dropin { '#{name}-90-limits.conf':
79+
ensure => $ensure,
80+
unit => $name,
81+
filename => '90-limits.conf',
82+
path => $path,
83+
selinux_ignore_defaults => $selinux_ignore_defaults,
84+
service_entry => $_my_limits,
85+
notify_service => true,
86+
}
87+
} else {
88+
deprecation("systemd::servicelimits ${title}",'systemd::servicelimits is deprecated, use systemd::dropin_file or systemd::manage_dropin')
89+
systemd::dropin_file { '#{name}-90-limits.conf':
90+
ensure => $ensure,
91+
unit => $name,
92+
filename => '90-limits.conf',
93+
path => $path,
94+
selinux_ignore_defaults => $selinux_ignore_defaults,
95+
source => $source,
96+
notify_service => true,
97+
}
7598
}
7699
}

spec/classes/init_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@
335335
}
336336
end
337337

338+
# systemd::service_limits is deprecated
339+
before do
340+
Puppet.settings[:strict] = :warning
341+
end
342+
338343
it { is_expected.to compile.with_all_deps }
339344
it { is_expected.to contain_systemd__service_limits('openstack-nova-compute.service').with_limits('LimitNOFILE' => 32_768) }
340345
end

spec/defines/service_limits_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
let(:title) { 'test.service' }
1212

13+
# Whole type is deprecated but check it still works.
14+
before do
15+
Puppet.settings[:strict] = :warning
16+
end
17+
1318
describe 'with limits and present' do
1419
let(:params) do
1520
{

templates/limits.erb

-16
This file was deleted.

types/servicelimits.pp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Matches Systemd Service Limit Struct
1+
# @summary Deprecated - Matches Systemd Service Limit Struct
2+
#
23
type Systemd::ServiceLimits = Struct[
34
{
45
Optional['LimitCPU'] => Pattern['^\d+(s|m|h|d|w|M|y)?(:\d+(s|m|h|d|w|M|y)?)?$'],

0 commit comments

Comments
 (0)