netns

package
v0.7.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 12 Imported by: 0

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

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

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, sandboxID string) (*Slot, error)

Build runs the FSM for sandboxID. On failure, teardown runs in reverse order.

type FakeHost

type FakeHost struct {
	// contains filtered or unexported fields
}

FakeHost records realize/remove calls for tests.

func NewFakeHost

func NewFakeHost() *FakeHost

func (*FakeHost) Realize

func (f *FakeHost) Realize(ctx context.Context, slot Slot) (string, string, error)

func (*FakeHost) RealizedCount

func (f *FakeHost) RealizedCount() int

func (*FakeHost) Remove

func (f *FakeHost) Remove(ctx context.Context, slot Slot) error

func (*FakeHost) RemovedCount

func (f *FakeHost) RemovedCount() int

func (*FakeHost) SetRealizeError

func (f *FakeHost) SetRealizeError(err error)

func (*FakeHost) SetRemoveError

func (f *FakeHost) SetRemoveError(err error)

type Host

type Host struct {
	Runner    cni.Runner
	NetnsRoot string
	// contains filtered or unexported fields
}

Host is the production HostManager. NetnsRoot is typically /run/netns.

func (*Host) Realize

func (h *Host) Realize(ctx context.Context, slot Slot) (string, string, error)

func (*Host) Remove

func (h *Host) Remove(ctx context.Context, slot Slot) error

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

type LiveSandbox func(ctx context.Context, sandboxID string) bool

LiveSandbox reports whether sandboxID still has a live containerd workload.

type NetnsExists

type NetnsExists func(path string) bool

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 New

func New(st *store.Store) *Pool

func (*Pool) Adopt

func (p *Pool) Adopt(ctx context.Context, sandboxID string, now time.Time) (*Slot, error)

Adopt marks the slot adopted once the container task is running.

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) Get

func (p *Pool) Get(ctx context.Context, sandboxID string) (*Slot, error)

Get returns the slot owned by sandboxID, or nil.

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

func (p *Pool) Prewarm(ctx context.Context, host HostManager, now time.Time) error

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.

func (*Pool) Release

func (p *Pool) Release(ctx context.Context, sandboxID string, now time.Time) error

Release returns a sandbox's slot to the pool. Idempotent.

func (*Pool) Reserve

func (p *Pool) Reserve(ctx context.Context, sandboxID string, now time.Time) (*Slot, error)

Reserve claims a slot for sandboxID. Idempotent for the same sandbox.

func (*Pool) Seed

func (p *Pool) Seed(ctx context.Context, cfg SeedConfig, now time.Time) error

Seed lays out PoolSize free slots. Idempotent on slot_id PK.

func (*Pool) Stats

func (p *Pool) Stats(ctx context.Context) (Stats, error)

func (*Pool) TargetDepth

func (p *Pool) TargetDepth(ctx context.Context, depth int) (need int, err error)

TargetDepth is the desired count of pooled+warm-ready slots.

type Refiller

type Refiller struct {
	// contains filtered or unexported fields
}

Refiller maintains the pooled warm depth on a ticker.

func NewRefiller

func NewRefiller(pool *Pool, host HostManager, depth int, interval time.Duration) *Refiller

func (*Refiller) Run

func (r *Refiller) Run(ctx context.Context)

func (*Refiller) Stop

func (r *Refiller) Stop()

Stop halts the refill loop.

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) Provision

func (h *RuntimeHandoff) Provision(ctx context.Context, sandboxID string) (netnsPath, containerIP string, err error)

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL