-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Add support for podman quadlets #474
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# @summary Creates a systemd Podman Quadlet file | ||
# Quadlet will generate a unit file, and this service can be managed by puppet. | ||
# @api public | ||
# | ||
# @see podman.systemd.unit(5) | ||
# | ||
# @param name | ||
# The name of the quadlet file | ||
# | ||
# @param ensure | ||
# The state of the quadlet file to ensure | ||
# | ||
# @param content | ||
# The full content of the quadlet file | ||
# | ||
# @param path | ||
# The path where the quadlet file will be created | ||
# For systemd in user mode use any of | ||
# - ~/.config/containers/systemd | ||
# - /etc/containers/systemd/users/$(UID) | ||
# | ||
# For global systemd use any of: | ||
# - /etc/containers/systemd | ||
# - /usr/share/containers/systemd | ||
# | ||
# @param source | ||
# The ``File`` resource compatible ``source`` | ||
# | ||
# * Mutually exclusive with ``$content`` | ||
# | ||
# @param owner | ||
# The owner to set on the unit file | ||
# | ||
# @param group | ||
# The group to set on the unit file | ||
# | ||
# @param mode | ||
# The mode to set on the unit file | ||
# | ||
# @param enable | ||
# If set, will manage the unit enablement status. | ||
# | ||
# @param active | ||
# If set, will manage the state of the unit. | ||
# | ||
# @param restart | ||
# Specify a restart command manually. If left unspecified, a standard Puppet service restart happens. | ||
# | ||
# @param service_parameters | ||
# hash that will be passed with the splat operator to the service resource | ||
# | ||
# @param daemon_reload | ||
# call `systemd::daemon-reload` to ensure that the modified unit file is loaded | ||
# | ||
# @param service_restart | ||
# restart (notify) the service when unit file changed | ||
define systemd::quadlet_file ( | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Stdlib::Absolutepath $path = '/etc/containers/systemd', | ||
Optional[Variant[String, Sensitive[String], Deferred]] $content = undef, | ||
Optional[String] $source = undef, | ||
String[1] $owner = 'root', | ||
String[1] $group = 'root', | ||
String[1] $mode = '0444', | ||
Optional[Boolean] $enable = undef, | ||
Optional[Boolean] $active = undef, | ||
Optional[String] $restart = undef, | ||
Hash[String[1], Any] $service_parameters = {}, | ||
Boolean $daemon_reload = true, | ||
Boolean $service_restart = true, | ||
) { | ||
include systemd | ||
assert_type(Systemd::Quadlet, $name) | ||
$service_name=regsubst($name, '^(.*)\\..*', '\\1.service') | ||
|
||
file { "${path}/${name}": | ||
ensure => $ensure, | ||
content => $content, | ||
source => $source, | ||
owner => $owner, | ||
group => $group, | ||
mode => $mode, | ||
} | ||
|
||
if $daemon_reload { | ||
ensure_resource('systemd::daemon_reload', $name) | ||
|
||
File["${path}/${name}"] ~> Systemd::Daemon_reload[$name] | ||
} | ||
|
||
if $enable != undef or $active != undef { | ||
service { $service_name: | ||
ensure => $active, | ||
enable => $enable, | ||
restart => $restart, | ||
provider => 'systemd', | ||
* => $service_parameters, | ||
} | ||
|
||
if $ensure == 'absent' { | ||
if $enable or $active { | ||
fail("Can't ensure the unit file is absent and activate/enable the service at the same time") | ||
} | ||
Service[$service_name] -> File["${path}/${name}"] | ||
} elsif $service_restart { | ||
File["${path}/${name}"] ~> Service[$service_name] | ||
|
||
if $daemon_reload { | ||
Systemd::Daemon_reload[$name] ~> Service[$service_name] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @summary custom datatype that validates different filenames for quadlet units | ||
# @see https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html https://www.freedesktop.org/software/systemd/man/systemd.unit.html | ||
type Systemd::Quadlet = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(container|volume|network|kube|image|build|pod)$/] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do those booleans need to be undef or can we default to true or false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not mandatory, it was copy/pasted directly from
unit_file.pp
to keep a consistent API in the module.If you request a change, I can remove the Optional, and set a default value.