[go: up one dir, main page]

driverapi

package
v2.0.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const NetworkPluginEndpointType = "NetworkDriver"

NetworkPluginEndpointType represents the Endpoint Type used by Plugin system

Variables

This section is empty.

Functions

func IsValidType

func IsValidType(objType ObjectType) bool

IsValidType validates the passed in type against the valid object types

Types

type Capability

type Capability struct {
	DataScope         string
	ConnectivityScope string
}

Capability represents the high level capabilities of the drivers which libnetwork can make use of

type Driver

type Driver interface {
	// CreateNetwork invokes the driver method to create a network
	// passing the network id and network specific config. The
	// config mechanism will eventually be replaced with labels
	// which are yet to be introduced. The driver can return a
	// list of table names for which it is interested in receiving
	// notification when a CRUD operation is performed on any
	// entry in that table. This will be ignored for local scope
	// drivers.
	CreateNetwork(ctx context.Context, nid string, options map[string]any, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error

	// DeleteNetwork invokes the driver method to delete network passing
	// the network id.
	DeleteNetwork(nid string) error

	// CreateEndpoint invokes the driver method to create an endpoint
	// passing the network id, endpoint id endpoint information and driver
	// specific config. The endpoint information can be either consumed by
	// the driver or populated by the driver. The config mechanism will
	// eventually be replaced with labels which are yet to be introduced.
	CreateEndpoint(ctx context.Context, nid, eid string, ifInfo InterfaceInfo, options map[string]any) error

	// DeleteEndpoint invokes the driver method to delete an endpoint
	// passing the network id and endpoint id.
	DeleteEndpoint(nid, eid string) error

	// EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
	EndpointOperInfo(nid, eid string) (map[string]any, error)

	// Join method is invoked when a Sandbox is attached to an endpoint.
	Join(ctx context.Context, nid, eid string, sboxKey string, jinfo JoinInfo, epOpts, sbOpts map[string]any) error

	// Leave method is invoked when a Sandbox detaches from an endpoint.
	Leave(nid, eid string) error

	// Type returns the type of this driver, the network type this driver manages
	Type() string

	// IsBuiltIn returns true if it is a built-in driver
	IsBuiltIn() bool
}

Driver is an interface that every plugin driver needs to implement.

type ErrActiveRegistration

type ErrActiveRegistration string

ErrActiveRegistration represents an error when a driver is registered to a networkType that is previously registered

func (ErrActiveRegistration) Error

func (ar ErrActiveRegistration) Error() string

Error interface for ErrActiveRegistration

func (ErrActiveRegistration) Forbidden

func (ar ErrActiveRegistration) Forbidden()

Forbidden denotes the type of this error

type ErrEndpointExists

type ErrEndpointExists string

ErrEndpointExists is returned if more than one endpoint is added to the network

func (ErrEndpointExists) Error

func (ee ErrEndpointExists) Error() string

func (ErrEndpointExists) Forbidden

func (ee ErrEndpointExists) Forbidden()

Forbidden denotes the type of this error

type ErrNoEndpoint

type ErrNoEndpoint string

ErrNoEndpoint is returned if no endpoint with the specified id exists

func (ErrNoEndpoint) Error

func (ene ErrNoEndpoint) Error() string

func (ErrNoEndpoint) NotFound

func (ene ErrNoEndpoint) NotFound()

NotFound denotes the type of this error

type ErrNoNetwork

type ErrNoNetwork string

ErrNoNetwork is returned if no network with the specified id exists

func (ErrNoNetwork) Error

func (enn ErrNoNetwork) Error() string

func (ErrNoNetwork) NotFound

func (enn ErrNoNetwork) NotFound()

NotFound denotes the type of this error

type ErrNotImplemented

type ErrNotImplemented struct{}

ErrNotImplemented is returned when a Driver has not implemented an API yet

func (*ErrNotImplemented) Error

func (eni *ErrNotImplemented) Error() string

func (*ErrNotImplemented) NotImplemented

func (eni *ErrNotImplemented) NotImplemented()

NotImplemented denotes the type of this error

type ExtConner

type ExtConner interface {
	// ProgramExternalConnectivity tells the driver the ids of the endpoints
	// currently acting as the container's default gateway for IPv4 and IPv6,
	// passed as gw4Id/gw6Id. (Those endpoints may be managed by different network
	// drivers. If there is no gateway, the id will be the empty string.)
	//
	// This method is called after Driver.Join, before Driver.Leave, and when eid
	// is or was equal to gw4Id or gw6Id, and there's a change. It may also be
	// called when the gateways have not changed.
	//
	// When an endpoint acting as a gateway is deleted, this function is called
	// with that endpoint's id in eid, and empty gateway ids (even if another
	// is present and will shortly be selected as the gateway).
	ProgramExternalConnectivity(ctx context.Context, nid, eid string, gw4Id, gw6Id string) error
}

ExtConner is an optional interface for a network driver.

type GwAllocChecker

type GwAllocChecker interface {
	// GetSkipGwAlloc returns true if the opts describe a network
	// that does not need a gateway IPv4/IPv6 address, else false.
	GetSkipGwAlloc(opts options.Generic) (skipIPv4, skipIPv6 bool, err error)
}

GwAllocChecker is an optional interface for a network driver.

type IPAMData

type IPAMData struct {
	AddressSpace string
	Pool         *net.IPNet
	Gateway      *net.IPNet
	AuxAddresses map[string]*net.IPNet
}

IPAMData represents the per-network ip related operational information libnetwork will send to the network driver during CreateNetwork()

func (*IPAMData) IsV6

func (i *IPAMData) IsV6() bool

IsV6 returns whether this is an IPv6 IPAMData structure

func (*IPAMData) MarshalJSON

func (i *IPAMData) MarshalJSON() ([]byte, error)

MarshalJSON encodes IPAMData into json message

func (*IPAMData) String

func (i *IPAMData) String() string

func (*IPAMData) UnmarshalJSON

func (i *IPAMData) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a json message into IPAMData

func (*IPAMData) Validate

func (i *IPAMData) Validate() error

Validate checks whether the IPAMData structure contains congruent data

type InterfaceInfo

type InterfaceInfo interface {
	// SetMacAddress allows the driver to set the mac address to the endpoint interface
	// during the call to CreateEndpoint, if the mac address is not already set.
	SetMacAddress(mac net.HardwareAddr) error

	// SetIPAddress allows the driver to set the ip address to the endpoint interface
	// during the call to CreateEndpoint, if the address is not already set.
	// The API is to be used to assign both the IPv4 and IPv6 address types.
	SetIPAddress(ip *net.IPNet) error

	// MacAddress returns the MAC address.
	MacAddress() net.HardwareAddr

	// Address returns the IPv4 address.
	Address() *net.IPNet

	// AddressIPv6 returns the IPv6 address.
	AddressIPv6() *net.IPNet

	// NetnsPath returns the path of the network namespace, if there is one. Else "".
	NetnsPath() string

	// SetCreatedInContainer can be called by the driver to indicate that it's
	// created the network interface in the container's network namespace (so,
	// it doesn't need to be moved there).
	SetCreatedInContainer(bool)
}

InterfaceInfo provides a go interface for drivers to retrieve network information to interface resources.

type InterfaceNameInfo

type InterfaceNameInfo interface {
	// SetNames method assigns the srcName, dstPrefix, and dstName for the
	// interface. If both dstName and dstPrefix are set, dstName takes
	// precedence.
	SetNames(srcName, dstPrefix, dstName string) error
}

InterfaceNameInfo provides a go interface for the drivers to assign names to interfaces.

type JoinInfo

type JoinInfo interface {
	// InterfaceName returns an InterfaceNameInfo go interface to facilitate
	// setting the names for the interface.
	InterfaceName() InterfaceNameInfo

	// SetGateway sets the default IPv4 gateway when a container joins the endpoint.
	SetGateway(net.IP) error

	// SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
	SetGatewayIPv6(net.IP) error

	// AddStaticRoute adds a route to the sandbox.
	// It may be used in addition to or instead of a default gateway (as above).
	AddStaticRoute(destination *net.IPNet, routeType types.RouteType, nextHop net.IP) error

	// DisableGatewayService tells libnetwork not to provide Default GW for the container
	DisableGatewayService()

	// AddTableEntry adds a table entry to the gossip layer
	// passing the table name, key and an opaque value.
	AddTableEntry(tableName string, key string, value []byte) error
}

JoinInfo represents a set of resources that the driver has the ability to provide during join time.

type NetworkAllocator

type NetworkAllocator interface {
	// NetworkAllocate invokes the driver method to allocate network
	// specific resources passing network id and network specific config.
	// It returns a key,value pair of network specific driver allocations
	// to the caller.
	NetworkAllocate(nid string, options map[string]string, ipV4Data, ipV6Data []IPAMData) (map[string]string, error)

	// NetworkFree invokes the driver method to free network specific resources
	// associated with a given network id.
	NetworkFree(nid string) error

	// IsBuiltIn returns true if it is a built-in driver
	IsBuiltIn() bool
}

NetworkAllocator is a special kind of network driver used by cnmallocator to allocate resources inside a Swarm cluster.

type NetworkInfo

type NetworkInfo interface {
	// TableEventRegister registers driver interest in a given
	// table name.
	TableEventRegister(tableName string, objType ObjectType) error

	// UpdateIpamConfig updates the networks IPAM configuration
	// based on information from the driver.  In windows, the OS (HNS) chooses
	// the IP address space if the user does not specify an address space.
	UpdateIpamConfig(ipV4Data []IPAMData)
}

NetworkInfo provides a go interface for drivers to provide network specific information to libnetwork.

type ObjectType

type ObjectType int

ObjectType represents the type of object driver wants to store in libnetwork's networkDB

const (
	// EndpointObject should be set for libnetwork endpoint object related data
	EndpointObject ObjectType = 1 + iota
	// NetworkObject should be set for libnetwork network object related data
	NetworkObject
	// OpaqueObject is for driver specific data with no corresponding libnetwork object
	OpaqueObject
)

type Registerer

type Registerer interface {
	RegisterDriver(name string, driver Driver, capability Capability) error
	RegisterNetworkAllocator(name string, driver NetworkAllocator) error
}

Registerer provides a way for network drivers to be dynamically registered.

type TableWatcher

type TableWatcher interface {
	// EventNotify notifies the driver when a CRUD operation has
	// happened on a table of its interest as soon as this node
	// receives such an event in the gossip layer. This method is
	// only invoked for the global scope driver.
	EventNotify(nid string, tableName string, key string, prev, value []byte)

	// DecodeTableEntry passes the driver a key, value pair from table it registered
	// with libnetwork. Driver should return {object ID, map[string]string} tuple.
	// If DecodeTableEntry is called for a table associated with NetworkObject or
	// EndpointObject the return object ID should be the network id or endpoint id
	// associated with that entry. map should have information about the object that
	// can be presented to the user.
	// For example: overlay driver returns the VTEP IP of the host that has the endpoint
	// which is shown in 'network inspect --verbose'
	DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string)
}

TableWatcher is an optional interface for a network driver.

Jump to

Keyboard shortcuts

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