ip-algo: pod annotation > NodeConfig annotation > random
Build flock Image / build (push) Has been cancelled

Add flock.fritzlab.net/ip-algo as a node-wide default via NodeConfig
metadata.annotations. Pod-level annotation still wins. Empty, missing,
or invalid input at either level falls through to the next; invalid
values warn-log via the agent's slog. Both unset → fully random IID
(unchanged baseline).

ParseAnnotations no longer touches ip-algo; ResolveIPAlgo handles the
full precedence chain, called from PodHandler.Add with the cached
NodeConfig's annotations and the agent logger.

Tests: 9 new TestResolveIPAlgo_* cases covering pod-wins, all
fall-through paths, both-absent, nil node map, whitespace, and
duplicate-as-invalid. Fuzz target rebuilt without ip-algo input space
(now exercised by ResolveIPAlgo unit tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Donavan Fritz
2026-04-25 11:09:09 -05:00
parent a6202a36bd
commit c860e9351b
5 changed files with 184 additions and 67 deletions
+11 -2
View File
@@ -3,6 +3,7 @@ package agent
import (
"context"
"fmt"
"log/slog"
"net"
"time"
@@ -22,6 +23,7 @@ type PodHandler struct {
IPAM *IPAM
Pods *PodCache
NodeConfig *NodeConfigCache
Logger *slog.Logger
// SetupFunc and TeardownFunc are injected at startup; in production
// they point at the Linux netlink ops, in tests they're fakes.
SetupFunc func(SetupRequest) error
@@ -49,12 +51,19 @@ func (h *PodHandler) Add(ctx context.Context, req flockcni.Request) (*current.Re
return nil, fmt.Errorf("lookup pod: %w", err)
}
defaults := FamilyDefaultsFromNodeConfig(h.NodeConfig.Load())
nc := h.NodeConfig.Load()
defaults := FamilyDefaultsFromNodeConfig(nc)
parsed, err := ParseAnnotations(pod.Annotations, defaults)
if err != nil {
return nil, fmt.Errorf("parse annotations: %w", err)
}
var nodeAnn map[string]string
if nc != nil {
nodeAnn = nc.GetAnnotations()
}
ipAlgo := ResolveIPAlgo(pod.Annotations, nodeAnn, h.Logger)
allocReq := AllocRequest{
ContainerID: req.ContainerID,
Namespace: args.PodNamespace,
@@ -63,7 +72,7 @@ func (h *PodHandler) Add(ctx context.Context, req flockcni.Request) (*current.Re
WantV4: parsed.WantV4,
AnnCIDR6: parsed.CIDR6,
AnnCIDR4: parsed.CIDR4,
IPAlgo: parsed.IPAlgo,
IPAlgo: ipAlgo,
}
res, err := h.IPAM.Allocate(allocReq)
if err != nil {