kube-hetzner / terraform-hcloud-kube-hetzner

Optimized and Maintenance-free Kubernetes on Hetzner Cloud in one command!
MIT License
2.31k stars 351 forks source link

[Feature Request]: Allow a reboot inside of preinstall_exec #1439

Closed mcosti closed 2 months ago

mcosti commented 2 months ago

Description

Hey everyone, thank you for this amazing terraform package, it's been a pleasure to use it.

I am currently trying to make a hybrid cluster using Tailscale and I want to include the install commands in the preinstall_exec, but the problem is that I need to reboot the servers for that.

Here is my code, checking in a hacky way if it's not a control plane:

  preinstall_exec = [
    "setenforce 0",
    "sudo zypper ar -g -r https://pkgs.tailscale.com/stable/opensuse/tumbleweed/tailscale.repo || true",
    "sudo transactional-update --non-interactive pkg in tailscale",
    "setenforce 1",

    // check if is control node based on hostname, if it contains "control" then it's a control node
    "if [[ $(hostname) != *control* ]]; then sudo shutdown -r 1; fi",
    "if [[ $(hostname) != *control* ]]; then sudo systemctl enable --now tailscaled || true; fi",
  ]

And this is the error I'm getting:

╷
│ Error: remote-exec provisioner error
│ 
│   with module.kube-hetzner.null_resource.agents["2-0-agent-database-small-fsn1"],
│   on .terraform/modules/kube-hetzner/agents.tf line 110, in resource "null_resource" "agents":
│  110:   provisioner "remote-exec" {
│ 
│ error executing "/tmp/terraform_1743271853.sh": wait: remote command exited without exit status or exit signal
╵
╷
│ Error: remote-exec provisioner error
│ 
│   with module.kube-hetzner.null_resource.agents["1-0-agent-medium-2-nbg1"],
│   on .terraform/modules/kube-hetzner/agents.tf line 110, in resource "null_resource" "agents":
│  110:   provisioner "remote-exec" {
│ 
│ error executing "/tmp/terraform_1267807957.sh": wait: remote command exited without exit status or exit signal
╵
╷
│ Error: remote-exec provisioner error
│ 
│   with module.kube-hetzner.null_resource.agents["0-0-agent-medium-1-fsn1"],
│   on .terraform/modules/kube-hetzner/agents.tf line 110, in resource "null_resource" "agents":
│  110:   provisioner "remote-exec" {
│ 
│ error executing "/tmp/terraform_719032720.sh": wait: remote command exited without exit status or exit signal

Somehow I'm sometimes able to install it if I run "terraform apply" a few times, but sometimes I just get stuck on this error.

Is there any way I could make this work? Thank you

mcosti commented 2 months ago

Nevermind, I solved this by customizing the MicroOS snapshot instead.