Documentation
¶
Overview ¶
Package netns manages the per-host pool of prepaid network namespaces for the containerd engine. Bookkeeping lives in SQLite (container_netns_slots); CNI ADD/DEL and netns creation live in host.go — the same pool.go/host.go split as internal/network/tap.
Index ¶
- type Builder
- type FakeHost
- func (f *FakeHost) Realize(ctx context.Context, slot Slot) (string, string, error)
- func (f *FakeHost) RealizedCount() int
- func (f *FakeHost) Remove(ctx context.Context, slot Slot) error
- func (f *FakeHost) Removed() []string
- func (f *FakeHost) RemovedCount() int
- func (f *FakeHost) SetRealizeError(err error)
- func (f *FakeHost) SetRemoveError(err error)
- type Host
- type HostManager
- type LiveSandbox
- type NetnsExists
- type Pool
- func (p *Pool) Adopt(ctx context.Context, sandboxID string, now time.Time) (*Slot, error)
- func (p *Pool) ClaimPooled(ctx context.Context, sandboxID string, now time.Time) (*Slot, bool, error)
- func (p *Pool) Get(ctx context.Context, sandboxID string) (*Slot, error)
- func (p *Pool) MarkRealized(ctx context.Context, sandboxID, netnsPath, containerIP string, now time.Time) (*Slot, error)
- func (p *Pool) Prewarm(ctx context.Context, host HostManager, now time.Time) error
- func (p *Pool) ReassignOwner(ctx context.Context, fromSandboxID, toSandboxID string, now time.Time) error
- func (p *Pool) Reconcile(ctx context.Context, host HostManager, live LiveSandbox, exists NetnsExists, ...) (reaped int, err error)
- func (p *Pool) Release(ctx context.Context, sandboxID string, now time.Time) error
- func (p *Pool) Reserve(ctx context.Context, sandboxID string, now time.Time) (*Slot, error)
- func (p *Pool) RetryReleasing(ctx context.Context, host HostManager, now time.Time) (int, error)
- func (p *Pool) Seed(ctx context.Context, cfg SeedConfig, now time.Time) error
- func (p *Pool) SetLogger(logger *slog.Logger)
- func (p *Pool) Stats(ctx context.Context) (Stats, error)
- func (p *Pool) TargetDepth(ctx context.Context, depth int) (need int, err error)
- type Refiller
- type RuntimeHandoff
- type SeedConfig
- type Slot
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder sequences reserve → realize → adopt with LIFO teardown on failure.
func NewBuilder ¶
func NewBuilder(pool *Pool, host HostManager) *Builder
type FakeHost ¶
type FakeHost struct {
// contains filtered or unexported fields
}
FakeHost records realize/remove calls for tests. Like Host, it keys host state by Slot.netnsName, so a test that releases under the wrong identity leaves the realized entry behind exactly as a real node would.
func NewFakeHost ¶
func NewFakeHost() *FakeHost
func (*FakeHost) RealizedCount ¶
func (*FakeHost) Removed ¶ added in v0.6.9
Removed returns the netns names Remove was called with, in order.
func (*FakeHost) RemovedCount ¶
func (*FakeHost) SetRealizeError ¶
func (*FakeHost) SetRemoveError ¶
type Host ¶
Host is the production HostManager. NetnsRoot is typically /run/netns.
func (*Host) DisableIPv6 ¶ added in v0.6.9
DisableIPv6 turns IPv6 off in an already-realized slot's netns. Reconcile runs it on every slot that survives a restart, so a warm slot an older daemon realized is not handed out with IPv6 on, and a running sandbox loses the link-local address it booted with. Idempotent.
func (*Host) IPv4Addrs ¶ added in v0.6.9
IPv4Addrs lists the IPv4 addresses inside an already-realized slot's netns: the address a task started there comes up at. Reconcile compares it with the address the slot's row records before a warm slot that outlived a restart is handed out again.
func (*Host) Remove ¶
Remove deletes everything Realize created for slot: the CNI attachment (veth, host-local lease, masquerade chain), conntrack entries and the named netns. It uses the same identity Realize used (Slot.netnsName), whoever owns the slot now. Errors are joined, never swallowed: the pool keeps a slot out of circulation until Remove succeeds.
type HostManager ¶
type HostManager interface {
Realize(ctx context.Context, slot Slot) (netnsPath string, ip string, err error)
Remove(ctx context.Context, slot Slot) error
}
HostManager realizes reserved slots: create netns, CNI ADD, and inverse on Remove. Idempotent Ensure/Remove mirrors tap.HostManager.
type LiveSandbox ¶
LiveSandbox reports whether sandboxID still has a live containerd workload.
type NetnsExists ¶
NetnsExists checks whether a prepaid netns path is still present on disk.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is the policy layer over container_netns_slots.
func (*Pool) ClaimPooled ¶
func (p *Pool) ClaimPooled(ctx context.Context, sandboxID string, now time.Time) (*Slot, bool, error)
ClaimPooled tries the warm queue before a cold build. Returns (slot, true, nil) on hit; (_, false, nil) on miss.
func (*Pool) MarkRealized ¶
func (p *Pool) MarkRealized(ctx context.Context, sandboxID, netnsPath, containerIP string, now time.Time) (*Slot, error)
MarkRealized records CNI output after host realization.
func (*Pool) Prewarm ¶
Prewarm reserves a free slot under its slot_id, runs CNI ADD, and parks it in the pooled warm queue.
func (*Pool) ReassignOwner ¶
func (p *Pool) ReassignOwner(ctx context.Context, fromSandboxID, toSandboxID string, now time.Time) error
ReassignOwner moves an adopted slot from a park slot id to the real sandbox id.
func (*Pool) Reconcile ¶
func (p *Pool) Reconcile(ctx context.Context, host HostManager, live LiveSandbox, exists NetnsExists, now time.Time) (reaped int, err error)
Reconcile tears down orphaned reserved/realized/pooled/adopted rows after a crash or daemon restart, and retries slots parked as releasing. A warm (pooled) slot survives only when its netns is there AND holds the address the row records; otherwise it is rebuilt, never handed out. live==nil treats every adopted/reserved owner as dead, so production wiring must pass a callback that answers "dead" only when the owner's container is confirmed gone: reaping a live owner runs CNI DEL inside its netns and deletes it, cutting a running sandbox off the network.
func (*Pool) Release ¶
Release returns a sandbox's slot to the pool. Idempotent. It only moves the row; callers that own host state go through teardown.
func (*Pool) Reserve ¶
Reserve claims a slot for sandboxID. Idempotent for the same sandbox. A create reserves after a warm queue miss, to build inline, so this is where a miss wakes the refiller: only once the create holds its slot. Woken at the miss itself, the refill could take the last free slot first and fail a create that would have fit.
func (*Pool) RetryReleasing ¶ added in v0.6.9
RetryReleasing re-runs the host teardown for every slot parked as releasing and frees each one whose teardown now succeeds. Returns how many it freed.
type Refiller ¶
type Refiller struct {
// contains filtered or unexported fields
}
Refiller maintains the pooled warm depth. A create taking a slot wakes it (Pool.claimed); the ticker stays as the backstop for what no claim signals: a slot a release frees while the queue is short, a failed prewarm with no create behind it, and the retry of slots parked as releasing. Every pass runs on Run's one goroutine, so passes never overlap. That single flight is what keeps the queue at or under depth: TargetDepth counts only finished warm slots, so two passes at once would both fill the same gap.
func NewRefiller ¶
type RuntimeHandoff ¶
type RuntimeHandoff struct {
// contains filtered or unexported fields
}
RuntimeHandoff adapts the native netns pool to the containerd driver's NetnsHandoff seam: Provision runs the reserve→realize→adopt FSM; Release tears down host resources and returns the slot to the free pool.
func NewRuntimeHandoff ¶
func NewRuntimeHandoff(pool *Pool, host HostManager) *RuntimeHandoff
func (*RuntimeHandoff) ReassignOwner ¶
func (h *RuntimeHandoff) ReassignOwner(ctx context.Context, fromSandboxID, toSandboxID string) error
ReassignOwner transfers netns slot ownership from a park slot id to the adopted sandbox id (rename-free warm adopt).
func (*RuntimeHandoff) Release ¶
func (h *RuntimeHandoff) Release(ctx context.Context, sandboxID string) error
Release tears down sandboxID's netns and returns the slot to the pool. Idempotent. The host teardown uses the identity CNI ADD used (which is NOT sandboxID for a claimed prewarmed slot or an adopted warm-park slot). If it fails, the slot is parked as releasing and retried by the refiller rather than freed with its lease and NAT chain still on the node; Release still returns nil then, because the failure is owned by the retry from here on.
type SeedConfig ¶
type SeedConfig struct {
PoolSize int
}
SeedConfig describes how many native netns slots to pre-create at boot.
type Slot ¶
type Slot struct {
SlotID string
NetnsPath string
ContainerIP string
SandboxID string
State string
}
Slot is the pool-level view of a claimed netns slot.
type Stats ¶
type Stats = store.ContainerNetnsPoolStats