From 846d4969058f445590cbe402cf182f9772874bfe Mon Sep 17 00:00:00 2001 From: Diego Abelenda Date: Thu, 4 Jul 2024 11:47:26 +0200 Subject: [PATCH] Preliminary work add Kube unit support --- manifests/manage_dropin.pp | 7 +++++++ manifests/unit_file.pp | 2 +- templates/unit_file.epp | 2 ++ types/unit.pp | 2 +- types/unit/kube.pp | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 types/unit/kube.pp diff --git a/manifests/manage_dropin.pp b/manifests/manage_dropin.pp index 140c79bb..fc1735b3 100644 --- a/manifests/manage_dropin.pp +++ b/manifests/manage_dropin.pp @@ -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, @@ -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") @@ -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, @@ -145,6 +151,7 @@ 'timer_entry' => $timer_entry, 'path_entry' => $path_entry, 'socket_entry' => $socket_entry, + 'kube_entry' => $kube_entry, }), } } diff --git a/manifests/unit_file.pp b/manifests/unit_file.pp index 237e27a9..2866b5f6 100644 --- a/manifests/unit_file.pp +++ b/manifests/unit_file.pp @@ -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 diff --git a/templates/unit_file.epp b/templates/unit_file.epp index 483281f0..4e791fa3 100644 --- a/templates/unit_file.epp +++ b/templates/unit_file.epp @@ -6,6 +6,7 @@ Optional[Hash] $timer_entry, Optional[Hash] $path_entry, Optional[Hash] $socket_entry, + Optional[Hash] $kube_entry, | -%> <%- @@ -14,6 +15,7 @@ $_unit_sections = [ 'Unit', + 'Kube', 'Slice', 'Service', 'Timer', diff --git a/types/unit.pp b/types/unit.pp index 999d9733..504b72b7 100644 --- a/types/unit.pp +++ b/types/unit.pp @@ -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)$/] diff --git a/types/unit/kube.pp b/types/unit/kube.pp new file mode 100644 index 00000000..c8e0d1c7 --- /dev/null +++ b/types/unit/kube.pp @@ -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, + } +]