31fcae2a97
Build flock Image / build (push) Has been cancelled
Locks the wire format between /opt/cni/bin/flock and flock-agent. ADD returns a CNI Result, DEL returns success/error, CHECK returns success/error. Connection-per-RPC, newline-delimited JSON. - pkg/cni/rpc.go: shared Op + Request + Response + framed encode/decode. - pkg/cni/rpc_client.go: net.Dial + EncodeRequest + DecodeResponse; rpcSocket overridable for tests. - pkg/cni/plugin.go: real implementations of CmdAdd/Del/Check that call through, mapping agent errors to types.Error. - pkg/agent/rpc.go: rpcServer with swappable AddHandler/DelHandler/ CheckHandler (defaults: not-implemented for ADD; idempotent-no-op for DEL/CHECK so kubelet teardown of a never-ADDed pod doesn't fail). - pkg/agent/server.go: replaces the M1 accept-and-close placeholder with rpcServer.serve(ctx, listener); listener closes on ctx cancel. Tests cover: Request/Response JSON roundtrip, end-to-end client → unix-socket → fake server, agent error → CNI types.Error mapping. ADD remains "not implemented" until netlink + IPAM wire-up — the agent returns an error and kubelet will fail pod sandbox creation IF a node were configured to use this CNI. host001's CNI plane is still 100% Calico, so this changes nothing observable on the cluster. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
// Package cni hosts the CNI plugin entry-points. The plugin binary is short-
|
|
// lived: it is invoked by kubelet, talks to flock-agent over a unix socket,
|
|
// and exits. All real work happens in the agent.
|
|
package cni
|
|
|
|
import (
|
|
"github.com/containernetworking/cni/pkg/skel"
|
|
"github.com/containernetworking/cni/pkg/types"
|
|
current "github.com/containernetworking/cni/pkg/types/100"
|
|
)
|
|
|
|
// SocketPath is the unix socket exposed by flock-agent.
|
|
const SocketPath = "/run/flock/flock.sock"
|
|
|
|
// CmdAdd is invoked by kubelet when a pod sandbox is created.
|
|
func CmdAdd(args *skel.CmdArgs) error {
|
|
resp, err := call(fromArgs(OpAdd, args))
|
|
if err != nil {
|
|
return types.NewError(types.ErrInternal, "flock-add", err.Error())
|
|
}
|
|
if cerr := toCNIError("add", resp); cerr != nil {
|
|
return cerr
|
|
}
|
|
if resp.Result == nil {
|
|
return types.NewError(types.ErrInternal, "flock-add", "agent returned no result")
|
|
}
|
|
return types.PrintResult(resp.Result, current.ImplementedSpecVersion)
|
|
}
|
|
|
|
// CmdDel is invoked by kubelet when a pod sandbox is torn down. CNI spec:
|
|
// DEL must be idempotent. The agent treats a missing allocation as success.
|
|
func CmdDel(args *skel.CmdArgs) error {
|
|
resp, err := call(fromArgs(OpDel, args))
|
|
if err != nil {
|
|
// On dial failure during DEL, fail loudly — kubelet retries DEL,
|
|
// and the next attempt may succeed once the agent is reachable.
|
|
return types.NewError(types.ErrInternal, "flock-del", err.Error())
|
|
}
|
|
return toCNIError("del", resp)
|
|
}
|
|
|
|
// CmdCheck verifies that the live netns matches the persisted allocation.
|
|
func CmdCheck(args *skel.CmdArgs) error {
|
|
resp, err := call(fromArgs(OpCheck, args))
|
|
if err != nil {
|
|
return types.NewError(types.ErrInternal, "flock-check", err.Error())
|
|
}
|
|
return toCNIError("check", resp)
|
|
}
|