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 0b253c6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
41 changes: 39 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* [`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
* [`Systemd::Unit::Install`](#Systemd--Unit--Install): Possible keys for the [Install] section of a unit file
* [`Systemd::Unit::Kube`](#Systemd--Unit--Kube): Possible keys for the [Kube] section of a unit file
* [`Systemd::Unit::Path`](#Systemd--Unit--Path): Possible keys for the [Path] section of a unit file
* [`Systemd::Unit::Percent`](#Systemd--Unit--Percent): Systemd definition of a percentage
* [`Systemd::Unit::Service`](#Systemd--Unit--Service): Possible keys for the [Service] section of a unit file
Expand Down Expand Up @@ -1022,6 +1023,7 @@ The following parameters are available in the `systemd::manage_dropin` defined t
* [`timer_entry`](#-systemd--manage_dropin--timer_entry)
* [`path_entry`](#-systemd--manage_dropin--path_entry)
* [`socket_entry`](#-systemd--manage_dropin--socket_entry)
* [`kube_entry`](#-systemd--manage_dropin--kube_entry)

##### <a name="-systemd--manage_dropin--unit"></a>`unit`

Expand Down Expand Up @@ -1165,6 +1167,14 @@ key value pairs for the [Socket] section of the unit file

Default value: `undef`

##### <a name="-systemd--manage_dropin--kube_entry"></a>`kube_entry`

Data type: `Optional[Systemd::Unit::Kube]`

key value pairs for the [Kube] section of the unit file

Default value: `undef`

### <a name="systemd--manage_unit"></a>`systemd::manage_unit`

Generate unit file from template
Expand Down Expand Up @@ -2183,7 +2193,7 @@ The following parameters are available in the `systemd::unit_file` defined type:

##### <a name="-systemd--unit_file--name"></a>`name`

Data type: `Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']`
Data type: `Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope|kube)$']`

The target unit file to create

Expand Down Expand Up @@ -2746,7 +2756,7 @@ custom datatype that validates different filenames for systemd units and unit te
* **See also**
* https://www.freedesktop.org/software/systemd/man/systemd.unit.html

Alias of `Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]`
Alias of `Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope|kube)$/]`

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

Expand Down Expand Up @@ -2789,6 +2799,33 @@ Struct[{
}]
```

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

Possible keys for the [Kube] section of a unit file

* **See also**
* https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#kube-units-kube

Alias of

```puppet
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,
}]
```

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

Possible keys for the [Path] section of a unit file
Expand Down
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 0b253c6

Please sign in to comment.