Initial upgrade flow for control-plane

This commit is contained in:
2026-04-06 23:49:39 +08:00
parent c6f89651ce
commit 578b3e6a6f
19 changed files with 563 additions and 42 deletions

View File

@@ -3,6 +3,8 @@ package agent
import (
"context"
"fmt"
"os"
"path/filepath"
"time"
"github.com/spf13/cobra"
@@ -50,6 +52,11 @@ func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command {
return fmt.Errorf("node name is empty in rendered config")
}
ctx := cmd.Context()
if err := waitForControlGate(ctx, envFile, 2*time.Second); err != nil {
return fmt.Errorf("wait for control gate to release: %w", err)
}
klog.InfoS("starting agent",
"node", cfg.Spec.NodeName,
"namespace", namespace,
@@ -62,7 +69,6 @@ func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command {
return fmt.Errorf("create kube clients: %w", err)
}
ctx := cmd.Context()
return runPollLoop(ctx, clients, namespace, cfg.Spec.NodeName, pollInterval)
},
}
@@ -74,6 +80,36 @@ func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command {
return cmd
}
func waitForControlGate(ctx context.Context, envFile string, pollInterval time.Duration) error {
dir := filepath.Dir(envFile)
marker := filepath.Join(dir, ".control-gate")
if pollInterval <= 0 {
pollInterval = 2 * time.Second
}
ticker := time.NewTicker(pollInterval)
defer ticker.Stop()
for {
_, err := os.Stat(marker)
if err == nil {
klog.InfoS("Control gate is present; waiting before starting poll loop", "path", marker)
} else if os.IsNotExist(err) {
klog.InfoS("Control gate not present; starting poll loop", "path", marker)
return nil
} else {
return fmt.Errorf("stat upgrade marker %s: %w", marker, err)
}
select {
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
}
}
}
func runPollLoop(ctx context.Context, clients *kube.Clients, namespace, nodeName string, interval time.Duration) error {
gvr := schema.GroupVersionResource{
Group: monov1alpha1.Group,