cni

package
v0.0.0-...-d1e3be9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Supported CNI versions.
	Version = "0.2.0"

	// CNI commands.
	CmdAdd = "ADD"
	CmdDel = "DEL"

	Internal = "internal"
)

Variables

This section is empty.

Functions

func CallPlugin

func CallPlugin(plugin PluginApi, cmd string, args *cniSkel.CmdArgs, config *NetworkConfig) (*cniTypes.Result, error)

CallPlugin calls the given CNI plugin through the internal interface.

func GetResult020

func GetResult020(network *network.NetworkInfo, endpoint *network.EndpointInfo) cniTypes020.Result

GetResult020 gets the v020 result object

Types

type IP

type IP struct {
	Version        string         `json:"version"` // 4 or 6
	Address        cniTypes.IPNet `json:"address"`
	Gateway        net.IP         `json:"gateway"`
	InterfaceIndex int            `json:"interface"` // Numeric index into 'interfaces' list
}

func GetIP

func GetIP(network *network.NetworkInfo, endpoint *network.EndpointInfo) IP

GetIP returns the IP for the corresponding endpoint

type Interface

type Interface struct {
	Name       string           `json:"name"`
	MacAddress net.HardwareAddr `json:"mac"`
	Sandbox    string           `json:"sandbox"`
}

func GetInterface

func GetInterface(endpoint *network.EndpointInfo) Interface

GetInterface returns the interface for endpoint

type K8SPodEnvArgs

type K8SPodEnvArgs struct {
	cniTypes.CommonArgs
	K8S_POD_NAMESPACE          cniTypes.UnmarshallableString `json:"K8S_POD_NAMESPACE,omitempty"`
	K8S_POD_NAME               cniTypes.UnmarshallableString `json:"K8S_POD_NAME,omitempty"`
	K8S_POD_INFRA_CONTAINER_ID cniTypes.UnmarshallableString `json:"K8S_POD_INFRA_CONTAINER_ID,omitempty"`
}

func ParseCniArgs

func ParseCniArgs(args string) (*K8SPodEnvArgs, error)

ParseCniArgs

type KVP

type KVP struct {
	Name  string          `json:"name"`
	Value json.RawMessage `json:"value"`
}

type NetworkConfig

type NetworkConfig struct {
	CniVersion string `json:"cniVersion"`
	Name       string `json:"name"` // Name is the Network Name. We would also use this as the Type of HNS Network
	Type       string `json:"type"` // As per SPEC, Type is Name of the Binary
	Ipam       struct {
		Type          string           `json:"type"`
		Environment   string           `json:"environment,omitempty"`
		AddrSpace     string           `json:"addressSpace,omitempty"`
		Subnet        string           `json:"subnet,omitempty"`
		Address       string           `json:"ipAddress,omitempty"`
		QueryInterval string           `json:"queryInterval,omitempty"`
		Routes        []cniTypes.Route `json:"routes,omitempty"`
	}
	DNS            cniTypes.DNS  `json:"dns"`
	RuntimeConfig  RuntimeConfig `json:"runtimeConfig"`
	AdditionalArgs []KVP
}

NetworkConfig represents the Windows CNI plugin's network configuration. Defined as per https://github.com/containernetworking/cni/blob/master/SPEC.md

func ParseNetworkConfig

func ParseNetworkConfig(b []byte) (*NetworkConfig, error)

ParseNetworkConfig unmarshals network configuration from bytes.

func (*NetworkConfig) GetEndpointInfo

func (config *NetworkConfig) GetEndpointInfo(
	networkinfo *network.NetworkInfo,
	containerID string, netNs string, podK8sNamespace string) *network.EndpointInfo

GetEndpointInfo constructs endpoint info using endpoint id, containerid and netns

func (*NetworkConfig) GetNetworkInfo

func (config *NetworkConfig) GetNetworkInfo() *network.NetworkInfo

Get NetworkInfo from the NetworkConfig

func (*NetworkConfig) Serialize

func (config *NetworkConfig) Serialize() []byte

Serialize marshals a network configuration to bytes.

type Plugin

type Plugin struct {
	*common.Plugin
}

Plugin is the parent class for CNI plugins.

func NewPlugin

func NewPlugin(name, version string) (*Plugin, error)

NewPlugin creates a new CNI plugin.

func (*Plugin) Execute

func (plugin *Plugin) Execute(api PluginApi) error

Execute executes the CNI command.

func (*Plugin) Initialize

func (plugin *Plugin) Initialize(config *common.PluginConfig) error

Initialize initializes the plugin.

func (*Plugin) Uninitialize

func (plugin *Plugin) Uninitialize()

Uninitialize uninitializes the plugin.

type PluginApi

type PluginApi interface {
	Add(args *cniSkel.CmdArgs) error
	Delete(args *cniSkel.CmdArgs) error
}

CNI contract.

type PortMapping

type PortMapping struct {
	HostPort      int    `json:"hostPort"`
	ContainerPort int    `json:"containerPort"`
	Protocol      string `json:"protocol"`
	HostIp        string `json:"hostIP,omitempty"`
}

type Result

type Result struct {
	CniVersion string           `json:"cniVersion"`
	Interfaces []Interface      `json:"interfaces"`
	IP         []IP             `json:"ip"`
	DNS        cniTypes.DNS     `json:"dns"`
	Routes     []cniTypes.Route `json:"routes,omitempty"`
}

func GetResult

func GetResult(network *network.NetworkInfo, endpoint *network.EndpointInfo) Result

GetResult gets the result object

func (*Result) Print

func (r *Result) Print()

func (*Result) String

func (r *Result) String() string

type RuntimeConfig

type RuntimeConfig struct {
	PortMappings []PortMapping `json:"portMappings,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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