Skip to content

Commit 95a67f5

Browse files
authored
Merge pull request #437 from traylenator/wrap
Deprecate `systemd::service_limits`
2 parents f1c49bf + 988d2c7 commit 95a67f5

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
@@ -61,7 +61,7 @@
6161
* [`Systemd::LogindSettings::Ensure`](#Systemd--LogindSettings--Ensure): defines allowed ensure states for systemd-logind settings
6262
* [`Systemd::MachineInfoSettings`](#Systemd--MachineInfoSettings): Matches Systemd machine-info (hostnamectl) file Struct
6363
* [`Systemd::OomdSettings`](#Systemd--OomdSettings): Configurations for oomd.conf
64-
* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Matches Systemd Service Limit Struct
64+
* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Deprecated - Matches Systemd Service Limit Struct
6565
* [`Systemd::Unit`](#Systemd--Unit): custom datatype that validates different filenames for systemd units and unit templates
6666
* [`Systemd::Unit::Amount`](#Systemd--Unit--Amount): Systemd definition of amount, often bytes or united bytes
6767
* [`Systemd::Unit::AmountOrPercent`](#Systemd--Unit--AmountOrPercent): Systemd definition of amount, often bytes or united bytes
@@ -163,7 +163,7 @@ Default value: `undef`
163163

164164
Data type: `Stdlib::CreateResources`
165165

166-
Hash of `systemd::service_limits` resources
166+
Deprecated, use dropin_files - Hash of `systemd::service_limits` resources
167167

168168
Default value: `{}`
169169

@@ -1584,7 +1584,7 @@ Default value: `true`
15841584

15851585
### <a name="systemd--service_limits"></a>`systemd::service_limits`
15861586

1587-
Adds a set of custom limits to the service
1587+
Deprecated - Adds a set of custom limits to the service
15881588

15891589
* **See also**
15901590
* systemd.exec(5)
@@ -2650,7 +2650,7 @@ Struct[{
26502650

26512651
### <a name="Systemd--ServiceLimits"></a>`Systemd::ServiceLimits`
26522652

2653-
Matches Systemd Service Limit Struct
2653+
Deprecated - Matches Systemd Service Limit Struct
26542654

26552655
Alias of
26562656

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
@@ -358,6 +358,11 @@
358358
}
359359
end
360360

361+
# systemd::service_limits is deprecated
362+
before do
363+
Puppet.settings[:strict] = :warning
364+
end
365+
361366
it { is_expected.to compile.with_all_deps }
362367
it { is_expected.to contain_systemd__service_limits('openstack-nova-compute.service').with_limits('LimitNOFILE' => 32_768) }
363368
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)