network

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

nolint: nilnil

Index

Constants

View Source
const (
	DefaultCNIbinPath  = "/opt/cni/bin"
	DefaultCNIconfPath = "/etc/cni/net.d"
)
View Source
const (
	// DefaultInterface for containers is always eth0
	DefaultInterface = "eth0"
)
View Source
const (
	DefaultLXDBridge = "lxdbr0"
)

Variables

View Source
var (
	ErrNoNetworksFound = errors.New("no valid networks found")
)
View Source
var (
	ErrNoop = errors.New("noop")
)
View Source
var (
	ErrNotBridge = errors.New("not a bridge")
)
View Source
var ErrNotImplemented = errors.New("not implemented")
View Source
var (
	ErrNotSupported = errors.New("not supported")
)

Functions

func FindFreeIP

func FindFreeIP(subnet *net.IPNet, leases []net.IP, start, end net.IP) net.IP

FindFreeIP tries to find an available IP address within given subnet, respecting reserved addresses in leases and must be between the start and end address. Network and broadcast IP are also reserved and automatically added to leases. If start or end is nil their closest available address from the subnet is selected. nolint: gomnd

func InitPluginCNI

func InitPluginCNI(conf ConfCNI) (*cniPlugin, error)

InitPluginCNI instantiates the cni plugin using the provided config

func InitPluginLXDBridge

func InitPluginLXDBridge(server lxd.ContainerServer, conf ConfLXDBridge) (*lxdBridgePlugin, error)

InitPluginLXDBridge instantiates the LXDBridge plugin using the provided config

func InitPluginNoop

func InitPluginNoop() (*noopPlugin, error)

InitPluginNoop instantiates the noop plugin

Types

type ConfCNI

type ConfCNI struct {
	BinPath   string
	ConfPath  string
	NetnsPath string
	// CNI output will be written to OutputWriter
	OutputWriter io.Writer
}

ConfCNI are configuration options for the cni plugin. All properties are optional and get a default value

type ConfLXDBridge

type ConfLXDBridge struct {
	LXDBridge  string
	Cidr       string
	Nat        bool
	CreateOnly bool
}

ConfLXDBridge are configuration options for the LXDBridge plugin. All properties are optional and get a default value

type ContainerNetwork

type ContainerNetwork interface {
	// WhenCreated is called when the container is created
	WhenCreated(ctx context.Context, prop *Properties) (*Result, error)
	// WhenStarted is called when the container is started
	WhenStarted(ctx context.Context, prop *PropertiesRunning) (*Result, error)
	// WhenStopped is called when the container is stopped. If tearing down here, must tear down as good as possible. Must tear
	// down here if not implemented for WhenDeleted. If an error is returned it will only be logged
	WhenStopped(ctx context.Context, prop *Properties) error
	// WhenDeleted is called when the container is deleted. If tearing down here, must tear down as good as possible. Must tear
	// down here if not implemented for WhenStopped. If an error is returned it will only be logged
	WhenDeleted(ctx context.Context, prop *Properties) error
}

ContainerNetwork is the interface for a container network environment context

type Plugin

type Plugin interface {
	// PodNetwork enters a pod network environment context
	PodNetwork(id string, annotations map[string]string) (PodNetwork, error)
	// Status returns error if the plugin is in error state
	Status() error
	// UpdateRuntimeConfig is called when there are updates to the configuration which the plugin might need to apply
	UpdateRuntimeConfig(conf *rtApi.RuntimeConfig) error
}

NetworkPlugin is the interface for lxe network plugins

type PodNetwork

type PodNetwork interface {
	// ContainerNetwork enters a container network environment context
	ContainerNetwork(id string, annotations map[string]string) (ContainerNetwork, error)
	// Status reports IP and any error with the network of that pod
	Status(ctx context.Context, prop *PropertiesRunning) (*Status, error)
	// WhenCreated is called when the pod is created
	WhenCreated(ctx context.Context, prop *Properties) (*Result, error)
	// WhenStarted is called when the pod is started.
	WhenStarted(ctx context.Context, prop *PropertiesRunning) (*Result, error)
	// WhenStopped is called when the pod is stopped. If tearing down here, must tear down as good as possible. Must tear
	// down here if not implemented for WhenDeleted. If an error is returned it will only be logged
	WhenStopped(ctx context.Context, prop *Properties) error
	// WhenDeleted is called when the pod is deleted. If tearing down here, must tear down as good as possible. Must tear
	// down here if not implemented for WhenStopped. If an error is returned it will only be logged
	WhenDeleted(ctx context.Context, prop *Properties) error
}

PodNetwork is the interface for a pod network environment.

type Properties

type Properties struct {
	// Arbitrary Data are provided if a previous call on this PodNetwork returned them
	Data map[string]string
}

Properties of the resource at the time of the call

type PropertiesRunning

type PropertiesRunning struct {
	Properties
	// Pid of the resource. This value is set for calls where the applicable resource is running
	Pid int64
}

PropertiesRunning contains additionally running info

type Result

type Result struct {
	// Arbitrary Data to keep related to the pod. If non-nil they will overwrite the previous saved data.
	Data map[string]string
	// List of Nics to add to the resource
	Nics []device.Nic
	// NetworkConfigEntries of cloudinit to be set. Keep in mind cloudinit runs only when the container starts
	NetworkConfigEntries []cloudinit.NetworkConfigEntryPhysical
}

Result contains additionally info which can only be set on creation

type Status

type Status struct {
	// The IP of the pod network
	IPs []net.IP
}

Contains Status and addresses of that pod network

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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