cni

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CNI

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

CNI implements network.Network using CNI plugins with per-VM netns + bridge + tap.

func New

func New(conf *config.Config) (*CNI, error)

New creates a CNI network provider. CNI conflist loading is best-effort at creation time; if no conflist is available (e.g. no network needed), Delete/Inspect/List still work. Config() will fail if the conflist is not loaded.

func (*CNI) Config

func (c *CNI) Config(ctx context.Context, vmID string, numNICs int, vmCfg *types.VMConfig, existing ...*types.NetworkConfig) (configs []*types.NetworkConfig, retErr error)

Config creates the network namespace, runs CNI ADD for each NIC, sets up TC redirect (eth↔tap) inside the netns, and returns NetworkConfigs ready for CH --net.

Flow per NIC:

  1. Create named netns cocoon-{vmID}
  2. CNI ADD (containerID=vmID, netns path, ifName=eth{i})
  3. Inside netns: flush eth{i} IP, create tap{i}, wire via TC ingress mirred
  4. Return NetworkConfig{Tap: "tap{i}", Mac: generated, Network: CNI result}

func (*CNI) Delete

func (c *CNI) Delete(ctx context.Context, vmIDs []string) ([]string, error)

Delete removes all network resources for the given VM IDs:

  1. CNI DEL for each NIC (releases IP from IPAM, removes veth pair).
  2. Remove the named netns (kernel cleans up bridge + tap automatically).
  3. Remove network records from the DB.

Best-effort: failing to clean one VM does not block others. Returns the VM IDs that were fully cleaned.

func (*CNI) GCModule

func (c *CNI) GCModule() gc.Module[cniSnapshot]

GCModule returns the GC module for orphan netns and stale CNI record cleanup.

func (*CNI) Inspect

func (c *CNI) Inspect(ctx context.Context, id string) (*types.Network, error)

Inspect returns the network record for a single network ID. Returns (nil, nil) if not found.

func (*CNI) List

func (c *CNI) List(ctx context.Context) ([]*types.Network, error)

List returns all known network records.

func (*CNI) RegisterGC

func (c *CNI) RegisterGC(orch *gc.Orchestrator)

RegisterGC registers the CNI GC module with the given Orchestrator.

func (*CNI) Type

func (c *CNI) Type() string

func (*CNI) Verify

func (c *CNI) Verify(_ context.Context, vmID string) error

Verify checks whether the network namespace for a VM exists.

type Config

type Config struct {
	*config.Config
}

Config holds CNI network provider specific configuration, embedding the global config.

func (*Config) CacheDir

func (c *Config) CacheDir() string

func (*Config) EnsureDirs

func (c *Config) EnsureDirs() error

EnsureDirs creates all static directories required by the CNI network provider.

func (*Config) IndexFile

func (c *Config) IndexFile() string

func (*Config) IndexLock

func (c *Config) IndexLock() string

Jump to

Keyboard shortcuts

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