Documentation
¶
Index ¶
- Constants
- func BuildDefaultConflist(name, bridge, subnet string) ([]byte, error)
- func SafeBridgeName(name string) string
- type BootstrapReport
- type BridgeIPAMConfig
- type BridgePluginModel
- type Conf
- type ConflistModel
- type LoopbackPluginModel
- type Manager
- func (m *Manager) AddContainerToNetwork(ctx context.Context, containerID, netnsPath string) error
- func (m *Manager) CreateNetwork(networkName, bridgeName, subnetCIDR string) (string, error)
- func (m *Manager) CreateNetworkWithConfig(cfg NetworkConfig) (string, error)
- func (m *Manager) DelContainerFromNetwork(ctx context.Context, containerID, netnsPath string) error
- func (m *Manager) DeleteNetwork(networkName, configPath string) error
- func (m *Manager) ExistsNetworkConfig(networkName, configPath string) (bool, string, error)
- func (m *Manager) LoadNetworkConfigList(configPath string) error
- func (m *Manager) ReadBridgeName(configPath string) (string, error)
- type NetworkConfig
- type RouteModel
Constants ¶
const CNINetworksDir = "/var/lib/cni/networks"
CNINetworksDir is the standard directory where CNI stores network state and IPAM allocations. This is the default location used by CNI plugins for host-local IPAM.
Variables ¶
This section is empty.
Functions ¶
func BuildDefaultConflist ¶
BuildDefaultConflist generates a default conflist JSON using provided parameters.
func SafeBridgeName ¶ added in v0.2.0
SafeBridgeName derives a Linux-legal bridge device name from a CNI network name. Names within the IFNAMSIZ limit pass through unchanged; longer ones are deterministically truncated to a 6-char prefix plus an 8-hex-char FNV-1a suffix (total 15 chars) to preserve readability while staying unique. The empty string is preserved so callers can detect "unset".
Types ¶
type BootstrapReport ¶
type BootstrapReport struct {
CniConfigDir string
CniCacheDir string
CniBinDir string
ConfigDirExistsPre bool
CacheDirExistsPre bool
BinDirExistsPre bool
ConfigDirCreated bool
CacheDirCreated bool
BinDirCreated bool
ConfigDirExistsPost bool
CacheDirExistsPost bool
BinDirExistsPost bool
}
BootstrapReport captures CNI environment checks and actions.
func BootstrapCNI ¶
func BootstrapCNI(cfgDir, cacheDir, binDir string) (BootstrapReport, error)
BootstrapCNI ensures required directories exist and the bin directory is present. If any directory is empty, the defaults from config.go are used.
type BridgeIPAMConfig ¶
type BridgeIPAMConfig struct {
Type string `json:"type"`
Ranges [][]map[string]string `json:"ranges"`
Routes []RouteModel `json:"routes"`
}
BridgeIPAMConfig represents the IPAM configuration for the bridge plugin.
type BridgePluginModel ¶
type BridgePluginModel struct {
Type string `json:"type"`
Bridge string `json:"bridge"`
IsGateway bool `json:"isGateway"`
IPMasq bool `json:"ipMasq"`
IPAM BridgeIPAMConfig `json:"ipam"`
}
BridgePluginModel represents the bridge plugin configuration in a conflist.
type ConflistModel ¶
type ConflistModel struct {
CNIVersion string `json:"cniVersion"`
Name string `json:"name"`
Plugins []interface{} `json:"plugins"`
}
ConflistModel represents the structure of a CNI conflist file.
type LoopbackPluginModel ¶
type LoopbackPluginModel struct {
Type string `json:"type"`
}
LoopbackPluginModel represents the loopback plugin configuration in a conflist.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages CNI network operations.
func NewManager ¶
NewManager creates a new CNI manager with the provided directories. cniBinDir: where plugins live, e.g. /opt/cni/bin cniConfigDir: where network configs live, e.g. /opt/cni/net.d cniCacheDir: where CNI stores cache, e.g. /opt/cni/cache.
func (*Manager) AddContainerToNetwork ¶
AddContainerToNetwork adds a container to the CNI network.
func (*Manager) CreateNetwork ¶
CreateNetwork is a backward-compatible helper using discrete params.
func (*Manager) CreateNetworkWithConfig ¶
func (m *Manager) CreateNetworkWithConfig(cfg NetworkConfig) (string, error)
CreateNetworkWithConfig creates a CNI network conflist file using the provided NetworkConfig.
func (*Manager) DelContainerFromNetwork ¶
DelContainerFromNetwork removes a container from the CNI network.
func (*Manager) DeleteNetwork ¶
DeleteNetwork removes a CNI network config file from the filesystem.
func (*Manager) ExistsNetworkConfig ¶
ExistsNetworkConfig checks if a network config exists and matches the expected network name.
func (*Manager) LoadNetworkConfigList ¶
LoadNetworkConfigList loads a CNI network config list from the given path.
func (*Manager) ReadBridgeName ¶ added in v0.2.0
ReadBridgeName parses the conflist at configPath and returns the `bridge` field of the first plugin whose `type` is "bridge". Returns errdefs.ErrNetworkNotFound if the file is missing, errdefs.ErrBridgePluginMissing if no bridge plugin is present, and a wrapped JSON error for malformed content. The returned string may be empty when the bridge plugin has no `bridge` field, which callers should treat as a mismatch.
type NetworkConfig ¶
type NetworkConfig struct {
// Name is the CNI network name and the filename (without extension).
Name string
// BridgeName is the bridge device name. Defaults to "cni0" when empty.
BridgeName string
// SubnetCIDR is the IPAM subnet CIDR. Defaults to "10.88.0.0/16" when empty.
SubnetCIDR string
}
NetworkConfig represents the desired parameters for creating a CNI network.
func NewCNINetworkConfig ¶
func NewCNINetworkConfig(name string) NetworkConfig
NewCNINetworkConfig builds a NetworkConfig with sensible defaults.
type RouteModel ¶
type RouteModel struct {
Dst string `json:"dst"`
}
RouteModel represents a route in the IPAM configuration.