Skip to content

Commit

Permalink
Preliminary work add Kube unit support
Browse files Browse the repository at this point in the history
  • Loading branch information
dabelenda committed Jul 4, 2024
1 parent 3317560 commit 846d496
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions manifests/manage_dropin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
# @param timer_entry key value pairs for [Timer] section of the unit file
# @param path_entry key value pairs for [Path] section of the unit file
# @param socket_entry key value pairs for the [Socket] section of the unit file
# @param kube_entry key value pairs for the [Kube] section of the unit file
#
define systemd::manage_dropin (
Systemd::Unit $unit,
Expand All @@ -108,6 +109,7 @@
Optional[Systemd::Unit::Timer] $timer_entry = undef,
Optional[Systemd::Unit::Path] $path_entry = undef,
Optional[Systemd::Unit::Socket] $socket_entry = undef,
Optional[Systemd::Unit::Kube] $kube_entry = undef,
) {
if $timer_entry and $unit !~ Pattern['^[^/]+\.timer'] {
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} timer_entry is only valid for timer units")
Expand All @@ -125,6 +127,10 @@
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} slice_entry is only valid for slice units")
}

if $kube_entry and $unit !~ Pattern['^[^/]+\.kube'] {
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} slice_entry is only valid for kube units")
}

systemd::dropin_file { $name:
ensure => $ensure,
filename => $filename,
Expand All @@ -145,6 +151,7 @@
'timer_entry' => $timer_entry,
'path_entry' => $path_entry,
'socket_entry' => $socket_entry,
'kube_entry' => $kube_entry,
}),
}
}
2 changes: 1 addition & 1 deletion manifests/unit_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# @see systemd.unit(5)
#
# @param name [Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']]
# @param name [Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope|kube)$']]
# The target unit file to create
#
# @param ensure
Expand Down
2 changes: 2 additions & 0 deletions templates/unit_file.epp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Optional[Hash] $timer_entry,
Optional[Hash] $path_entry,
Optional[Hash] $socket_entry,
Optional[Hash] $kube_entry,
| -%>
<%-

Expand All @@ -14,6 +15,7 @@

$_unit_sections = [
'Unit',
'Kube',
'Slice',
'Service',
'Timer',
Expand Down
2 changes: 1 addition & 1 deletion types/unit.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @summary custom datatype that validates different filenames for systemd units and unit templates
# @see https://www.freedesktop.org/software/systemd/man/systemd.unit.html
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope|kube)$/]
19 changes: 19 additions & 0 deletions types/unit/kube.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @summary Possible keys for the [Kube] section of a unit file
# @see https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#kube-units-kube
type Systemd::Unit::Kube = Struct[
{
Optional['AutoUpdate'] => String,
Optional['ConfigMap'] => Stdlib::Unixpath,
Optional['ContainersConfModule'] => Stdlib::Unixpath,
Optional['ExitCodePropagation'] => Enum['all', 'any', 'none'],
Optioanl['GlobalArgs'] => String,
Optional['KubeDownForce'] => Boolean,
Optional['LogDriver'] => String,
Optional['Network'] => String,
Optional['PodmanArgs'] => String,
Optional['PublishPort'] => Variant[String, Integer],
Optional['SetWorkingDirectory'] => Enum['yaml', 'unit'],
Optional['UserNS'] => String,
Optional['Yaml'] => Stdlib::Unixpath,
}
]

0 comments on commit 846d496

Please sign in to comment.