package libcni

import "github.com/containernetworking/cni/libcni"

Index

Constants

const (
	CNICacheV1 = "cniCacheV1"
)

Variables

var (
	CacheDir = "/var/lib/cni"
	// slightly awkward wording to preserve anyone matching on error strings
	ErrorCheckNotSupp = fmt.Errorf("does not support the CHECK command")
)

Functions

func ConfFiles

func ConfFiles(dir string, extensions []string) ([]string, error)

ConfFiles simply returns a slice of all files in the provided directory with extensions matching the provided set.

Types

type CNI

type CNI interface {
	AddNetworkList(ctx context.Context, net *NetworkConfigList, rt *RuntimeConf) (types.Result, error)
	CheckNetworkList(ctx context.Context, net *NetworkConfigList, rt *RuntimeConf) error
	DelNetworkList(ctx context.Context, net *NetworkConfigList, rt *RuntimeConf) error
	GetNetworkListCachedResult(net *NetworkConfigList, rt *RuntimeConf) (types.Result, error)
	GetNetworkListCachedConfig(net *NetworkConfigList, rt *RuntimeConf) ([]byte, *RuntimeConf, error)

	AddNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) (types.Result, error)
	CheckNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error
	DelNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error
	GetNetworkCachedResult(net *PluginConfig, rt *RuntimeConf) (types.Result, error)
	GetNetworkCachedConfig(net *PluginConfig, rt *RuntimeConf) ([]byte, *RuntimeConf, error)

	ValidateNetworkList(ctx context.Context, net *NetworkConfigList) ([]string, error)
	ValidateNetwork(ctx context.Context, net *PluginConfig) ([]string, error)

	GCNetworkList(ctx context.Context, net *NetworkConfigList, args *GCArgs) error
	GetStatusNetworkList(ctx context.Context, net *NetworkConfigList) error

	GetCachedAttachments(containerID string) ([]*NetworkAttachment, error)

	GetVersionInfo(ctx context.Context, pluginType string) (version.PluginInfo, error)
}

type CNIConfig

type CNIConfig struct {
	Path []string
	// contains filtered or unexported fields
}

func NewCNIConfig

func NewCNIConfig(path []string, exec invoke.Exec) *CNIConfig

NewCNIConfig returns a new CNIConfig object that will search for plugins in the given paths and use the given exec interface to run those plugins, or if the exec interface is not given, will use a default exec handler.

func NewCNIConfigWithCacheDir

func NewCNIConfigWithCacheDir(path []string, cacheDir string, exec invoke.Exec) *CNIConfig

NewCNIConfigWithCacheDir returns a new CNIConfig object that will search for plugins in the given paths use the given exec interface to run those plugins, or if the exec interface is not given, will use a default exec handler. The given cache directory will be used for temporary data storage when needed.

func (*CNIConfig) AddNetwork

func (c *CNIConfig) AddNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) (types.Result, error)

AddNetwork executes the plugin with the ADD command

func (*CNIConfig) AddNetworkList

func (c *CNIConfig) AddNetworkList(ctx context.Context, list *NetworkConfigList, rt *RuntimeConf) (types.Result, error)

AddNetworkList executes a sequence of plugins with the ADD command

func (*CNIConfig) CheckNetwork

func (c *CNIConfig) CheckNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error

CheckNetwork executes the plugin with the CHECK command

func (*CNIConfig) CheckNetworkList

func (c *CNIConfig) CheckNetworkList(ctx context.Context, list *NetworkConfigList, rt *RuntimeConf) error

CheckNetworkList executes a sequence of plugins with the CHECK command

func (*CNIConfig) DelNetwork

func (c *CNIConfig) DelNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error

DelNetwork executes the plugin with the DEL command

func (*CNIConfig) DelNetworkList

func (c *CNIConfig) DelNetworkList(ctx context.Context, list *NetworkConfigList, rt *RuntimeConf) error

DelNetworkList executes a sequence of plugins with the DEL command

func (*CNIConfig) GCNetworkList

func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList, args *GCArgs) error

GCNetworkList will do two things - dump the list of cached attachments, and issue deletes as necessary - issue a GC to the underlying plugins (if the version is high enough)

func (*CNIConfig) GetCachedAttachments

func (c *CNIConfig) GetCachedAttachments(containerID string) ([]*NetworkAttachment, error)

GetCachedAttachments returns a list of network attachments from the cache. The returned list will be filtered by the containerID if the value is not empty.

func (*CNIConfig) GetNetworkCachedConfig

func (c *CNIConfig) GetNetworkCachedConfig(net *PluginConfig, rt *RuntimeConf) ([]byte, *RuntimeConf, error)

GetNetworkCachedConfig copies the input RuntimeConf to output RuntimeConf with fields updated with info from the cached Config.

func (*CNIConfig) GetNetworkCachedResult

func (c *CNIConfig) GetNetworkCachedResult(net *PluginConfig, rt *RuntimeConf) (types.Result, error)

GetNetworkCachedResult returns the cached Result of the previous AddNetwork() operation for a network, or an error.

func (*CNIConfig) GetNetworkListCachedConfig

func (c *CNIConfig) GetNetworkListCachedConfig(list *NetworkConfigList, rt *RuntimeConf) ([]byte, *RuntimeConf, error)

GetNetworkListCachedConfig copies the input RuntimeConf to output RuntimeConf with fields updated with info from the cached Config.

func (*CNIConfig) GetNetworkListCachedResult

func (c *CNIConfig) GetNetworkListCachedResult(list *NetworkConfigList, rt *RuntimeConf) (types.Result, error)

GetNetworkListCachedResult returns the cached Result of the previous AddNetworkList() operation for a network list, or an error.

func (*CNIConfig) GetStatusNetworkList

func (c *CNIConfig) GetStatusNetworkList(ctx context.Context, list *NetworkConfigList) error

func (*CNIConfig) GetVersionInfo

func (c *CNIConfig) GetVersionInfo(ctx context.Context, pluginType string) (version.PluginInfo, error)

GetVersionInfo reports which versions of the CNI spec are supported by the given plugin.

func (*CNIConfig) ValidateNetwork

func (c *CNIConfig) ValidateNetwork(ctx context.Context, net *PluginConfig) ([]string, error)

ValidateNetwork checks that a configuration is reasonably valid. It uses the same logic as ValidateNetworkList) Returns a list of capabilities

func (*CNIConfig) ValidateNetworkList

func (c *CNIConfig) ValidateNetworkList(ctx context.Context, list *NetworkConfigList) ([]string, error)

ValidateNetworkList checks that a configuration is reasonably valid. - all the specified plugins exist on disk - every plugin supports the desired version.

Returns a list of all capabilities supported by the configuration, or error

type GCArgs

type GCArgs struct {
	ValidAttachments []types.GCAttachment
}

type NetworkAttachment

type NetworkAttachment struct {
	ContainerID    string
	Network        string
	IfName         string
	Config         []byte
	NetNS          string
	CniArgs        [][2]string
	CapabilityArgs map[string]interface{}
}

type NetworkConfig

type NetworkConfig = PluginConfig

Use PluginConfig instead of NetworkConfig, the NetworkConfig backwards-compat alias will be removed in a future release.

func ConfFromBytes

func ConfFromBytes(bytes []byte) (*NetworkConfig, error)

Deprecated: This file format is no longer supported, use NetworkConfXXX and NetworkPluginXXX functions

func ConfFromFile

func ConfFromFile(filename string) (*NetworkConfig, error)

Deprecated: This file format is no longer supported, use NetworkConfXXX and NetworkPluginXXX functions

func LoadConf

func LoadConf(dir, name string) (*NetworkConfig, error)

Deprecated: This file format is no longer supported, use NetworkConfXXX and NetworkPluginXXX functions

type NetworkConfigList

type NetworkConfigList struct {
	Name                   string
	CNIVersion             string
	DisableCheck           bool
	DisableGC              bool
	LoadOnlyInlinedPlugins bool
	Plugins                []*PluginConfig
	Bytes                  []byte
}

func ConfListFromBytes

func ConfListFromBytes(bytes []byte) (*NetworkConfigList, error)

func ConfListFromConf

func ConfListFromConf(original *PluginConfig) (*NetworkConfigList, error)

ConfListFromConf "upconverts" a network config in to a NetworkConfigList, with the single network as the only entry in the list.

Deprecated: Non-conflist file formats are unsupported, use NetworkConfXXX and NetworkPluginXXX functions

func ConfListFromFile

func ConfListFromFile(filename string) (*NetworkConfigList, error)

func LoadConfList

func LoadConfList(dir, name string) (*NetworkConfigList, error)

func LoadNetworkConf

func LoadNetworkConf(dir, name string) (*NetworkConfigList, error)

LoadNetworkConf looks at all the network configs in a given dir, loads and parses them all, and returns the first one with an extension of `.conf` that matches the provided network name predicate.

func NetworkConfFromBytes

func NetworkConfFromBytes(confBytes []byte) (*NetworkConfigList, error)

func NetworkConfFromFile

func NetworkConfFromFile(filename string) (*NetworkConfigList, error)

type NoConfigsFoundError

type NoConfigsFoundError struct {
	Dir string
}

func (NoConfigsFoundError) Error

func (e NoConfigsFoundError) Error() string

type NotFoundError

type NotFoundError struct {
	Dir  string
	Name string
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type PluginConfig

type PluginConfig struct {
	Network *types.PluginConf
	Bytes   []byte
}

func InjectConf

func InjectConf(original *PluginConfig, newValues map[string]interface{}) (*PluginConfig, error)

InjectConf takes a PluginConfig and inserts additional values into it, ensuring the result is serializable.

func NetworkPluginConfFromBytes

func NetworkPluginConfFromBytes(pluginConfBytes []byte) (*PluginConfig, error)

This will not validate that the plugins actually belong to the netconfig by ensuring that they are loaded from a directory named after the networkName, relative to the network config.

Since here we are just accepting raw bytes, the caller is responsible for ensuring that the plugin config provided here actually "belongs" to the networkconfig in question.

func NetworkPluginConfsFromFiles

func NetworkPluginConfsFromFiles(networkConfPath, networkName string) ([]*PluginConfig, error)

Given a path to a directory containing a network configuration, and the name of a network, loads all plugin definitions found at path `networkConfPath/networkName/*.conf`

type RuntimeConf

type RuntimeConf struct {
	ContainerID string
	NetNS       string
	IfName      string
	Args        [][2]string
	// A dictionary of capability-specific data passed by the runtime
	// to plugins as top-level keys in the 'runtimeConfig' dictionary
	// of the plugin's stdin data.  libcni will ensure that only keys
	// in this map which match the capabilities of the plugin are passed
	// to the plugin
	CapabilityArgs map[string]interface{}

	// DEPRECATED. Will be removed in a future release.
	CacheDir string
}

A RuntimeConf holds the arguments to one invocation of a CNI plugin excepting the network configuration, with the nested exception that the `runtimeConfig` from the network configuration is included here.

Source Files

api.go conf.go

Version
v1.3.0 (latest)
Published
Apr 7, 2025
Platform
js/wasm
Imports
14 packages
Last checked
6 days ago

Tools for package owners.