Skip to content

Commit

Permalink
Merge pull request #1142 from kube-hetzner/fix/user-kustomization
Browse files Browse the repository at this point in the history
Fix for flawed user kustomization
  • Loading branch information
mysticaltech authored Dec 30, 2023
2 parents c7120eb + 68f23cb commit 3cd66f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 44 deletions.
4 changes: 2 additions & 2 deletions init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ resource "null_resource" "first_control_plane" {
provisioner "remote-exec" {
inline = [
"systemctl start k3s",
# prepare the post_install directory
"mkdir -p /var/post_install",
# prepare the needed directories
"mkdir -p /var/post_install /var/user_kustomize",
# wait for k3s to become ready
<<-EOT
timeout 120 bash <<EOF
Expand Down
46 changes: 4 additions & 42 deletions kustomization_user.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@ locals {
user_kustomization_templates = try(fileset("extra-manifests", "*.yaml.tpl"), toset([]))
}

resource "null_resource" "kustomization_user_setup" {
count = length(local.user_kustomization_templates) > 0 ? 1 : 0

connection {
user = "root"
private_key = var.ssh_private_key
agent_identity = local.ssh_agent_identity
host = module.control_planes[keys(module.control_planes)[0]].ipv4_address
port = var.ssh_port
}

# Create remote directory
provisioner "remote-exec" {
inline = [
"echo 'Create new /var/user_kustomize directory...'",
"rm -rf /var/user_kustomize && mkdir -p /var/user_kustomize"
]
}

# Copy all files, recursively from extra-manifests/ into the /var/user_kustomize directory.
# NOTE: If non *.yaml.tpl files are changed, you need to taint this resource to re-provision the changes,
# since there is no 'triggers {}' definition that watches all files/directories for changes.
provisioner "file" {
source = "extra-manifests/"
destination = "/var/user_kustomize"
}

depends_on = [
null_resource.kustomization
]
}

resource "null_resource" "kustomization_user" {
for_each = local.user_kustomization_templates

Expand All @@ -54,14 +22,8 @@ resource "null_resource" "kustomization_user" {
manifest_sha1 = "${sha1(templatefile("extra-manifests/${each.key}", var.extra_kustomize_parameters))}"
}

lifecycle {
replace_triggered_by = [
null_resource.kustomization_user_setup
]
}

depends_on = [
null_resource.kustomization_user_setup[0]
null_resource.kustomization
]
}

Expand All @@ -81,9 +43,9 @@ resource "null_resource" "kustomization_user_deploy" {
# Debugging: "sh -c 'for file in $(find /var/user_kustomize -type f -name \"*.yaml\" | sort -n); do echo \"\n### Template $${file}.tpl after rendering:\" && cat $${file}; done'",
inline = compact([
"rm -f /var/user_kustomize/*.yaml.tpl",
"echo 'Deploying manifests from /var/user_kustomize/:' && ls -alh /var/user_kustomize",
"kubectl kustomize /var/user_kustomize/ | kubectl apply --wait=true -f -",
"${var.extra_kustomize_deployment_commands}"
"echo 'Applying user kustomization...",
"kubectl apply -k /var/user_kustomize/ --wait=true",
var.extra_kustomize_deployment_commands
])
}

Expand Down

0 comments on commit 3cd66f1

Please sign in to comment.