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) 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) Seed(ctx context.Context, cfg SeedConfig, now time.Time) error
- 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.
func NewFakeHost ¶
func NewFakeHost() *FakeHost
func (*FakeHost) RealizedCount ¶
func (*FakeHost) RemovedCount ¶
func (*FakeHost) SetRealizeError ¶
func (*FakeHost) SetRemoveError ¶
type Host ¶
Host is the production HostManager. NetnsRoot is typically /run/netns.
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. live==nil treats every adopted/reserved owner as dead.
type Refiller ¶
type Refiller struct {
// contains filtered or unexported fields
}
Refiller maintains the pooled warm depth on a ticker.
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).
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