From 64e9a6a7d9c3eb290f833947f2d6340356e5d376 Mon Sep 17 00:00:00 2001 From: eding Date: Tue, 21 Jul 2026 23:05:40 +0200 Subject: [PATCH] fix: wait for talos installer reboot --- internal/bootstrap/bootstrap.go | 19 +++++++++++++++++++ internal/utils/helpers.go | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go index 5be9bc4..99d7cfb 100644 --- a/internal/bootstrap/bootstrap.go +++ b/internal/bootstrap/bootstrap.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/Pingu-Studio/MaidnCLI/internal/config" "github.com/Pingu-Studio/MaidnCLI/internal/forgejo" @@ -70,6 +71,9 @@ func (r Runner) Run() error { if err := utils.RunCommandInDir(generatedDir, "talosctl", "apply-config", "--insecure", "--nodes="+r.Config.Talos.BootstrapNode, "--endpoints="+r.Config.Talos.BootstrapEndpoint, "--file="+configFile); err != nil { return err } + if err := waitForTalosReboot(generatedDir, r.Config); err != nil { + return err + } if err := utils.RunCommandInDir(generatedDir, "talosctl", "bootstrap", "--talosconfig=./clusterconfig/talosconfig", "--endpoints="+r.Config.Talos.BootstrapEndpoint, "--nodes="+r.Config.Talos.BootstrapNode); err != nil { return err } @@ -85,6 +89,21 @@ func (r Runner) Run() error { return nil } +func waitForTalosReboot(dir string, cfg config.Config) error { + deadline := time.Now().Add(2 * time.Minute) + offline := false + for time.Now().Before(deadline) { + err := utils.RunCommandQuietInDir(dir, "talosctl", "get", "machinestatus", "--talosconfig=./clusterconfig/talosconfig", "--endpoints="+cfg.Talos.BootstrapEndpoint, "--nodes="+cfg.Talos.BootstrapNode) + if err != nil { + offline = true + } else if offline { + return nil + } + time.Sleep(2 * time.Second) + } + return fmt.Errorf("Talos API did not return after applying its machine configuration") +} + func ensureRepo(dir, repoURL, ref string) error { if _, err := os.Stat(dir); os.IsNotExist(err) { return utils.RunCommand("git", "clone", "--branch", ref, repoURL, dir) diff --git a/internal/utils/helpers.go b/internal/utils/helpers.go index c8b8e7c..6626618 100644 --- a/internal/utils/helpers.go +++ b/internal/utils/helpers.go @@ -44,6 +44,12 @@ func RunCommandInDir(dir string, name string, args ...string) error { return cmd.Run() } +func RunCommandQuietInDir(dir string, name string, args ...string) error { + cmd := exec.Command(name, args...) + cmd.Dir = dir + return cmd.Run() +} + func RunCommandOutput(name string, args ...string) ([]byte, error) { cmd := exec.Command(name, args...) var stdout bytes.Buffer