Initial upgrade flow for control-plane
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user