Documentation ¶
Index ¶
- Variables
- func Accept(state *state.State, gateway *Gateway, name, address string, schema, api int) ([]db.RaftNode, error)
- func Bootstrap(state *state.State, gateway *Gateway, name string) error
- func ConfigGetBool(cluster *db.Cluster, key string) (bool, error)
- func ConfigGetInt64(cluster *db.Cluster, key string) (int64, error)
- func ConfigGetString(cluster *db.Cluster, key string) (string, error)
- func Connect(address string, cert *shared.CertInfo, notify bool) (lxd.ContainerServer, error)
- func ConnectIfContainerIsRemote(cluster *db.Cluster, name string, cert *shared.CertInfo) (lxd.ContainerServer, error)
- func ConnectIfVolumeIsRemote(cluster *db.Cluster, poolID int64, volumeName string, volumeType int, ...) (lxd.ContainerServer, error)
- func Count(state *state.State) (int, error)
- func Enabled(node *db.Node) (bool, error)
- func Events(endpoints *endpoints.Endpoints, cluster *db.Cluster, ...) (task.Func, task.Schedule)
- func Heartbeat(gateway *Gateway, cluster *db.Cluster) (task.Func, task.Schedule)
- func Join(state *state.State, gateway *Gateway, cert *shared.CertInfo, name string, ...) error
- func Leave(state *state.State, gateway *Gateway, name string, force bool) (string, error)
- func List(state *state.State) ([]api.ClusterMember, error)
- func NotifyUpgradeCompleted(state *state.State, cert *shared.CertInfo) error
- func Purge(cluster *db.Cluster, name string) error
- func ResolveTarget(cluster *db.Cluster, target string) (string, error)
- func SetupTrust(cert, targetAddress, targetCert, targetPassword string) error
- type Config
- func (c *Config) AutoUpdateInterval() time.Duration
- func (c *Config) Dump() map[string]interface{}
- func (c *Config) HTTPSAllowedCredentials() bool
- func (c *Config) HTTPSAllowedHeaders() string
- func (c *Config) HTTPSAllowedMethods() string
- func (c *Config) HTTPSAllowedOrigin() string
- func (c *Config) MAASController() (string, string)
- func (c *Config) MacaroonEndpoint() string
- func (c *Config) OfflineThreshold() time.Duration
- func (c *Config) Patch(patch map[string]interface{}) (map[string]string, error)
- func (c *Config) ProxyHTTP() string
- func (c *Config) ProxyHTTPS() string
- func (c *Config) ProxyIgnoreHosts() string
- func (c *Config) RemoteCacheExpiry() int64
- func (c *Config) Replace(values map[string]interface{}) (map[string]string, error)
- func (c *Config) TrustPassword() string
- type Gateway
- func (g *Gateway) Dialer() grpcsql.Dialer
- func (g *Gateway) HandlerFuncs() map[string]http.HandlerFunc
- func (g *Gateway) Kill()
- func (g *Gateway) LeaderAddress() (string, error)
- func (g *Gateway) Reset(cert *shared.CertInfo) error
- func (g *Gateway) Shutdown() error
- func (g *Gateway) WaitUpgradeNotification()
- type Notifier
- type NotifierPolicy
- type Option
Constants ¶
This section is empty.
Variables ¶
var ConfigSchema = config.Schema{ "cluster.offline_threshold": {Type: config.Int64, Default: offlineThresholdDefault(), Validator: offlineThresholdValidator}, "core.https_allowed_headers": {}, "core.https_allowed_methods": {}, "core.https_allowed_origin": {}, "core.https_allowed_credentials": {Type: config.Bool}, "core.proxy_http": {}, "core.proxy_https": {}, "core.proxy_ignore_hosts": {}, "core.trust_password": {Hidden: true, Setter: passwordSetter}, "core.macaroon.endpoint": {}, "images.auto_update_cached": {Type: config.Bool, Default: "true"}, "images.auto_update_interval": {Type: config.Int64, Default: "6"}, "images.compression_algorithm": {Default: "gzip", Validator: validateCompression}, "images.remote_cache_expiry": {Type: config.Int64, Default: "10"}, "maas.api.key": {}, "maas.api.url": {}, "storage.lvm_fstype": {Setter: deprecatedStorage, Default: "ext4"}, "storage.lvm_mount_options": {Setter: deprecatedStorage, Default: "discard"}, "storage.lvm_thinpool_name": {Setter: deprecatedStorage, Default: "LXDPool"}, "storage.lvm_vg_name": {Setter: deprecatedStorage}, "storage.lvm_volume_size": {Setter: deprecatedStorage, Default: "10GiB"}, "storage.zfs_pool_name": {Setter: deprecatedStorage}, "storage.zfs_remove_snapshots": {Setter: deprecatedStorage, Type: config.Bool}, "storage.zfs_use_refquota": {Setter: deprecatedStorage, Type: config.Bool}, }
ConfigSchema defines available server configuration keys.
var SchemaVersion = cluster.SchemaVersion
SchemaVersion holds the version of the cluster database schema.
Functions ¶
func Accept ¶
func Accept(state *state.State, gateway *Gateway, name, address string, schema, api int) ([]db.RaftNode, error)
Accept a new node and add it to the cluster.
This instance must already be clustered.
Return an updated list raft database nodes (possibly including the newly accepted node).
func Bootstrap ¶
Bootstrap turns a non-clustered LXD instance into the first (and leader) node of a new LXD cluster.
This instance must already have its core.https_address set and be listening on the associated network address.
func ConfigGetBool ¶
ConfigGetBool is a convenience for loading the cluster configuration and returning the value of a particular boolean key.
It's a deprecated API meant to be used by call sites that are not interacting with the database in a transactional way.
func ConfigGetInt64 ¶
ConfigGetInt64 is a convenience for loading the cluster configuration and returning the value of a particular key.
It's a deprecated API meant to be used by call sites that are not interacting with the database in a transactional way.
func ConfigGetString ¶
ConfigGetString is a convenience for loading the cluster configuration and returning the value of a particular key.
It's a deprecated API meant to be used by call sites that are not interacting with the database in a transactional way.
func Connect ¶
Connect is a convenience around lxd.ConnectLXD that configures the client with the correct parameters for node-to-node communication.
If 'notify' switch is true, then the user agent will be set to the special value 'lxd-cluster-notifier', which can be used in some cases to distinguish between a regular client request and an internal cluster request.
func ConnectIfContainerIsRemote ¶
func ConnectIfContainerIsRemote(cluster *db.Cluster, name string, cert *shared.CertInfo) (lxd.ContainerServer, error)
ConnectIfContainerIsRemote figures out the address of the node which is running the container with the given name. If it's not the local node will connect to it and return the connected client, otherwise it will just return nil.
func ConnectIfVolumeIsRemote ¶
func ConnectIfVolumeIsRemote(cluster *db.Cluster, poolID int64, volumeName string, volumeType int, cert *shared.CertInfo) (lxd.ContainerServer, error)
ConnectIfVolumeIsRemote figures out the address of the node on which the volume with the given name is defined. If it's not the local node will connect to it and return the connected client, otherwise it will just return nil.
If there is more than one node with a matching volume name, an error is returned.
func Events ¶
func Events(endpoints *endpoints.Endpoints, cluster *db.Cluster, f func(int64, interface{})) (task.Func, task.Schedule)
Events starts a task that continuously monitors the list of cluster nodes and maintains a pool of websocket connections against all of them, in order to get notified about events.
Whenever an event is received the given callback is invoked.
func Heartbeat ¶
Heartbeat returns a task function that performs leader-initiated heartbeat checks against all LXD nodes in the cluster.
It will update the heartbeat timestamp column of the nodes table accordingly, and also notify them of the current list of database nodes.
func Join ¶
func Join(state *state.State, gateway *Gateway, cert *shared.CertInfo, name string, nodes []db.RaftNode) error
Join makes a non-clustered LXD node join an existing cluster.
It's assumed that Accept() was previously called against the target node, which handed the raft server ID.
The cert parameter must contain the keypair/CA material of the cluster being joined.
func Leave ¶
Leave a cluster.
If the force flag is true, the node will leave even if it still has containers and images.
The node will only leave the raft cluster, and won't be removed from the database. That's done by Purge().
Upon success, return the address of the leaving node.
func List ¶
func List(state *state.State) ([]api.ClusterMember, error)
List the nodes of the cluster.
func NotifyUpgradeCompleted ¶
NotifyUpgradeCompleted sends a notification to all other nodes in the cluster that any possible pending database update has been applied, and any nodes which was waiting for this node to be upgraded should re-check if it's okay to move forward.
func ResolveTarget ¶
ResolveTarget is a convenience for handling the value ?targetNode query parameter. It returns the address of the given node, or the empty string if the given node is the local one.
func SetupTrust ¶
SetupTrust is a convenience around ContainerServer.CreateCertificate that adds the given client certificate to the trusted pool of the cluster at the given address, using the given password.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds cluster-wide configuration values.
func ConfigLoad ¶
ConfigLoad loads a new Config object with the current cluster configuration values fetched from the database.
func (*Config) AutoUpdateInterval ¶
AutoUpdateInterval returns the configured images auto update interval.
func (*Config) Dump ¶
Dump current configuration keys and their values. Keys with values matching their defaults are omitted.
func (*Config) HTTPSAllowedCredentials ¶
HTTPSAllowedCredentials returns the relevant CORS setting.
func (*Config) HTTPSAllowedHeaders ¶
HTTPSAllowedHeaders returns the relevant CORS setting.
func (*Config) HTTPSAllowedMethods ¶
HTTPSAllowedMethods returns the relevant CORS setting.
func (*Config) HTTPSAllowedOrigin ¶
HTTPSAllowedOrigin returns the relevant CORS setting.
func (*Config) MAASController ¶
MAASController the configured MAAS url and key, if any.
func (*Config) MacaroonEndpoint ¶
MacaroonEndpoint returns the address of the macaroon endpoint to use for authentication, if any.
func (*Config) OfflineThreshold ¶
OfflineThreshold returns the configured heartbeat threshold, i.e. the number of seconds before after which an unresponsive node is considered offline..
func (*Config) Patch ¶
Patch changes only the configuration keys in the given map.
Return what has actually changed.
func (*Config) ProxyHTTPS ¶
ProxyHTTPS returns the configured HTTPS proxy, if any.
func (*Config) ProxyIgnoreHosts ¶
ProxyIgnoreHosts returns the configured ignore-hosts proxy setting, if any.
func (*Config) RemoteCacheExpiry ¶
RemoteCacheExpiry returns the configured expiration value for remote images expiration.
func (*Config) Replace ¶
Replace the current configuration with the given values.
Return what has actually changed.
func (*Config) TrustPassword ¶
TrustPassword returns the LXD trust password for authenticating clients.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway mediates access to the dqlite cluster using a gRPC SQL client, and possibly runs a dqlite replica on this LXD node (if we're configured to do so).
func NewGateway ¶
NewGateway creates a new Gateway for managing access to the dqlite cluster.
When a new gateway is created, the node-level database is queried to check what kind of role this node plays and if it's exposed over the network. It will initialize internal data structures accordingly, for example starting a dqlite driver if this node is a database node.
After creation, the Daemon is expected to expose whatever http handlers the HandlerFuncs method returns and to access the dqlite cluster using the gRPC dialer returned by the Dialer method.
func (*Gateway) Dialer ¶
func (g *Gateway) Dialer() grpcsql.Dialer
Dialer returns a gRPC dial function that can be used to connect to one of the dqlite nodes via gRPC.
func (*Gateway) HandlerFuncs ¶
func (g *Gateway) HandlerFuncs() map[string]http.HandlerFunc
HandlerFuncs returns the HTTP handlers that should be added to the REST API endpoint in order to handle database-related requests.
There are two handlers, one for the /internal/raft endpoint and the other for /internal/db, which handle respectively raft and gRPC-SQL requests.
These handlers might return 404, either because this LXD node is a non-clustered node not available over the network or because it is not a database node part of the dqlite cluster.
func (*Gateway) Kill ¶
func (g *Gateway) Kill()
Kill is an API that the daemon calls before it actually shuts down and calls Shutdown(). It will abort any ongoing or new attempt to establish a SQL gRPC connection with the dialer (typically for running some pre-shutdown queries).
func (*Gateway) LeaderAddress ¶
LeaderAddress returns the address of the current raft leader.
func (*Gateway) Reset ¶
Reset the gateway, shutting it down and starting against from scratch using the given certificate.
This is used when disabling clustering on a node.
func (*Gateway) Shutdown ¶
Shutdown this gateway, stopping the gRPC server and possibly the raft factory.
func (*Gateway) WaitUpgradeNotification ¶
func (g *Gateway) WaitUpgradeNotification()
WaitUpgradeNotification waits for a notification from another node that all nodes in the cluster should now have been upgraded and have matching schema and API versions.
type Notifier ¶
type Notifier func(hook func(lxd.ContainerServer) error) error
Notifier is a function that invokes the given function against each node in the cluster excluding the invoking one.
func NewNotifier ¶
func NewNotifier(state *state.State, cert *shared.CertInfo, policy NotifierPolicy) (Notifier, error)
NewNotifier builds a Notifier that can be used to notify other peers using the given policy.
type NotifierPolicy ¶
type NotifierPolicy int
NotifierPolicy can be used to tweak the behavior of NewNotifier in case of some nodes are down.
const ( NotifyAll NotifierPolicy = iota // Requires that all nodes are up. NotifyAlive // Only notifies nodes that are alive )
Possible notifcation policies.
type Option ¶
type Option func(*options)
Option to be passed to NewGateway to customize the resulting instance.
func Latency ¶
Latency is a coarse grain measure of how fast/reliable network links are. This is used to tweak the various timeouts parameters of the raft algorithm. See the raft.Config structure for more details. A value of 1.0 means use the default values from hashicorp's raft package. Values closer to 0 reduce the values of the various timeouts (useful when running unit tests in-memory).