Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate systemd::service_limits #437

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
10 changes: 5 additions & 5 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: `{}`

Expand Down Expand Up @@ -1533,7 +1533,7 @@ Default value: `true`

### <a name="systemd--service_limits"></a>`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)
Expand Down Expand Up @@ -2501,7 +2501,7 @@ Struct[{

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

Matches Systemd Service Limit Struct
Deprecated - Matches Systemd Service Limit Struct

Alias of

Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 40 additions & 17 deletions manifests/service_limits.pp
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down Expand Up @@ -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')
Expand All @@ -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,
}
}
}
5 changes: 5 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/defines/service_limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
16 changes: 0 additions & 16 deletions templates/limits.erb

This file was deleted.

3 changes: 2 additions & 1 deletion types/servicelimits.pp
Original file line number Diff line number Diff line change
@@ -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)?)?$'],
Expand Down