Skip to content

Commit 461151d

Browse files
committed
Replace references to extra_kustomize_* with the usage of user_kustomizations[]
1 parent 527129e commit 461151d

File tree

7 files changed

+83
-75
lines changed

7 files changed

+83
-75
lines changed

MIGRATION.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Migration advice when updating the module
2+
3+
# 2.18.3 -> 2.19.0
4+
5+
## Extra_kustomization
6+
The extra_kustomization-feature has been moved to a module so that multiple extra_kustomizations can be run in sequential steps.
7+
A new variable `user_kustomizations` is now in use, which contains the previous extra_kustomize_* vars.
8+
9+
### Affects
10+
If you are using helms from `extra-manifests`-folder or if you are using any of the following variables: `extra_kustomize_deployment_commands`, `extra_kustomize_parameters` or `extra_kustomize_folder`.
11+
12+
### Steps
13+
14+
1. Create a new variable `user_kustomizations`, see below and the kube.tf.example.
15+
16+
```
17+
user_kustomizations = {
18+
"1" = {
19+
source_folder = "extra-manifests" # Place here the source-folder defined previously in `var.extra_kustomize_folder`. If `var.extra_kustomize_folder` was previously undefined, leave as "extra-manifests".
20+
21+
kustomize_parameters = {} # Replace with contents of `var.extra_kustomize_parameters`. If `var.extra_kustomize_parameters` was previously undefined, remove the line or keep the default {}.
22+
23+
pre_commands = ""
24+
25+
post_commands = "" # Replace with contents of `var.extra_kustomize_deployment_commands`. If `var.extra_kustomize_deployment_commands` was previously undefined, remove the line or keep the default "".
26+
27+
}
28+
}
29+
```
30+
31+
2. After placing the variables, remove the variables `extra_kustomize_deployment_commands`, `extra_kustomize_parameters` and `extra_kustomize_folder` from kube.tf.

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ See the [guide on adding robot servers](docs/add-robot-server.md)
318318

319319
If you need to install additional Helm charts or Kubernetes manifests that are not provided by default, you can easily do so by using [Kustomize](https://kustomize.io). This is done by creating one or more `extra-manifests/kustomization.yaml.tpl` files beside your `kube.tf`.
320320

321-
These files need to be valid `Kustomization` manifests, additionally supporting terraform templating! (The templating parameters can be passed via the `extra_kustomize_parameters` variable (via a map) to the module).
321+
These files need to be valid `Kustomization` manifests, additionally supporting terraform templating! (The templating parameters can be passed via the `user_kustomizations` variable (via a map) to the module).
322322

323323
All files in the `extra-manifests` directory and its subdirectories including the rendered versions of the `*.yaml.tpl` will be applied to k3s with `kubectl apply -k` (which will be executed after and independently of the basic cluster configuration).
324324

325-
If you'd like to use a different folder name or apply the kustomizations in multiple steps due to CRD installation etc, you can override the values using `user_kustomizations`-variable. Note! This will override `extra_kustomize_deployment_commands` and `extra_kustomize_parameters`, so you will need to move them into the `user_kustomizations`-variable.
325+
If you'd like to use a different folder name, specify the template parameters or apply the kustomizations in multiple steps due to CRD installation etc, you can override the values using `user_kustomizations`-variable, see below:
326326

327327
Example of using user_kustomizations in `kube.tf`:
328328
```
@@ -333,7 +333,7 @@ Example of using user_kustomizations in `kube.tf`:
333333
"2" = {
334334
source_folder = "extra-manifests"
335335
kustomize_parameters = {key: "LowSecretKey"}
336-
post_commands = var.extra_kustomize_deployment_commands
336+
post_commands = "kubectl wait --for=condition=Available deployment --all -A --timeout=120s || true"
337337
}
338338
}
339339
```
@@ -356,8 +356,6 @@ However, some applications that e.g. provide custom CRDs (e.g. [ArgoCD](https://
356356

357357
To support these scenarios, you can use the `user_kustomizations` variable in your `kube.tf`. This allows you to define multiple "sets" of kustomizations that are applied sequentially. Each set can have its own `source_folder`, `kustomize_parameters`, and `pre_commands`/`post_commands` for running scripts before or after the `kubectl apply -k`.
358358

359-
For backward compatibility, if `user_kustomizations` is not defined, the module uses the `extra_kustomize_parameters` and `extra_kustomize_deployment_commands` with `extra-manifests` being the source folder.
360-
361359
### Example: external-secrets repo and Helm
362360
You can install Helm repos and CRDs before the main Kustomization scripts by adding the Helm charts a different folder, e.g. `extra-manifests-preinstall` and specifying the folder in `user_kustomizations`-settings.
363361

docs/llms.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,33 +2201,34 @@ Locked and loaded! Let's continue the detailed exploration.
22012201
**Section 2.21: Kustomize and Post-Deployment Operations**
22022202

22032203
```terraform
2204-
# Extra commands to be executed after the `kubectl apply -k` (useful for post-install actions, e.g. wait for CRD, apply additional manifests, etc.).
2205-
# extra_kustomize_deployment_commands=""
2204+
# You can add user kustomizations to be deployed in sequence by setting the `user_kustomizations` variable.
2205+
# The Kustomization "sets" are run in sequential order (by numeric key) so that you can for example install a CRD and wait for it to be deployed.
2206+
#
2207+
# Properties of each value:
2208+
# - source_folder: Sets the source folder for *.yaml.tpl and Kustomization.yaml.tpl
2209+
# - kustomize_parameters: Key-value map for passing variables into Kustomization. Applies only to the Kustomization-set in the object, but to all files defined in the source_folder of the "set". Defaults to {}.
2210+
# - pre_commands: Commands to be executed before applying the Kustomization ("kubectl apply -k"). Defaults to "".
2211+
# - post_commands: Commands to be executed after applying the Kustomization ("kubectl apply -k"). You can use it to wait for CRD deployment etc. Defaults to "".
2212+
# -- An example to wait for deployments in all namespaces: `kubectl wait --for=condition=Available deployment --all -A --timeout=120s || true` (The `|| true` is necessary to prevent the script from exiting on a timeout if you want the sequence to continue.)
2213+
# -- It is recommended to use more specific `kubectl wait` commands depending on the case, for example filtering for a certain deployment or pod.
2214+
# -- You can pass full bash-compatible scripts into the `post_commands`-variable with EOT
2215+
#
2216+
# An example:
2217+
# user_kustomizations = {
2218+
# "1" = {
2219+
# source_folder = "extra-manifests"
2220+
# kustomize_parameters = { myvar = "myvalue" }
2221+
# pre_commands = ""
2222+
# post_commands = "kubectl wait --for=condition=Available deployment --all -A --timeout=120s || true"
2223+
# }
2224+
# }
22062225
```
22072226

2208-
* **`extra_kustomize_deployment_commands` (String or List of Strings, Optional):**
2209-
* **Purpose:** Allows you to specify shell commands that will be executed *after* the module has run its main Kustomize deployment (which applies manifests for core components like CCM, CSI, Ingress, etc., based on your selections).
2210-
* **Mechanism:** The module likely uses a `local-exec` or `remote-exec` provisioner (if commands need to run on a node) to execute these. If they are `kubectl` commands, they'd run from where Terraform is executed, using the generated kubeconfig.
2227+
* **`user_kustomizations` (Map of Objects, Optional):**
2228+
* **Purpose:** Allows you to specify Kustomization sets that are run sequantially, with each set containing its own source_folder, pre_commands, post_commands and kustomize_parameters
22112229
* **Use Cases:**
2212-
* **Waiting for CRDs:** Some applications deployed via Helm or Kustomize install CustomResourceDefinitions (CRDs) first, and then CustomResources (CRs) that depend on those CRDs. There can be a race condition if the CRs are applied before the CRDs are fully registered. You could add a command here to wait for CRDs to become available (e.g., `kubectl wait --for condition=established crd/mycrd.example.com --timeout=120s`).
2213-
* Applying additional Kubernetes manifests that depend on the core setup.
2214-
* Running post-install scripts or triggering initial application setup jobs.
2215-
* **Format:** Can be a single string with commands separated by `&&` or `\n`, or a list of individual command strings.
2216-
2217-
```terraform
2218-
# Extra values that will be passed to the `extra-manifests/kustomization.yaml.tpl` if its present.
2219-
# extra_kustomize_parameters={}
2220-
```
2221-
2222-
* **`extra_kustomize_parameters` (Map of Strings, Optional):**
2223-
* **Purpose:** If you are using the module's "extra manifests" feature (where you can provide your own Kustomize setup in an `extra-manifests` directory), this map allows you to pass key-value parameters into a `kustomization.yaml.tpl` template file within that directory.
2224-
* **Mechanism:** The module would process `extra-manifests/kustomization.yaml.tpl` as a template, substituting placeholders with values from this map, and then run `kustomize build` on the result.
2225-
* **Use Case:** Parameterizing your custom Kustomize deployments based on Terraform inputs or computed values from the `kube-hetzner` module (e.g., passing in the cluster name, node IPs, etc., to your custom manifests).
2226-
* **Reference:** The comment points to examples in the module's repository for how to use this feature.
2227-
2228-
```terraform
2229-
# See working examples for extra manifests or a HelmChart in examples/kustomization_user_deploy/README.md
2230-
```
2230+
* Some applications deployed via Helm or Kustomize install CustomResourceDefinitions (CRDs) first, and then CustomResources (CRs) that depend on those CRDs. There can be a race condition if the CRs are applied before the CRDs are fully registered. You could add a command here to wait for CRDs to become available (e.g., `kubectl wait --for condition=established crd/mycrd.example.com --timeout=120s`).
2231+
* The `user_kustomzizations`-map allows you to define steps of install where e.g. the first step installs CRDs, checks for their proper existence and then second step that install further CRs.
22312232

22322233
* **Documentation Pointer:** This directs users to example usage of the "extra manifests" feature, which is crucial for extending the module's capabilities with custom deployments.
22332234

examples/kustomization_user_deploy/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Kube-Hetzner allows you to provide user-defined resources after the initial setu
44

55
When you execute terraform apply, the manifests in the extra-manifests directory, including the rendered versions of the `*.yaml.tpl` files, will be automatically deployed to the cluster.
66

7+
Note: If you would like to use a different folder, define the `user_kustomizations` in kube.tf.
8+
79
## Examples
810

911
Here are some examples of common use cases for deploying additional resources:
@@ -12,14 +14,18 @@ Here are some examples of common use cases for deploying additional resources:
1214
1315
### Deploying Simple Resources
1416

15-
The easiest use case is to deploy simple resources to the cluster. Since the Kustomize resources are [Terraform template](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) files, they can make use of parameters provided in the `extra_kustomize_parameters` map of the `kube.tf` file.
17+
The easiest use case is to deploy simple resources to the cluster. Since the Kustomize resources are [Terraform template](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) files, they can make use of parameters provided in the `kustomize_parameters` map of the `user_kustomizations`.
1618

1719
#### `kube.tf`
1820

1921
```
2022
...
21-
extra_kustomize_parameters = {
22-
my_config_key = "somestring"
23+
user_kustomizations = {
24+
...
25+
kustomize_parameters = {
26+
my_config_key = "somestring"
27+
}
28+
...
2329
}
2430
...
2531
```

kube.tf.example

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -953,35 +953,27 @@ module "kube-hetzner" {
953953
# More information about the registration can be found here https://rancher.com/docs/rancher/v2.6/en/cluster-provisioning/registered-clusters/
954954
# rancher_registration_manifest_url = "https://rancher.xyz.dev/v3/import/xxxxxxxxxxxxxxxxxxYYYYYYYYYYYYYYYYYYYzzzzzzzzzzzzzzzzzzzzz.yaml"
955955

956-
# Extra commands to be executed after the `kubectl apply -k` (useful for post-install actions, e.g. wait for CRD, apply additional manifests, etc.).
957-
# extra_kustomize_deployment_commands=""
958-
959-
# Extra values that will be passed to the `extra-manifests/kustomization.yaml.tpl`.
960-
# extra_kustomize_parameters={}
961-
962-
# You can add extra kustomizations to be deployed in sequence by setting the `user_kustomizations` variable.
963-
# This will override the use of `extra_kustomize_deployment_commands` and `extra_kustomize_parameters` for extra-manifests, hence they will need to be reset, see below.
964-
#
956+
# You can add user kustomizations to be deployed in sequence by setting the `user_kustomizations` variable.
965957
# The Kustomization "sets" are run in sequential order (by numeric key) so that you can for example install a CRD and wait for it to be deployed.
966958
#
967-
# source_folder: Sets the source folder for *.yaml.tpl and Kustomization.yaml.tpl
968-
# kustomize_parameters: Key-value map for passing variables into Kustomization. Applies only to the Kustomization-set in the object, but to all files defined in the source_folder of the "set". Defaults to {}.
969-
# pre_commands: Commands to be executed before applying the Kustomization ("kubectl apply -k"). Defaults to "".
970-
# post_commands: Commands to be executed after applying the Kustomization ("kubectl apply -k"). You can use it to wait for CRD deployment etc. Defaults to "".
971-
# - An example to wait for deployments in all namespaces: `kubectl wait --for=condition=Available deployment --all -A --timeout=120s || true` (The `|| true` is necessary to prevent the script from exiting on a timeout if you want the sequence to continue.)
972-
# - It is recommended to use more specific `kubectl wait` commands depending on the case, for example filtering for a certain deployment or pod.
973-
# - You can pass full bash-compatible scripts into the `post_commands`-variable with EOT
959+
# Properties of each value:
960+
# - source_folder: Sets the source folder for *.yaml.tpl and Kustomization.yaml.tpl
961+
# - kustomize_parameters: Key-value map for passing variables into Kustomization. Applies only to the Kustomization-set in the object, but to all files defined in the source_folder of the "set". Defaults to {}.
962+
# - pre_commands: Commands to be executed before applying the Kustomization ("kubectl apply -k"). Defaults to "".
963+
# - post_commands: Commands to be executed after applying the Kustomization ("kubectl apply -k"). You can use it to wait for CRD deployment etc. Defaults to "".
964+
# -- An example to wait for deployments in all namespaces: `kubectl wait --for=condition=Available deployment --all -A --timeout=120s || true` (The `|| true` is necessary to prevent the script from exiting on a timeout if you want the sequence to continue.)
965+
# -- It is recommended to use more specific `kubectl wait` commands depending on the case, for example filtering for a certain deployment or pod.
966+
# -- You can pass full bash-compatible scripts into the `post_commands`-variable with EOT
974967
#
975-
# An example from the default values:
968+
# An example:
976969
# user_kustomizations = {
977970
# "1" = {
978971
# source_folder = "extra-manifests"
979-
# kustomize_parameters = var.extra_kustomize_parameters # Same as `extra_kustomize_parameters` in kube.tf, replace with actual values if uncommenting
972+
# kustomize_parameters = { myvar = "myvalue" }
980973
# pre_commands = ""
981-
# post_commands = var.extra_kustomize_deployment_commands # Same as `extra_kustomize_deployment_commands` in kube.tf, replace with actual values if uncommenting
974+
# post_commands = "kubectl wait --for=condition=Available deployment --all -A --timeout=120s || true"
982975
# }
983976
# }
984-
985977
# See working examples for extra manifests or a HelmChart in examples/kustomization_user_deploy/README.md
986978

987979
# It is best practice to turn this off, but for backwards compatibility it is set to "true" by default.

kustomization_user.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
locals {
22
default_user_kustomize = {
33
"1" = {
4-
source_folder = var.extra_kustomize_folder
5-
kustomize_parameters = var.extra_kustomize_parameters
4+
source_folder = "extra-manifests"
5+
kustomize_parameters = {}
66
pre_commands = ""
7-
post_commands = var.extra_kustomize_deployment_commands
7+
post_commands = ""
88
}
99
}
1010

variables.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,26 +1068,6 @@ variable "postinstall_exec" {
10681068
description = "Additional to execute after the install calls, for example restoring a backup."
10691069
}
10701070

1071-
variable "extra_kustomize_deployment_commands" {
1072-
type = string
1073-
default = ""
1074-
description = "Commands to be executed after the `kubectl apply -k <dir>` step."
1075-
sensitive = true
1076-
}
1077-
1078-
variable "extra_kustomize_parameters" {
1079-
type = any
1080-
default = {}
1081-
description = "All values will be passed to the `kustomization.tmp.yml` template."
1082-
sensitive = true
1083-
}
1084-
1085-
variable "extra_kustomize_folder" {
1086-
type = string
1087-
default = "extra-manifests"
1088-
description = "Folder from where to upload extra manifests"
1089-
}
1090-
10911071
variable "user_kustomizations" {
10921072
type = map(object({
10931073
source_folder = string

0 commit comments

Comments
 (0)