fix: wait for talos installer reboot
This commit is contained in:
parent
795a6038f2
commit
64e9a6a7d9
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue