cluster

package
v0.0.0-...-e623927 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func Bootstrap(state *state.State, gateway *Gateway, name string) error

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

func ConfigGetBool(cluster *db.Cluster, key string) (bool, error)

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

func ConfigGetInt64(cluster *db.Cluster, key string) (int64, error)

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

func ConfigGetString(cluster *db.Cluster, key string) (string, error)

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

func Connect(address string, cert *shared.CertInfo, notify bool) (lxd.ContainerServer, error)

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 Count

func Count(state *state.State) (int, error)

Count is a convenience for checking the current number of nodes in the cluster.

func Enabled

func Enabled(node *db.Node) (bool, error)

Enabled is a convenience that returns true if clustering is enabled on this node.

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

func Heartbeat(gateway *Gateway, cluster *db.Cluster) (task.Func, task.Schedule)

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

func Leave(state *state.State, gateway *Gateway, name string, force bool) (string, error)

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

func NotifyUpgradeCompleted(state *state.State, cert *shared.CertInfo) error

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 Purge

func Purge(cluster *db.Cluster, name string) error

Purge removes a node entirely from the cluster database.

func ResolveTarget

func ResolveTarget(cluster *db.Cluster, target string) (string, error)

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

func SetupTrust(cert, targetAddress, targetCert, targetPassword string) error

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

func ConfigLoad(tx *db.ClusterTx) (*Config, error)

ConfigLoad loads a new Config object with the current cluster configuration values fetched from the database.

func (*Config) AutoUpdateInterval

func (c *Config) AutoUpdateInterval() time.Duration

AutoUpdateInterval returns the configured images auto update interval.

func (*Config) Dump

func (c *Config) Dump() map[string]interface{}

Dump current configuration keys and their values. Keys with values matching their defaults are omitted.

func (*Config) HTTPSAllowedCredentials

func (c *Config) HTTPSAllowedCredentials() bool

HTTPSAllowedCredentials returns the relevant CORS setting.

func (*Config) HTTPSAllowedHeaders

func (c *Config) HTTPSAllowedHeaders() string

HTTPSAllowedHeaders returns the relevant CORS setting.

func (*Config) HTTPSAllowedMethods

func (c *Config) HTTPSAllowedMethods() string

HTTPSAllowedMethods returns the relevant CORS setting.

func (*Config) HTTPSAllowedOrigin

func (c *Config) HTTPSAllowedOrigin() string

HTTPSAllowedOrigin returns the relevant CORS setting.

func (*Config) MAASController

func (c *Config) MAASController() (string, string)

MAASController the configured MAAS url and key, if any.

func (*Config) MacaroonEndpoint

func (c *Config) MacaroonEndpoint() string

MacaroonEndpoint returns the address of the macaroon endpoint to use for authentication, if any.

func (*Config) OfflineThreshold

func (c *Config) OfflineThreshold() time.Duration

OfflineThreshold returns the configured heartbeat threshold, i.e. the number of seconds before after which an unresponsive node is considered offline..

func (*Config) Patch

func (c *Config) Patch(patch map[string]interface{}) (map[string]string, error)

Patch changes only the configuration keys in the given map.

Return what has actually changed.

func (*Config) ProxyHTTP

func (c *Config) ProxyHTTP() string

ProxyHTTP returns the configured HTTP proxy, if any.

func (*Config) ProxyHTTPS

func (c *Config) ProxyHTTPS() string

ProxyHTTPS returns the configured HTTPS proxy, if any.

func (*Config) ProxyIgnoreHosts

func (c *Config) ProxyIgnoreHosts() string

ProxyIgnoreHosts returns the configured ignore-hosts proxy setting, if any.

func (*Config) RemoteCacheExpiry

func (c *Config) RemoteCacheExpiry() int64

RemoteCacheExpiry returns the configured expiration value for remote images expiration.

func (*Config) Replace

func (c *Config) Replace(values map[string]interface{}) (map[string]string, error)

Replace the current configuration with the given values.

Return what has actually changed.

func (*Config) TrustPassword

func (c *Config) TrustPassword() string

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

func NewGateway(db *db.Node, cert *shared.CertInfo, options ...Option) (*Gateway, error)

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

func (g *Gateway) LeaderAddress() (string, error)

LeaderAddress returns the address of the current raft leader.

func (*Gateway) Reset

func (g *Gateway) Reset(cert *shared.CertInfo) error

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

func (g *Gateway) Shutdown() error

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

func Latency(latency float64) Option

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).

func LogLevel

func LogLevel(level string) Option

LogLevel sets the logging level for messages emitted by dqlite and raft.

Jump to

Keyboard shortcuts

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