types

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PodCIDREnvVar is the name of the environment variable that contains the pod CIDR.
	PodCIDREnvVar = "WEBMESH_CNI_POD_CIDR"
	// ServiceCIDREnvVar is the name of the environment variable that contains the service CIDR.
	ServiceCIDREnvVar = "WEBMESH_CNI_SERVICE_CIDR"
	// ClusterDomainEnvVar is the name of the environment variable that contains the cluster domain.
	ClusterDomainEnvVar = "WEBMESH_CNI_CLUSTER_DOMAIN"
	// DryRunEnvVar is the name of the environment variable that enables dry run mode.
	DryRunEnvVar = "WEBMESH_CNI_INSTALL_DRY_RUN"
	// NetConfTemplateEnvVar is the name of the environment variable that contains the CNI configuration.
	NetConfTemplateEnvVar = "WEBMESH_CNI_NETWORK_CONFIG"
	// DestConfFileNameEnvVar is the name of the file that contains the CNI configuration.
	DestConfFileNameEnvVar = "WEBMESH_CNI_CONF_NAME"
	// DestBinEnvVar is the destination directory for the CNI binaries.
	DestBinEnvVar = "WEBMESH_CNI_BIN_DIR"
	// DestConfEnvVar is the destination directory for the CNI configuration.
	DestConfEnvVar = "WEBMESH_CNI_CONF_DIR"
	// CNINetDirEnvVar is the directory containing host-local IPAM allocations. We release these
	// when we start for the first time.
	CNINetDirEnvVar = "WEBMESH_CNI_HOSTNET_DIR"
	// NodeNameEnvVar is the name of the environment variable that contains the node name.
	NodeNameEnvVar = "KUBERNETES_NODE_NAME"
	// PodNamespaceEnvVar is the name of the environment variable that contains the pod namespace.
	PodNamespaceEnvVar = "KUBERNETES_POD_NAMESPACE"
	// KubeconfigEnvVar is the name of the environment variable that contains the kubeconfig.
	KubeconfigEnvVar = "WEBMESH_CNI_KUBECONFIG"
	// NodeNameReplaceStr is the string that will be replaced in the CNI configuration with the node name.
	NodeNameReplaceStr = "__KUBERNETES_NODE_NAME__"
	// PodNamespaceReplaceStr is the string that will be replaced in the CNI configuration with the pod namespace.
	PodNamespaceReplaceStr = "__KUBERNETES_POD_NAMESPACE__"
	// KubeAPIEndpointReplaceStr is the string that will be replaced in the CNI configuration with the Kubernetes API endpoint.
	APIEndpointReplaceStr = "__KUBERNETES_API_ENDPOINT__"
	// KubeconfigFilepathReplaceStr is the string that will be replaced in the CNI configuration with the kubeconfig filepath.
	KubeconfigFilepathReplaceStr = "__KUBECONFIG_FILEPATH__"
	// HostLocalNetDir is the directory containing host-local IPAM allocations. We release these when we start for the first time.
	DefaultHostLocalNetDir = "/var/lib/cni/networks"
	// DefaultDestBin is the default destination directory for the CNI binaries.
	DefaultDestBin = "/opt/cni/bin"
	// DefaultDestConfDir is the default destination directory for the CNI configuration.
	DefaultDestConfDir = "/etc/cni/net.d"
	// DefaultDestConfFilename is the default name of the CNI configuration file.
	DefaultDestConfFilename = "10-webmesh.conflist"
	// DefaultNetConfPath is the default path to the CNI configuration file.
	DefaultNetConfPath = "/etc/cni/net.d/10-webmesh.conflist"
	// Default kubeconfig path if not provided.
	DefaultKubeconfigPath = "/etc/cni/net.d/webmesh-kubeconfig"
	// DefaultNamespace is the default namespace to use for the plugin.
	DefaultNamespace = "kube-system"
	// PluginKubeconfigName is the name of the kubeconfig file for the plugin.
	PluginKubeconfigName = "webmesh-kubeconfig"
	// PluginBinaryName is the name of the plugin binary.
	PluginBinaryName = "webmesh"
	// KubeconfigContextName is the name of the context in the kubeconfig.
	KubeconfigContextName = "webmesh-cni"
	// IfacePrefix is the prefix for interface names.
	IfacePrefix = "wmesh"
	// IPAMLockID is the ID used for the IPAM lock.
	IPAMLockID = "webmesh-cni-ipam"
)

Variables

View Source
var (
	// ErrPeerContainerNotFound is returned when a container is not found.
	ErrPeerContainerNotFound = fmt.Errorf("peer container not found")
)

SchemeBuilders is a list of scheme builders to use for webmesh-cni clients.

Functions

func GetInClusterNamespace added in v0.0.3

func GetInClusterNamespace() (string, error)

GetInClusterNamespace returns the namespace of the pod we are running in.

func IfNameFromID added in v0.0.2

func IfNameFromID(id string) string

IfNameFromID returns a suitable interface name for the given identifier.

func IsPeerContainerNotFound

func IsPeerContainerNotFound(err error) bool

IsPeerContainerNotFound returns true if the given error is a peer container not found error.

func KubeconfigFromRestConfig

func KubeconfigFromRestConfig(cfg *rest.Config, namespace string) (clientcmdapi.Config, error)

KubeconfigFromRestConfig returns a kubeconfig from the given rest config. It reads in any files and encodes them as base64 in the final configuration. GetKubeconfig tries to build a kubeconfig from the current in cluster configuration.

func NewRawClientForConfig

func NewRawClientForConfig(conf *rest.Config) (client.Client, error)

NewRawClientForConfig creates a new raw client from the given configuration.

func NewRestConfigFromBytes added in v0.0.17

func NewRestConfigFromBytes(kubeconfig []byte) (*rest.Config, error)

NewRestConfigFromBytes creates a new rest config from the given kubeconfig bytes.

Types

type Client

type Client struct {
	client.Client
	// contains filtered or unexported fields
}

Client is the client for the CNI plugin.

func NewClientForConfig

func NewClientForConfig(conf ClientConfig) (*Client, error)

NewClientForConfig creates a new client from the given configuration.

func (*Client) CreatePeerContainer

func (c *Client) CreatePeerContainer(ctx context.Context, args *skel.CmdArgs) error

CreatePeerContainer attempts to create the peer container for the given args.

func (*Client) DeletePeerContainer

func (c *Client) DeletePeerContainer(ctx context.Context, args *skel.CmdArgs) error

DeletePeerContainer attempts to delete the peer container for the given args.

func (*Client) EnsureContainer

func (c *Client) EnsureContainer(ctx context.Context, args *skel.CmdArgs) error

EnsureContainer attempts to retrieve the peer container for the given args. If it does not exist, it will create it.

func (*Client) GetPeerContainer

func (c *Client) GetPeerContainer(ctx context.Context, args *skel.CmdArgs) (*meshcniv1.PeerContainer, error)

GetPeerContainer attempts to retrieve the peer container for the given args.

func (*Client) Ping

func (c *Client) Ping(timeout time.Duration) error

Ping will make sure the client can contact the API server using the given timeout.

func (*Client) WaitForRunning

func (c *Client) WaitForRunning(ctx context.Context, args *skel.CmdArgs) (*meshcniv1.PeerContainer, error)

WaitForRunning is a helper function that waits for the container to be running.

func (*Client) WaitForStatus

func (c *Client) WaitForStatus(ctx context.Context, args *skel.CmdArgs, status meshcniv1.InterfaceStatus) (*meshcniv1.PeerContainer, error)

WaitForStatus is a helper function that waits for the given status to be true on the container for the given args. The status is returned if it is true before the timeout.

type ClientConfig

type ClientConfig struct {
	NetConf    *NetConf
	RestConfig *rest.Config
}

ClientConfig is the configuration for the CNI client.

type InstallOptions

type InstallOptions struct {
	// Kubeconfig is the kubeconfig to use for the plugin.
	Kubeconfig string `json:"kubeconfig" mapstructure:"kubeconfig"`
	// SourceBinary is the path to the source binary.
	SourceBinary string `json:"sourceBinary" mapstructure:"sourceBinary"`
	// BinaryDestBin is the destination directory for the CNI binaries.
	BinaryDestBin string `json:"binaryDestBin" mapstructure:"binaryDestBin"`
	// ConfDestDir is the destination directory for the CNI configuration.
	ConfDestDir string `json:"confDestDir" mapstructure:"confDestDir"`
	// ConfDestName is the name of the CNI configuration file.
	ConfDestName string `json:"confDestName" mapstructure:"confDestName"`
	// HostLocalNetDir is the directory containing host-local IPAM allocations.
	// We release these when we start for the first time.
	HostLocalNetDir string `json:"hostLocalNetDir" mapstructure:"hostLocalNetDir"`
	// NetConfTemplate is the template for the CNI configuration.
	NetConfTemplate string `json:"netConfTemplate" mapstructure:"netConfTemplate"`
	// NodeName is the name of the node we are running on.
	NodeName string `json:"nodeName" mapstructure:"nodeName"`
	// Namespace is the namespace to use for the plugin.
	Namespace string `json:"namespace" mapstructure:"namespace"`
	// DryRun is whether or not to run in dry run mode.
	DryRun bool `json:"dryRun" mapstructure:"dryRun"`
}

InstallOptions are the options for the install component.

func LoadInstallOptionsFromEnv

func LoadInstallOptionsFromEnv() *InstallOptions

LoadInstallOptionsFromEnv loads the install options from the environment.

func (*InstallOptions) BindFlags added in v0.0.2

func (i *InstallOptions) BindFlags(fs *flag.FlagSet)

BindFlags binds the install options to the given flag set.

func (*InstallOptions) ClearHostLocalIPAMAllocations

func (i *InstallOptions) ClearHostLocalIPAMAllocations() error

ClearHostLocalIPAMAllocations removes any host-local CNI plugins from the CNI configuration.

func (*InstallOptions) Default added in v0.0.2

func (i *InstallOptions) Default()

func (*InstallOptions) GetKubeconfig

func (i *InstallOptions) GetKubeconfig() (clientcmdapi.Config, error)

GetKubeconfig tries to build a kubeconfig from the current in cluster configuration.

func (*InstallOptions) InstallKubeconfig

func (i *InstallOptions) InstallKubeconfig(kubeconfigPath string) error

InstallKubeconfig writes the kubeconfig file for the plugin.

func (*InstallOptions) InstallNetConf

func (i *InstallOptions) InstallNetConf(path string, config string) error

InstallNetConf installs the CNI configuration.

func (*InstallOptions) InstallPlugin

func (i *InstallOptions) InstallPlugin(dest string) error

InstallPlugin installs the plugin.

func (*InstallOptions) RenderNetConf

func (i *InstallOptions) RenderNetConf(apiEndpoint string, kubeconfig string) string

RenderNetConf renders the CNI configuration.

func (*InstallOptions) RunInstall

func (i *InstallOptions) RunInstall() error

RunInstall is an alias for running all install steps.

func (*InstallOptions) String added in v0.0.2

func (i *InstallOptions) String() string

String returns a string representation of the install options.

func (*InstallOptions) Validate added in v0.0.2

func (i *InstallOptions) Validate() error

type Interface

type Interface struct {
	// MTU is the MTU to set on interfaces.
	MTU int `json:"mtu,omitempty"`
	// DisableIPv4 is whether to disable IPv4 on the interface.
	DisableIPv4 bool `json:"disableIPv4,omitempty"`
	// DisableIPv6 is whether to disable IPv6 on the interface.
	DisableIPv6 bool `json:"disableIPv6,omitempty"`
}

Interface is the configuration for a single interface.

func (*Interface) DeepEqual

func (i *Interface) DeepEqual(other *Interface) bool

DeepEqual returns whether the interface is equal to the given interface.

func (*Interface) Default

func (i *Interface) Default()

Default sets the default values for the interface configuration.

type Kubernetes

type Kubernetes struct {
	// Kubeconfig is the path to the kubeconfig file.
	Kubeconfig string `json:"kubeconfig,omitempty"`
	// NodeName is the name of the node we are running on.
	NodeName string `json:"nodeName,omitempty"`
	// K8sAPIRoot is the root URL of the Kubernetes API server.
	K8sAPIRoot string `json:"k8sAPIRoot,omitempty"`
	// Namespace is the namespace to use for the plugin.
	Namespace string `json:"namespace,omitempty"`
}

Kubernetes is the configuration for the Kubernetes API server and information about the node we are running on.

func (*Kubernetes) DeepEqual

func (k *Kubernetes) DeepEqual(other *Kubernetes) bool

DeepEqual returns whether the Kubernetes configuration is equal to the given configuration.

func (*Kubernetes) Default

func (k *Kubernetes) Default()

Default sets the default values for the Kubernetes configuration.

type NetConf

type NetConf struct {
	// NetConf is the typed configuration for the CNI plugin.
	cnitypes.NetConf `json:",inline"`

	// Interface is the configuration for container interfaces.
	Interface Interface `json:"interface,omitempty"`
	// Kubernetes is the configuration for the Kubernetes API server and
	// information about the node we are running on.
	Kubernetes Kubernetes `json:"kubernetes,omitempty"`
	// LogLevel is the log level for the plugin and managed interfaces.
	LogLevel string `json:"logLevel,omitempty"`
	// LogFile is the file to write logs to.
	LogFile string `json:"logFile,omitempty"`
}

NetConf is the configuration for the CNI plugin.

func DecodeNetConf

func DecodeNetConf(data []byte) (*NetConf, error)

DecodeNetConf loads the configuration from the given JSON data.

func LoadDefaultNetConf

func LoadDefaultNetConf() (*NetConf, error)

LoadDefaultNetConf attempts to load the configuration from the default file.

func LoadNetConfFromArgs

func LoadNetConfFromArgs(cmd *skel.CmdArgs) (*NetConf, error)

LoadConfigFromArgs loads the configuration from the given CNI arguments.

func LoadNetConfFromFile

func LoadNetConfFromFile(path string) (*NetConf, error)

LoadNetConfFromFile loads the configuration from the given file.

func (*NetConf) ContainerFromArgs

func (n *NetConf) ContainerFromArgs(args *skel.CmdArgs) meshcniv1.PeerContainer

ContainerFromArgs creates a skeleton container object for the given container arguments.

func (*NetConf) DeepEqual

func (n *NetConf) DeepEqual(other *NetConf) bool

DeepEqual returns whether the configuration is equal to the given configuration.

func (*NetConf) LogWriter

func (n *NetConf) LogWriter() io.Writer

LogWriter reteurns the io.Writer for the plugin logger.

func (*NetConf) NewClient

func (n *NetConf) NewClient(pingTimeout time.Duration) (*Client, error)

NewClient creates a new client for the Kubernetes API server.

func (*NetConf) NewLogger

func (n *NetConf) NewLogger(args *skel.CmdArgs) *slog.Logger

NewLogger creates a new logger for the plugin.

func (*NetConf) ObjectKeyFromArgs

func (n *NetConf) ObjectKeyFromArgs(args *skel.CmdArgs) client.ObjectKey

ObjectKeyFromArgs creates a new object key for the given container ID.

func (*NetConf) RestConfig

func (n *NetConf) RestConfig() (*rest.Config, error)

RestConfig returns the rest config for the Kubernetes API server.

func (*NetConf) SetDefaults

func (n *NetConf) SetDefaults() *NetConf

SetDefaults sets the default values for the configuration. It returns the configuration for convenience.

func (*NetConf) SlogLevel

func (n *NetConf) SlogLevel() slog.Level

SlogLevel returns the slog.Level for the given log level string.

Jump to

Keyboard shortcuts

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