From 3c46e561cc8c4074181fa8b22b2ff80d3e6b5098 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Fri, 27 Sep 2024 11:05:30 +0100 Subject: [PATCH 1/7] Enable templating within systemd unit files Signed-off-by: Marcus Noble --- CHANGELOG.md | 5 +++ helm/cluster/README.md | 28 +++++++++++++ .../templates/clusterapi/_helpers_flatcar.tpl | 17 ++++++++ helm/cluster/values.schema.json | 42 +++++++++++++++++++ 4 files changed, 92 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6b46823..f0c54aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added support for `Service` section in custom systemd configuration +- Added support for `After` and `BindsTo` within unit section of custom systemd configuration + ## [1.4.1] - 2024-09-23 ### Fixed diff --git a/helm/cluster/README.md b/helm/cluster/README.md index 0d337da9..91fbedcf 100644 --- a/helm/cluster/README.md +++ b/helm/cluster/README.md @@ -570,7 +570,14 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.type` | **Type** - A file system type to mount.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.what` | **What** - An absolute path of a device node, file or other resource to mount.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.where` | **Where** - An absolute path of a file or directory for the mount point; in particular, the destination cannot be a symbolic link.|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service` | **Service** - Configuration of the [Service] section.|**Type:** `object`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.additionalFields` | **AdditionalFields** - any extra fields to add to the systemd [Service] section.|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.execStart` | **ExecStart** - systemd service ExecStart.|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| @@ -682,7 +689,14 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.type` | **Type** - A file system type to mount.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.what` | **What** - An absolute path of a device node, file or other resource to mount.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.where` | **Where** - An absolute path of a file or directory for the mount point; in particular, the destination cannot be a symbolic link.|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service` | **Service** - Configuration of the [Service] section.|**Type:** `object`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.additionalFields` | **AdditionalFields** - any extra fields to add to the systemd [Service] section.|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.execStart` | **ExecStart** - systemd service ExecStart.|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| @@ -771,7 +785,14 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.type` | **Type** - A file system type to mount.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.what` | **What** - An absolute path of a device node, file or other resource to mount.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.where` | **Where** - An absolute path of a file or directory for the mount point; in particular, the destination cannot be a symbolic link.|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service` | **Service** - Configuration of the [Service] section.|**Type:** `object`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.additionalFields` | **AdditionalFields** - any extra fields to add to the systemd [Service] section.|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.execStart` | **ExecStart** - systemd service ExecStart.|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| @@ -893,7 +914,14 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.type` | **Type** - A file system type to mount.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.what` | **What** - An absolute path of a device node, file or other resource to mount.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.mount.where` | **Where** - An absolute path of a file or directory for the mount point; in particular, the destination cannot be a symbolic link.|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service` | **Service** - Configuration of the [Service] section.|**Type:** `object`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.additionalFields` | **AdditionalFields** - any extra fields to add to the systemd [Service] section.|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.execStart` | **ExecStart** - systemd service ExecStart.|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| diff --git a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl index 1666582d..849ecf19 100644 --- a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl +++ b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl @@ -21,6 +21,23 @@ {{- if hasKey .contents.unit "defaultDependencies" }} DefaultDependencies={{ if .contents.unit.defaultDependencies }}yes{{ else }}no{{ end }} {{- end }} + {{- if hasKey .contents.unit "after" }} + After={{ .contents.unit.after }} + {{- end }} + {{- if hasKey .contents.unit "bindsTo" }} + BindsTo={{ .contents.unit.bindsTo }} + {{- end }} + {{- end }} + {{- if .contents.service }} + [Service] + Type={{ .contents.service.type }} + RemainAfterExit={{ .contents.service.remainAfterExit }} + {{- if hasKey .contents.service "execStart" }} + ExecStart={{ .contents.service.execStart }} + {{- end }} + {{- if hasKey .contents.service "additionalFields" }} + {{ tpl .contents.service.additionalFields $ | nindent 4 }} + {{- end }} {{- end }} {{- if .contents.mount }} [Mount] diff --git a/helm/cluster/values.schema.json b/helm/cluster/values.schema.json index 936aaf43..2c418c41 100644 --- a/helm/cluster/values.schema.json +++ b/helm/cluster/values.schema.json @@ -926,6 +926,38 @@ } } }, + "service": { + "type": "object", + "title": "Service", + "description": "Configuration of the [Service] section.", + "required": [ + "type", + "remainAfterExit" + ], + "additionalProperties": false, + "properties": { + "type": { + "type": "string", + "title": "Type", + "description": "systemd service Type." + }, + "additionalFields": { + "type": "string", + "title": "AdditionalFields", + "description": "any extra fields to add to the systemd [Service] section." + }, + "execStart": { + "type": "string", + "title": "ExecStart", + "description": "systemd service ExecStart." + }, + "remainAfterExit": { + "type": "string", + "title": "RemainAfterExit", + "description": "systemd service RemainAfterExit." + } + } + }, "unit": { "type": "object", "title": "Unit", @@ -940,6 +972,16 @@ "title": "Description", "description": "systemd unit description." }, + "after": { + "type": "string", + "title": "After", + "description": "systemd unit After." + }, + "bindsTo": { + "type": "string", + "title": "BindsTo", + "description": "systemd unit BindsTo." + }, "defaultDependencies": { "type": "boolean", "title": "DefaultDependencies", From 68b4d3b55c5eb887bfc86e3709ced3eba0de5211 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Fri, 27 Sep 2024 11:17:04 +0100 Subject: [PATCH 2/7] Removed haskey conditional Signed-off-by: Marcus Noble --- helm/cluster/templates/clusterapi/_helpers_flatcar.tpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl index 849ecf19..e0c84d78 100644 --- a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl +++ b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl @@ -21,10 +21,10 @@ {{- if hasKey .contents.unit "defaultDependencies" }} DefaultDependencies={{ if .contents.unit.defaultDependencies }}yes{{ else }}no{{ end }} {{- end }} - {{- if hasKey .contents.unit "after" }} + {{- if .contents.unit.after }} After={{ .contents.unit.after }} {{- end }} - {{- if hasKey .contents.unit "bindsTo" }} + {{- if .contents.unit.bindsTo }} BindsTo={{ .contents.unit.bindsTo }} {{- end }} {{- end }} @@ -32,10 +32,10 @@ [Service] Type={{ .contents.service.type }} RemainAfterExit={{ .contents.service.remainAfterExit }} - {{- if hasKey .contents.service "execStart" }} + {{- if .contents.service.execStart }} ExecStart={{ .contents.service.execStart }} {{- end }} - {{- if hasKey .contents.service "additionalFields" }} + {{- if .contents.service.additionalFields }} {{ tpl .contents.service.additionalFields $ | nindent 4 }} {{- end }} {{- end }} From b629f78abf179e1ec5106b3e5a500848cc93828b Mon Sep 17 00:00:00 2001 From: Simon Weald Date: Fri, 27 Sep 2024 13:08:19 +0100 Subject: [PATCH 3/7] support multiple fields for dependency ordering --- CHANGELOG.md | 2 +- helm/cluster/README.md | 28 ++++++++++++++++--- .../templates/clusterapi/_helpers_flatcar.tpl | 14 +++++++++- helm/cluster/values.schema.json | 23 +++++++++++++-- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0c54aa6..79e60c17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added support for `Service` section in custom systemd configuration -- Added support for `After` and `BindsTo` within unit section of custom systemd configuration +- Added support for `After`, `Requires`, `Wants` and `BindsTo` within unit section of custom systemd configuration ## [1.4.1] - 2024-09-23 diff --git a/helm/cluster/README.md b/helm/cluster/README.md index 91fbedcf..b91204a7 100644 --- a/helm/cluster/README.md +++ b/helm/cluster/README.md @@ -576,10 +576,15 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| -| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `array`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after[*]` |**None**|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires` | **Requires** - systemd unit Requires.|**Type:** `array`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires[*]` |**None**|**Type:** `string`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants` | **Wants** - systemd unit Wants.|**Type:** `array`
| +| `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants[*]` |**None**|**Type:** `string`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*]` | **Unit drop-in**|**Type:** `object`
| | `providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*].contents` | **Contents** - The contents of the drop-in.|**Type:** `string`
| @@ -695,10 +700,15 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| -| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `array`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after[*]` |**None**|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires` | **Requires** - systemd unit Requires.|**Type:** `array`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires[*]` |**None**|**Type:** `string`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants` | **Wants** - systemd unit Wants.|**Type:** `array`
| +| `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants[*]` |**None**|**Type:** `string`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*]` | **Unit drop-in**|**Type:** `object`
| | `providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*].contents` | **Contents** - The contents of the drop-in.|**Type:** `string`
| @@ -791,10 +801,15 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| -| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `array`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after[*]` |**None**|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires` | **Requires** - systemd unit Requires.|**Type:** `array`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires[*]` |**None**|**Type:** `string`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants` | **Wants** - systemd unit Wants.|**Type:** `array`
| +| `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants[*]` |**None**|**Type:** `string`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*]` | **Unit drop-in**|**Type:** `object`
| | `providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*].contents` | **Contents** - The contents of the drop-in.|**Type:** `string`
| @@ -920,10 +935,15 @@ Provider-specific properties that can be set by cluster-$provider chart in order | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.remainAfterExit` | **RemainAfterExit** - systemd service RemainAfterExit.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.service.type` | **Type** - systemd service Type.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit` | **Unit** - Configuration of the [Unit] section.|**Type:** `object`
| -| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after` | **After** - systemd unit After.|**Type:** `array`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.after[*]` |**None**|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.bindsTo` | **BindsTo** - systemd unit BindsTo.|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.defaultDependencies` | **DefaultDependencies** - Flag that indicates if this systemd unit should have the default systemd unit dependencies.|**Type:** `boolean`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.description` | **Description** - systemd unit description.|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires` | **Requires** - systemd unit Requires.|**Type:** `array`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.requires[*]` |**None**|**Type:** `string`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants` | **Wants** - systemd unit Wants.|**Type:** `array`
| +| `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].contents.unit.wants[*]` |**None**|**Type:** `string`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins` | **Unit drop-ins** - The list of drop-ins for the unit|**Type:** `array`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*]` | **Unit drop-in**|**Type:** `object`
| | `providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units[*].dropins[*].contents` | **Contents** - The contents of the drop-in.|**Type:** `string`
| diff --git a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl index e0c84d78..0ae6a0cc 100644 --- a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl +++ b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl @@ -22,7 +22,19 @@ DefaultDependencies={{ if .contents.unit.defaultDependencies }}yes{{ else }}no{{ end }} {{- end }} {{- if .contents.unit.after }} - After={{ .contents.unit.after }} + {{- range $after := .contents.unit.after }} + After={{ $after }} + {{- end }} + {{- end }} + {{- if .contents.unit.requires }} + {{- range $requires := .contents.unit.requires }} + Requires={{ $requires }} + {{- end }} + {{- end }} + {{- if .contents.unit.wants }} + {{- range $wants := .contents.unit.wants }} + Wants={{ $wants }} + {{- end }} {{- end }} {{- if .contents.unit.bindsTo }} BindsTo={{ .contents.unit.bindsTo }} diff --git a/helm/cluster/values.schema.json b/helm/cluster/values.schema.json index 2c418c41..e3874454 100644 --- a/helm/cluster/values.schema.json +++ b/helm/cluster/values.schema.json @@ -973,9 +973,12 @@ "description": "systemd unit description." }, "after": { - "type": "string", + "type": "array", "title": "After", - "description": "systemd unit After." + "description": "systemd unit After.", + "items": { + "type": "string" + } }, "bindsTo": { "type": "string", @@ -986,6 +989,22 @@ "type": "boolean", "title": "DefaultDependencies", "description": "Flag that indicates if this systemd unit should have the default systemd unit dependencies." + }, + "requires": { + "type": "array", + "title": "Requires", + "description": "systemd unit Requires.", + "items": { + "type": "string" + } + }, + "wants": { + "type": "array", + "title": "Wants", + "description": "systemd unit Wants.", + "items": { + "type": "string" + } } } } From fe525c9a16862ac112a81a826431dc544272390e Mon Sep 17 00:00:00 2001 From: Simon Weald Date: Mon, 30 Sep 2024 15:38:27 +0100 Subject: [PATCH 4/7] pass global values to systemd unit templating functions --- helm/cluster/templates/bastion/_helpers_flatcar.tpl | 3 ++- helm/cluster/templates/clusterapi/_helpers_flatcar.tpl | 2 +- .../templates/clusterapi/controlplane/_helpers_flatcar.tpl | 6 ++++-- .../templates/clusterapi/workers/_helpers_flatcar.tpl | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/helm/cluster/templates/bastion/_helpers_flatcar.tpl b/helm/cluster/templates/bastion/_helpers_flatcar.tpl index c0513bf1..31ec4d59 100644 --- a/helm/cluster/templates/bastion/_helpers_flatcar.tpl +++ b/helm/cluster/templates/bastion/_helpers_flatcar.tpl @@ -3,8 +3,9 @@ containerLinuxConfig: additionalConfig: | systemd: {{- if (((((($.Values.providerIntegration.bastion).kubeadmConfig).ignition).containerLinuxConfig).additionalConfig).systemd).units }} + {{- $systemdUnitValues := dict "global" $.Values.global "units" $.Values.providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} units: - {{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $.Values.providerIntegration.bastion.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units | indent 6 }} + {{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $systemdUnitValues | indent 6 }} {{- else }} units: [] {{- end }} diff --git a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl index 0ae6a0cc..53aa8221 100644 --- a/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl +++ b/helm/cluster/templates/clusterapi/_helpers_flatcar.tpl @@ -5,7 +5,7 @@ {{- end }} {{- define "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" }} -{{- range . }} +{{- range .units }} - name: {{ .name }} {{- if hasKey . "enabled" }} enabled: {{ .enabled }} diff --git a/helm/cluster/templates/clusterapi/controlplane/_helpers_flatcar.tpl b/helm/cluster/templates/clusterapi/controlplane/_helpers_flatcar.tpl index aea101e9..09a8af93 100644 --- a/helm/cluster/templates/clusterapi/controlplane/_helpers_flatcar.tpl +++ b/helm/cluster/templates/clusterapi/controlplane/_helpers_flatcar.tpl @@ -19,10 +19,12 @@ containerLinuxConfig: {{- define "cluster.internal.controlPlane.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" }} {{- if ((((($.Values.providerIntegration.kubeadmConfig).ignition).containerLinuxConfig).additionalConfig).systemd).units }} -{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $.Values.providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- $systemdUnitValues := dict "global" $.Values.global "units" $.Values.providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $systemdUnitValues }} {{- end }} {{- if (((((($.Values.providerIntegration.controlPlane).kubeadmConfig).ignition).containerLinuxConfig).additionalConfig).systemd).units }} -{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $.Values.providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- $systemdUnitValues := dict "global" $.Values.global "units" $.Values.providerIntegration.controlPlane.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $systemdUnitValues }} {{- end }} {{- end }} diff --git a/helm/cluster/templates/clusterapi/workers/_helpers_flatcar.tpl b/helm/cluster/templates/clusterapi/workers/_helpers_flatcar.tpl index f65cfd38..af0c4988 100644 --- a/helm/cluster/templates/clusterapi/workers/_helpers_flatcar.tpl +++ b/helm/cluster/templates/clusterapi/workers/_helpers_flatcar.tpl @@ -16,10 +16,12 @@ containerLinuxConfig: {{- define "cluster.internal.workers.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" }} {{- if ((((($.Values.providerIntegration.kubeadmConfig).ignition).containerLinuxConfig).additionalConfig).systemd).units }} -{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $.Values.providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- $systemdUnitValues := dict "global" $.Values.global "units" $.Values.providerIntegration.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $systemdUnitValues }} {{- end }} {{- if (((((($.Values.providerIntegration.workers).kubeadmConfig).ignition).containerLinuxConfig).additionalConfig).systemd).units }} -{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $.Values.providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- $systemdUnitValues := dict "global" $.Values.global "units" $.Values.providerIntegration.workers.kubeadmConfig.ignition.containerLinuxConfig.additionalConfig.systemd.units }} +{{- include "cluster.internal.kubeadm.ignition.containerLinuxConfig.additionalConfig.systemd.units" $systemdUnitValues }} {{- end }} {{- end }} From fb4dd7968a4c3d228005ebd8e1e6edb20dff7e75 Mon Sep 17 00:00:00 2001 From: Simon Weald Date: Mon, 30 Sep 2024 16:17:18 +0100 Subject: [PATCH 5/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79e60c17..dc9644ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support for `Service` section in custom systemd configuration - Added support for `After`, `Requires`, `Wants` and `BindsTo` within unit section of custom systemd configuration +- Added support for passing Helm templating from provider chart values through to systemd unit templates ## [1.4.1] - 2024-09-23 From 83c11b5d586fa1d4e51a981f6c0772f4447da975 Mon Sep 17 00:00:00 2001 From: Simon Weald Date: Mon, 30 Sep 2024 21:40:12 +0100 Subject: [PATCH 6/7] Update README with systemd templating info --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/README.md b/README.md index f95c617e..744be80a 100644 --- a/README.md +++ b/README.md @@ -430,6 +430,64 @@ cluster: - echo "workers command after kubeadm" ``` +### Systemd unit templating + +You can pass Helm templating syntax through from cluster-\ charts which will be rendered by the cluster chart. This is +written as plain text within the cluster-\ chart values under the `additionalFields` key. Consider the following: + +``` +global: + connectivity: + network: + staticRoutes: + - destination: 10.2.3.0/24 + via: 10.9.8.7 + - destination: 10.20.30.0/24 + via: 10.9.8.7 +cluster: + providerIntegration: + kubeadmConfig: + # ignition for both control plane and worker nodes + ignition: + containerLinuxConfig: + additionalConfig: + systemd: + units: + - contents: + install: + wantedBy: + - multi-user.target + service: + additionalFields: |- + {{- if $.global.connectivity.network.staticRoutes }} + {{- range $.global.connectivity.network.staticRoutes }} + ExecStart=/usr/bin/bash -cv 'ip route add {{ .destination }} via {{ .via }}' + {{- end }} + {{- end }} + unit: + requires: + - coreos-metadata.service +``` + +This results in the following unit: + +``` +[Unit] +Requires=coreos-metadata.service +[Service] +ExecStart=/usr/bin/bash -cv 'ip route add 10.2.3.0/24 via 10.9.8.7' +ExecStart=/usr/bin/bash -cv 'ip route add 10.20.30.0/24 via 10.9.8.7' +[Install] +WantedBy=multi-user.target +``` + +The Helm templating syntax is treated as plain text by the provider chart. The cluster chart's templating function has +access to the values under the provider chart's `.global` key so any values referenced in the template must exist +under `.global`. + +Note that variable scoping is important here - the templating function does not have access to the root `$.Values` object, +so any variables under `.global` must be referenced as `.global.some.var` (not `$.Values.global.some.var`). + ## Workload cluster configuration Workload clusters can be configured by setting Helm values in two top-level objects: From f2c8e070a07a42332a102195e7baaabe76522726 Mon Sep 17 00:00:00 2001 From: Simon Weald Date: Tue, 1 Oct 2024 09:23:09 +0100 Subject: [PATCH 7/7] tiniest nitpick --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 744be80a..84b71113 100644 --- a/README.md +++ b/README.md @@ -486,7 +486,7 @@ access to the values under the provider chart's `.global` key so any values refe under `.global`. Note that variable scoping is important here - the templating function does not have access to the root `$.Values` object, -so any variables under `.global` must be referenced as `.global.some.var` (not `$.Values.global.some.var`). +so any variables under `.global` must be referenced as `$.global.some.var` (not `$.Values.global.some.var`). ## Workload cluster configuration