Can now reconcile

This commit is contained in:
2026-03-30 18:41:18 +08:00
parent 0aa4065c26
commit 68e7dcd001
7 changed files with 245 additions and 141 deletions

View File

@@ -2,6 +2,11 @@ package node
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"time"
system "undecided.project/monok8s/pkg/system"
)
@@ -9,3 +14,36 @@ import (
func StartKubelet(ctx context.Context, n *NodeContext) error {
return system.EnsureServiceRunning(ctx, n.SystemRunner, "kubelet")
}
func waitForKubeletHealthy(ctx context.Context, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
url := "http://127.0.0.1:10248/healthz"
client := &http.Client{
Timeout: 2 * time.Second,
}
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
for {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err == nil {
resp, err := client.Do(req)
if err == nil {
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode == http.StatusOK && strings.TrimSpace(string(body)) == "ok" {
return nil
}
}
}
select {
case <-ctx.Done():
return fmt.Errorf("kubelet health endpoint did not become ready: %w", ctx.Err())
case <-ticker.C:
}
}
}