Documentation ¶
Index ¶
- Constants
- Variables
- func IsCNINotInitialized(err error) bool
- func IsInvalidConfig(err error) bool
- func IsInvalidResult(err error) bool
- func IsNotFound(err error) bool
- func IsReadFailure(err error) bool
- func WithAllConf(c *libcni) error
- func WithDefaultConf(c *libcni) error
- func WithLoNetwork(c *libcni) error
- type BandWidth
- type CNI
- type CNIOptdeprecated
- type CNIResultdeprecated
- type ConfNetwork
- type Config
- type ConfigResult
- type DNS
- type IPConfig
- type IPRanges
- type Namespace
- type NamespaceOpts
- func WithArgs(k, v string) NamespaceOpts
- func WithCapability(name string, capability interface{}) NamespaceOpts
- func WithCapabilityBandWidth(bandWidth BandWidth) NamespaceOpts
- func WithCapabilityCgroupPath(cgroupPath string) NamespaceOpts
- func WithCapabilityDNS(dns DNS) NamespaceOpts
- func WithCapabilityIPRanges(ipRanges []IPRanges) NamespaceOpts
- func WithCapabilityPortMap(portMapping []PortMapping) NamespaceOpts
- func WithLabels(labels map[string]string) NamespaceOpts
- type Network
- type NetworkConf
- type NetworkConfList
- type Opt
- func WithConf(bytes []byte) Opt
- func WithConfFile(fileName string) Opt
- func WithConfIndex(bytes []byte, index int) Opt
- func WithConfListBytes(bytes []byte) Opt
- func WithConfListFile(fileName string) Opt
- func WithInterfacePrefix(prefix string) Opt
- func WithMinNetworkCount(count int) Opt
- func WithPluginConfDir(dir string) Opt
- func WithPluginDir(dirs []string) Opt
- func WithPluginMaxConfNum(max int) Opt
- type PortMapping
- type Result
Constants ¶
const ( CNIPluginName = "cni" DefaultMaxConfNum = 1 DefaultPrefix = "eth" )
const ( DefaultNetDir = "/etc/cni/net.d" DefaultCNIDir = "/opt/cni/bin" VendorCNIDirTemplate = "%s/opt/%s/bin" )
Variables ¶
var ( ErrCNINotInitialized = errors.New("cni plugin not initialized") ErrInvalidConfig = errors.New("invalid cni config") ErrNotFound = errors.New("not found") ErrRead = errors.New("failed to read config file") ErrInvalidResult = errors.New("invalid result") ErrLoad = errors.New("failed to load cni config") )
Functions ¶
func IsCNINotInitialized ¶
IsCNINotInitialized returns true if the error is due to cni config not being initialized
func IsInvalidConfig ¶
IsInvalidConfig returns true if the error is invalid cni config
func IsInvalidResult ¶
IsInvalidResult return true if the error is due to invalid cni result
func IsNotFound ¶
IsNotFound returns true if the error is due to a missing config or result
func IsReadFailure ¶
IsReadFailure return true if the error is a config read failure
func WithAllConf ¶
func WithAllConf(c *libcni) error
WithAllConf can be used to detect all network config files from the configured cni config directory and load them.
func WithDefaultConf ¶
func WithDefaultConf(c *libcni) error
WithDefaultConf can be used to detect the default network config file from the configured cni config directory and load it. Since the CNI spec does not specify a way to detect default networks, the convention chosen is - the first network configuration in the sorted list of network conf files as the default network.
func WithLoNetwork ¶
func WithLoNetwork(c *libcni) error
WithLoNetwork can be used to load the loopback network config.
Types ¶
type BandWidth ¶
type BandWidth struct { IngressRate uint64 IngressBurst uint64 EgressRate uint64 EgressBurst uint64 }
BandWidth defines the ingress/egress rate and burst limits
type CNI ¶
type CNI interface { // Setup setup the network for the namespace Setup(ctx context.Context, id string, path string, opts ...NamespaceOpts) (*Result, error) // SetupSerially sets up each of the network interfaces for the namespace in serial SetupSerially(ctx context.Context, id string, path string, opts ...NamespaceOpts) (*Result, error) // Remove tears down the network of the namespace. Remove(ctx context.Context, id string, path string, opts ...NamespaceOpts) error // Check checks if the network is still in desired state Check(ctx context.Context, id string, path string, opts ...NamespaceOpts) error // Load loads the cni network config Load(opts ...Opt) error // Status checks the status of the cni initialization Status() error // GetConfig returns a copy of the CNI plugin configurations as parsed by CNI GetConfig() *ConfigResult }
type ConfNetwork ¶
type ConfNetwork struct { Config *NetworkConfList IFName string }
type ConfigResult ¶
type ConfigResult struct { PluginDirs []string PluginConfDir string PluginMaxConfNum int Prefix string Networks []*ConfNetwork }
type DNS ¶
type DNS struct { // List of DNS servers of the cluster. Servers []string // List of DNS search domains of the cluster. Searches []string // List of DNS options. Options []string }
DNS defines the dns config
type NamespaceOpts ¶
func WithArgs ¶
func WithArgs(k, v string) NamespaceOpts
func WithCapability ¶
func WithCapability(name string, capability interface{}) NamespaceOpts
WithCapability support well-known capabilities https://www.cni.dev/docs/conventions/#well-known-capabilities
func WithCapabilityBandWidth ¶
func WithCapabilityBandWidth(bandWidth BandWidth) NamespaceOpts
WithCapabilityBandWitdh adds support for bandwidth limits
func WithCapabilityCgroupPath ¶ added in v1.1.9
func WithCapabilityCgroupPath(cgroupPath string) NamespaceOpts
WithCapabilityCgroupPath passes in the cgroup path capability.
func WithCapabilityDNS ¶
func WithCapabilityDNS(dns DNS) NamespaceOpts
WithCapabilityDNS adds support for dns
func WithCapabilityIPRanges ¶
func WithCapabilityIPRanges(ipRanges []IPRanges) NamespaceOpts
WithCapabilityIPRanges adds support for ip ranges
func WithCapabilityPortMap ¶
func WithCapabilityPortMap(portMapping []PortMapping) NamespaceOpts
WithCapabilityPortMap adds support for port mappings
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
type NetworkConf ¶
NetworkConf is a source bytes to string conversion of cnilibrary.NetworkConfig
type NetworkConfList ¶
type NetworkConfList struct { Name string CNIVersion string Plugins []*NetworkConf Source string }
NetworkConfList is a source bytes to string version of cnilibrary.NetworkConfigList
type Opt ¶ added in v1.0.2
type Opt func(c *libcni) error
Opt sets options for a CNI instance
func WithConfFile ¶
WithConfFile can be used to load network config from an .conf file. Supported with absolute fileName with path only.
func WithConfIndex ¶
WithConfIndex can be used to load config directly from byte and set the interface name's index.
func WithConfListBytes ¶
WithConfListBytes can be used to load network config list directly from byte
func WithConfListFile ¶
WithConfListFile can be used to load network config from an .conflist file. Supported with absolute fileName with path only.
func WithInterfacePrefix ¶
WithInterfacePrefix sets the prefix for network interfaces e.g. eth or wlan
func WithMinNetworkCount ¶
WithMinNetworkCount can be used to configure the minimum networks to be configured and initialized for the status to report success. By default its 1.
func WithPluginConfDir ¶
WithPluginConfDir can be used to configure the cni configuration directory.
func WithPluginDir ¶
WithPluginDir can be used to set the locations of the cni plugin binaries
func WithPluginMaxConfNum ¶
WithPluginMaxConfNum can be used to configure the max cni plugin config file num.
type PortMapping ¶
type Result ¶ added in v1.0.2
type Result struct { Interfaces map[string]*Config DNS []types.DNS Routes []*types.Route // contains filtered or unexported fields }
Result contains the network information returned by CNI.Setup
a) Interfaces list. Depending on the plugin, this can include the sandbox
(eg, container or hypervisor) interface name and/or the host interface name, the hardware addresses of each interface, and details about the sandbox (if any) the interface is in.
b) IP configuration assigned to each interface. The IPv4 and/or IPv6 addresses,
gateways, and routes assigned to sandbox and/or host interfaces.
c) DNS information. Dictionary that includes DNS information for nameservers,
domain, search domains and options.