759ed21b37
Build flock Image / build (push) Has been cancelled
Agent now watches nodeconfigs.flock.fritzlab.net via a client-go dynamic informer, filters events to its own node name, and caches the typed NodeConfig in memory (NodeConfigCache, atomic pointer). M2's IPAM will read from that cache. - pkg/agent/nodeconfig.go: informer + JSON-round-trip decode (avoids hand-written DeepCopy + scheme registration for this small a use). - pkg/agent/server.go: starts the informer goroutine; Run terminates if the informer returns. - pkg/api/v1alpha1: switch placeholder TypeMeta/ObjectMeta to metav1. - deploy/rbac: get/list/watch on nodeconfigs. - cmd/flock-agent: --kubeconfig flag for out-of-cluster runs (tests). Satisfies M1 verified-by: "kubectl apply NodeConfig; agent logs read it". Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
// Command flock-agent is the per-node DaemonSet binary. It owns IPAM, netns
|
|
// programming, BIRD config, and nftables. M1 boots only the state store and a
|
|
// placeholder unix listener.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"code.fritzlab.net/fritzlab/flock/pkg/agent"
|
|
)
|
|
|
|
func main() {
|
|
var (
|
|
node = flag.String("node", os.Getenv("NODE_NAME"), "node name (defaults to $NODE_NAME)")
|
|
statePath = flag.String("state", "/var/lib/flock/allocations.json", "path to allocations.json")
|
|
socket = flag.String("socket", agent.SocketPath, "unix socket for CNI RPC")
|
|
kubeconfig = flag.String("kubeconfig", os.Getenv("KUBECONFIG"), "kubeconfig path (empty = in-cluster)")
|
|
)
|
|
flag.Parse()
|
|
|
|
logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo}))
|
|
|
|
if *node == "" {
|
|
logger.Error("--node or $NODE_NAME is required")
|
|
os.Exit(2)
|
|
}
|
|
|
|
srv, err := agent.NewServer(agent.Config{
|
|
Node: *node,
|
|
StatePath: *statePath,
|
|
Socket: *socket,
|
|
Logger: logger,
|
|
Kubeconfig: *kubeconfig,
|
|
})
|
|
if err != nil {
|
|
logger.Error("init server", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer cancel()
|
|
|
|
if err := srv.Run(ctx); err != nil {
|
|
logger.Error("run", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|