fix: wait for talos bootstrap readiness

This commit is contained in:
eding 2026-07-20 23:49:44 +02:00
parent df1a95f349
commit d80e3fac02

View file

@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/Pingu-Studio/MaidnCLI/internal/config"
"github.com/Pingu-Studio/MaidnCLI/internal/forgejo"
@ -65,10 +66,10 @@ func (r Runner) Run() error {
}
if r.Config.Talos.AutoBootstrap {
configFile := filepath.Join("clusterconfig", fmt.Sprintf("%s-%s.yaml", r.Config.Talos.Cluster.Name, r.Config.Talos.Nodes[0].Name))
if err := utils.RunCommandInDir(generatedDir, "talosctl", "apply-config", "--insecure", "--nodes="+r.Config.Talos.BootstrapNode, "--endpoints="+r.Config.Talos.BootstrapEndpoint, "--file="+configFile); err != nil {
if err := retryTalosCommand(generatedDir, "apply-config", "--insecure", "--nodes="+r.Config.Talos.BootstrapNode, "--endpoints="+r.Config.Talos.BootstrapEndpoint, "--file="+configFile); 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 {
if err := retryTalosCommand(generatedDir, "bootstrap", "--talosconfig=./clusterconfig/talosconfig", "--endpoints="+r.Config.Talos.BootstrapEndpoint, "--nodes="+r.Config.Talos.BootstrapNode); err != nil {
return err
}
if err := utils.RunCommandInDir(generatedDir, "talosctl", "kubeconfig", "--talosconfig=./clusterconfig/talosconfig", "--nodes="+r.Config.Talos.KubeconfigNode, "."); err != nil {
@ -96,6 +97,17 @@ func ensureRepo(dir, repoURL, ref string) error {
return utils.RunCommandInDir(dir, "git", "pull", "--ff-only", "origin", ref)
}
func retryTalosCommand(dir string, args ...string) error {
var err error
for range 120 {
if err = utils.RunCommandInDir(dir, "talosctl", args...); err == nil {
return nil
}
time.Sleep(5 * time.Second)
}
return err
}
func ensureTalosConfig(generatedDir string, cfg config.Config) error {
talhelperPath := "talhelper"
secretPath := filepath.Join(generatedDir, "talsecret.sops.yaml")