Documentation
¶
Index ¶
- Constants
- Variables
- func GetInClusterNamespace() (string, error)
- func IfNameFromID(id string) string
- func IsPeerContainerNotFound(err error) bool
- func KubeconfigFromRestConfig(cfg *rest.Config, namespace string) (clientcmdapi.Config, error)
- func NewRawClientForConfig(conf *rest.Config) (client.Client, error)
- func NewRestConfigFromBytes(kubeconfig []byte) (*rest.Config, error)
- type Client
- func (c *Client) CreatePeerContainer(ctx context.Context, args *skel.CmdArgs) error
- func (c *Client) DeletePeerContainer(ctx context.Context, args *skel.CmdArgs) error
- func (c *Client) EnsureContainer(ctx context.Context, args *skel.CmdArgs) error
- func (c *Client) GetPeerContainer(ctx context.Context, args *skel.CmdArgs) (*meshcniv1.PeerContainer, error)
- func (c *Client) Ping(timeout time.Duration) error
- func (c *Client) WaitForRunning(ctx context.Context, args *skel.CmdArgs) (*meshcniv1.PeerContainer, error)
- func (c *Client) WaitForStatus(ctx context.Context, args *skel.CmdArgs, status meshcniv1.InterfaceStatus) (*meshcniv1.PeerContainer, error)
- type ClientConfig
- type InstallOptions
- func (i *InstallOptions) BindFlags(fs *flag.FlagSet)
- func (i *InstallOptions) ClearHostLocalIPAMAllocations() error
- func (i *InstallOptions) Default()
- func (i *InstallOptions) GetKubeconfig() (clientcmdapi.Config, error)
- func (i *InstallOptions) InstallKubeconfig(kubeconfigPath string) error
- func (i *InstallOptions) InstallNetConf(path string, config string) error
- func (i *InstallOptions) InstallPlugin(dest string) error
- func (i *InstallOptions) RenderNetConf(apiEndpoint string, kubeconfig string) string
- func (i *InstallOptions) RunInstall() error
- func (i *InstallOptions) String() string
- func (i *InstallOptions) Validate() error
- type Interface
- type Kubernetes
- type NetConf
- func (n *NetConf) ContainerFromArgs(args *skel.CmdArgs) meshcniv1.PeerContainer
- func (n *NetConf) DeepEqual(other *NetConf) bool
- func (n *NetConf) LogWriter() io.Writer
- func (n *NetConf) NewClient(pingTimeout time.Duration) (*Client, error)
- func (n *NetConf) NewLogger(args *skel.CmdArgs) *slog.Logger
- func (n *NetConf) ObjectKeyFromArgs(args *skel.CmdArgs) client.ObjectKey
- func (n *NetConf) RestConfig() (*rest.Config, error)
- func (n *NetConf) SetDefaults() *NetConf
- func (n *NetConf) SlogLevel() slog.Level
Constants ¶
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 ¶
var ( // ErrPeerContainerNotFound is returned when a container is not found. ErrPeerContainerNotFound = fmt.Errorf("peer container not found") )
var SchemeBuilders = []func(*runtime.Scheme) error{ clientgoscheme.AddToScheme, apiextensions.AddToScheme, storagev1.AddToScheme, meshcniv1.AddToScheme, }
SchemeBuilders is a list of scheme builders to use for webmesh-cni clients.
Functions ¶
func GetInClusterNamespace ¶ added in v0.0.3
GetInClusterNamespace returns the namespace of the pod we are running in.
func IfNameFromID ¶ added in v0.0.2
IfNameFromID returns a suitable interface name for the given identifier.
func IsPeerContainerNotFound ¶
IsPeerContainerNotFound returns true if the given error is a peer container not found error.
func KubeconfigFromRestConfig ¶
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 ¶
NewRawClientForConfig creates a new raw client from the given configuration.
Types ¶
type Client ¶
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 ¶
CreatePeerContainer attempts to create the peer container for the given args.
func (*Client) DeletePeerContainer ¶
DeletePeerContainer attempts to delete the peer container for the given args.
func (*Client) EnsureContainer ¶
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 ¶
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 ¶
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.
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 ¶
DecodeNetConf loads the configuration from the given JSON data.
func LoadDefaultNetConf ¶
LoadDefaultNetConf attempts to load the configuration from the default file.
func LoadNetConfFromArgs ¶
LoadConfigFromArgs loads the configuration from the given CNI arguments.
func LoadNetConfFromFile ¶
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 ¶
DeepEqual returns whether the configuration is equal to the given configuration.
func (*NetConf) ObjectKeyFromArgs ¶
ObjectKeyFromArgs creates a new object key for the given container ID.
func (*NetConf) RestConfig ¶
RestConfig returns the rest config for the Kubernetes API server.
func (*NetConf) SetDefaults ¶
SetDefaults sets the default values for the configuration. It returns the configuration for convenience.