incus

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminalError

func IsTerminalError(err error) bool

IsTerminalError checks whether the error is a terminalError. These are returned to indicate non-retriable errors.

Types

type Client

type Client struct {
	Client incus.InstanceServer
}

func New

func New(ctx context.Context, opts Options) (*Client, error)

func (*Client) CreateAndWaitForInstance added in v0.6.0

func (c *Client) CreateAndWaitForInstance(ctx context.Context, instance api.InstancesPost) error

func (*Client) CreateInstance

func (c *Client) CreateInstance(ctx context.Context, machine *clusterv1.Machine, lxcMachine *infrav1.LXCMachine, cluster *clusterv1.Cluster, lxcCluster *infrav1.LXCCluster, cloudInit string) ([]string, error)

CreateInstance creates the LXC instance based on configuration from the machine.

func (*Client) CreateInstanceSnapshot added in v0.6.0

func (c *Client) CreateInstanceSnapshot(ctx context.Context, instanceName string, snapshotName string) error

func (*Client) DeleteInstance

func (c *Client) DeleteInstance(ctx context.Context, lxcMachine *infrav1.LXCMachine) error

DeleteInstance deletes the matching LXC instance, if any.

func (*Client) DeleteProfile

func (c *Client) DeleteProfile(ctx context.Context, profileName string) error

DeleteProfile deletes an LXC profile if it exists.

func (*Client) ForceRemoveInstance added in v0.6.0

func (c *Client) ForceRemoveInstance(ctx context.Context, instanceName string) error

func (*Client) InitProfile

func (c *Client) InitProfile(ctx context.Context, profile api.ProfilesPost) error

InitProfile creates an LXC profile if it does not already exist.

func (*Client) LoadBalancerManagerForCluster

func (c *Client) LoadBalancerManagerForCluster(cluster *clusterv1.Cluster, lxcCluster *infrav1.LXCCluster) LoadBalancerManager

LoadBalancerManagerForCluster returns the proper LoadBalancerManager based on the lxcCluster spec.

func (*Client) ParseActiveMachineAddresses

func (c *Client) ParseActiveMachineAddresses(state *api.InstanceState) []string

ParseActiveMachineAddresses returns the main IP addresses of the instance. It filters for networks that have a host interface name (e.g. vethbbcd39c7), so that CNI addresses are ignored. It filters for addresses with global scope, so that IPv6 link-local addresses are ignored.

func (*Client) PublishImage added in v0.6.0

func (c *Client) PublishImage(ctx context.Context, instanceName string, imageAliasName string, imageProperties map[string]string) error

func (*Client) RunCommand

func (c *Client) RunCommand(ctx context.Context, instanceName string, command []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error

RunCommand on a specified instance, and allow retrieving the stdout and stderr. It returns an error if execution failed.

func (*Client) StopInstance added in v0.6.0

func (c *Client) StopInstance(ctx context.Context, name string) error

func (*Client) SupportsInstanceOCI

func (c *Client) SupportsInstanceOCI() error

SupportsInstanceOCI checks if the necessary API extensions for OCI instances are supported by the server.

If instance_oci is not supported, a terminalError is returned.

func (*Client) SupportsNetworkLoadBalancer

func (c *Client) SupportsNetworkLoadBalancer() error

SupportsNetworkLoadBalancer checks if the necessary API extensions for Network Load Balancers are supported by the server.

If network_load_balancer or network_load_balancer_health_check are not supported, a terminalError is returned.

type LoadBalancerManager

type LoadBalancerManager interface {
	// Create provisions the load balancer instance.
	// Implementations can indicate non-retriable failures (e.g. because of Incus not having the required extensions).
	// Callers must check these with incus.IsTerminalError() and treat them as terminal failures.
	Create(context.Context) ([]string, error)
	// Delete cleans up any load balancer resources.
	Delete(context.Context) error
	// Reconfigure updates the load balancer configuration based on the currently running control plane instances.
	Reconfigure(context.Context) error
	// Inspect returns a map[string]string of the current state of the load balancer infrastructure.
	// It is mainly used by the E2E tests.
	Inspect(context.Context) map[string]string
}

LoadBalancerManager can be used to interact with the cluster load balancer.

type Options

type Options struct {
	// Server URL and certificate.
	ServerURL          string `yaml:"server"`
	ServerCrt          string `yaml:"server-crt"`
	InsecureSkipVerify bool   `yaml:"insecure-skip-verify"`

	// Client certificate and key.
	ClientCrt string `yaml:"client-crt"`
	ClientKey string `yaml:"client-key"`

	// Project name
	Project string `yaml:"project"`
}

func NewOptionsFromConfigFile

func NewOptionsFromConfigFile(configFile string, forceRemoteName string, requireHTTPS bool) (Options, error)

NewOptionsFromConfigFile attempts to load client options from the local node configuration.

func NewOptionsFromSecret

func NewOptionsFromSecret(secret *corev1.Secret) Options

NewOptionsFromSecret parses a Kubernetes secret and derives Options for connecting to Incus.

The secret can be created like this:

```bash

# create a client certificate and key trusted by incus
$ incus remote generate-certificate
$ sudo incus config trust add-certificate ~/.config/incus/client.crt

# generate kubernetes secret
$ kubectl create secret generic incus-secret \
	--from-literal=server="https://10.0.0.49:8443" \
	--from-literal=server-crt="$(sudo cat /var/lib/incus/cluster.crt)" \
	--from-literal=client-crt="$(cat ~/.config/incus/client.crt)" \
	--from-literal=client-key="$(cat ~/.config/incus/client.key)" \
	--from-literal=project="default"

# or with insecure skip verify
$ kubectl create secret generic lxd-secret \
	--from-literal=server=https://10.0.1.2:8901 \
	--from-literal=insecure-skip-verify=true \
	--from-literal=client-crt="$(cat ~/.config/incus/client.crt)" \
	--from-literal=client-key="$(cat ~/.config/incus/client.key)" \
	--from-literal=project="default"

```

func (Options) ToSecret

func (o Options) ToSecret(name string, namespace string) *corev1.Secret

ToSecretData generates secret data from an Options struct.

Jump to

Keyboard shortcuts

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