Skip to content

Commit 453fa10

Browse files
committed
Apply recommendations from gemini to user_kustomization
1 parent 59d18bf commit 453fa10

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

kube.tf.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,8 @@ module "kube-hetzner" {
968968
# 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 {}.
969969
# pre_commands: Commands to be executed before applying the Kustomization ("kubectl apply -k"). Defaults to "".
970970
# 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 || exit 0` (The `|| exit 0` is not "required", it just makes the deployment to continue even if a deployment hasn't started up properly)
971+
# - An example to wait for deployments in all namespaces: `kubectl wait --for=condition=Available deployment --all -A --timeout=120s || exit 0` (The `|| exit 0` is completely optional; it allows the script to proceed even if the wait command times out and fails, preventing the entire sequence from being aborted.)
972+
# - It is recommended to use a more specific `kubectl wait`-commands depending on the case and filter according to certain deployment or a pod.
972973
# - You can pass full bash-compatible scripts into the `post_commands`-variable with EOT
973974
#
974975
# An example from the default values:

modules/user_kustomizations/main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,20 @@ resource "null_resource" "kustomization_user_deploy" {
4242
inline = [
4343
<<-EOT
4444
#!/bin/bash
45+
set -e
46+
47+
function cleanup {
48+
echo "Cleaning up ${local.base_destination_folder}..."
49+
rm -rf ${local.base_destination_folder}
50+
}
51+
trap cleanup EXIT
52+
4553
for dest_folder in ${join(" ", local.sorted_kustomization_destination_folders)}; do
4654
if [ -d "$dest_folder" ]; then
4755
echo "Running pre-install script from $dest_folder"
4856
/bin/bash "$dest_folder/preinstall.sh"
4957
50-
if [ -f "$dest_folder/kustomization.yaml" ]; then
58+
if [ -s "$dest_folder/kustomization.yaml" ]; then
5159
echo "Applying kustomization from $dest_folder"
5260
kubectl apply -k "$dest_folder"
5361
else
@@ -58,8 +66,6 @@ resource "null_resource" "kustomization_user_deploy" {
5866
/bin/bash "$dest_folder/postinstall.sh"
5967
fi
6068
done
61-
echo "Cleaning up ${local.base_destination_folder}..."
62-
rm -rf ${local.base_destination_folder}/*
6369
EOT
6470
]
6571
}

modules/user_kustomizations/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ variable "kustomizations_map" {
2626
validation {
2727
condition = alltrue([
2828
for key in keys(var.kustomizations_map) :
29-
tonumber(key) > 0 && floor(tonumber(key)) == tonumber(key) && can(regex("^[0-9]+$", key))
29+
can(regex("^[0-9]+$", key)) && tonumber(key) > 0
3030
])
3131
error_message = "All keys in kustomizations_map must be numeric strings (e.g., '1', '2')."
3232
}

0 commit comments

Comments
 (0)