Documentation ¶
Overview ¶
Package cluster provides types and functions for management of Docker clusters, scheduling container operations among hosts running Docker (nodes).
Package cluster provides types and functions for management of Docker clusters, scheduling container operations among hosts running Docker (nodes).
Index ¶
- Constants
- type Cluster
- func (c *Cluster) AddHook(evt HookEvent, h Hook)
- func (c *Cluster) AtomicUpdateNode(address string, updateFunc func(Node) (Node, error)) (Node, error)
- func (c *Cluster) AttachToContainer(opts docker.AttachToContainerOptions) error
- func (c *Cluster) AttachToContainerNonBlocking(opts docker.AttachToContainerOptions) (docker.CloseWaiter, error)
- func (c *Cluster) BuildImage(buildOptions docker.BuildImageOptions) error
- func (c *Cluster) CommitContainer(opts docker.CommitContainerOptions) (*docker.Image, error)
- func (c *Cluster) CreateContainer(opts docker.CreateContainerOptions, inactivityTimeout time.Duration, ...) (string, *docker.Container, error)
- func (c *Cluster) CreateContainerPullOptsSchedulerOpts(opts docker.CreateContainerOptions, pullOpts docker.PullImageOptions, ...) (string, *docker.Container, error)
- func (c *Cluster) CreateContainerSchedulerOpts(opts docker.CreateContainerOptions, schedulerOpts SchedulerOptions, ...) (string, *docker.Container, error)
- func (c *Cluster) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error)
- func (c *Cluster) DownloadFromContainer(containerId string, opts docker.DownloadFromContainerOptions) error
- func (c *Cluster) DryMode() error
- func (c *Cluster) ExportContainer(opts docker.ExportContainerOptions) error
- func (c *Cluster) GetNode(address string) (Node, error)
- func (c *Cluster) Hooks(evt HookEvent) []Hook
- func (c *Cluster) ImageHistory(repo string) ([]docker.ImageHistory, error)
- func (c *Cluster) ImportImage(opts docker.ImportImageOptions) error
- func (c *Cluster) InspectContainer(id string) (*docker.Container, error)
- func (c *Cluster) InspectExec(execId string) (*docker.ExecInspect, error)
- func (c *Cluster) InspectImage(repo string) (*docker.Image, error)
- func (c *Cluster) KillContainer(opts docker.KillContainerOptions) error
- func (c *Cluster) ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)
- func (c *Cluster) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)
- func (c *Cluster) Logs(opts docker.LogsOptions) error
- func (c *Cluster) Nodes() ([]Node, error)
- func (c *Cluster) NodesForMetadata(metadata map[string]string) ([]Node, error)
- func (c *Cluster) PauseContainer(id string) error
- func (c *Cluster) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration, nodes ...string) error
- func (c *Cluster) PushImage(opts docker.PushImageOptions, auth docker.AuthConfiguration) error
- func (c *Cluster) Register(node Node) error
- func (c *Cluster) RemoveContainer(opts docker.RemoveContainerOptions) error
- func (c *Cluster) RemoveImage(name string) error
- func (c *Cluster) ResizeContainerTTY(containerId string, height, width int) error
- func (c *Cluster) ResizeExecTTY(execId string, height, width int) error
- func (c *Cluster) RestartContainer(id string, timeout uint) error
- func (c *Cluster) StartActiveMonitoring(updateInterval time.Duration)
- func (c *Cluster) StartContainer(id string, hostConfig *docker.HostConfig) error
- func (c *Cluster) StartExec(execId string, opts docker.StartExecOptions) error
- func (c *Cluster) StopActiveMonitoring()
- func (c *Cluster) StopContainer(id string, timeout uint) error
- func (c *Cluster) StopDryMode()
- func (c *Cluster) TagImage(name string, opts docker.TagImageOptions) error
- func (c *Cluster) TopContainer(id string, psArgs string) (docker.TopResult, error)
- func (c *Cluster) UnfilteredNodes() ([]Node, error)
- func (c *Cluster) UnfilteredNodesForMetadata(metadata map[string]string) ([]Node, error)
- func (c *Cluster) UnpauseContainer(id string) error
- func (c *Cluster) Unregister(address string) error
- func (c *Cluster) UnregisterNodes(addresses ...string) error
- func (c *Cluster) UpdateNode(node Node) (Node, error)
- func (c *Cluster) UploadToContainer(containerId string, opts docker.UploadToContainerOptions) error
- func (c *Cluster) WaitContainer(id string) (int, error)
- type Container
- type ContainerStorage
- type DefaultHealer
- type DockerNodeError
- type ExecStorage
- type Healer
- type HealingData
- type Hook
- type HookEvent
- type Image
- type ImageHistory
- type ImageStorage
- type MapStorage
- func (s *MapStorage) ExtendNodeLock(address string, timeout time.Duration) error
- func (s *MapStorage) LockNodeForHealing(address string, isFailure bool, timeout time.Duration) (bool, error)
- func (s *MapStorage) RemoveContainer(containerID string) error
- func (s *MapStorage) RemoveImage(repo, id, host string) error
- func (s *MapStorage) RemoveNode(addr string) error
- func (s *MapStorage) RemoveNodes(addresses []string) error
- func (s *MapStorage) RetrieveContainer(containerID string) (string, error)
- func (s *MapStorage) RetrieveContainers() ([]Container, error)
- func (s *MapStorage) RetrieveExec(execID string) (containerID string, err error)
- func (s *MapStorage) RetrieveImage(repo string) (Image, error)
- func (s *MapStorage) RetrieveImages() ([]Image, error)
- func (s *MapStorage) RetrieveNode(address string) (Node, error)
- func (s *MapStorage) RetrieveNodes() ([]Node, error)
- func (s *MapStorage) RetrieveNodesByMetadata(metadata map[string]string) ([]Node, error)
- func (s *MapStorage) SetImageDigest(repo, digest string) error
- func (s *MapStorage) StoreContainer(containerID, hostID string) error
- func (s *MapStorage) StoreExec(execID, containerID string) error
- func (s *MapStorage) StoreImage(repo, id, host string) error
- func (s *MapStorage) StoreNode(node Node) error
- func (s *MapStorage) UnlockNode(address string) error
- func (s *MapStorage) UpdateNode(node Node) error
- type Node
- func (n *Node) CleanMetadata() map[string]string
- func (n *Node) Client() (*docker.Client, error)
- func (n *Node) ExtraMetadata() map[string]string
- func (n *Node) FailureCount() int
- func (n *Node) HasSuccess() bool
- func (n Node) MarshalJSON() ([]byte, error)
- func (n *Node) ResetFailures()
- func (n *Node) Status() string
- type NodeList
- type NodeStorage
- type Scheduler
- type SchedulerOptions
- type Storage
Constants ¶
const ( HookEventBeforeContainerCreate = iota HookEventBeforeNodeRegister HookEventBeforeNodeUnregister )
const ( NodeStatusWaiting = "waiting" NodeStatusReady = "ready" NodeStatusRetry = "ready for retry" NodeStatusTemporarilyDisabled = "temporarily disabled" NodeStatusHealing = "healing" NodeCreationStatusCreated = "created" NodeCreationStatusError = "error" NodeCreationStatusPending = "pending" NodeCreationStatusDisabled = "disabled" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct { Healer Healer // contains filtered or unexported fields }
Cluster is the basic type of the package. It manages internal nodes, and provide methods for interaction with those nodes, like CreateContainer, which creates a container in one node of the cluster.
func New ¶
New creates a new Cluster, initially composed by the given nodes.
The scheduler parameter defines the scheduling strategy. It defaults to round robin if nil. The storage parameter is the storage the cluster instance will use.
func (*Cluster) AtomicUpdateNode ¶
func (*Cluster) AttachToContainer ¶
AttachToContainer attaches to a container, using the given options.
func (*Cluster) AttachToContainerNonBlocking ¶
func (c *Cluster) AttachToContainerNonBlocking(opts docker.AttachToContainerOptions) (docker.CloseWaiter, error)
AttachToContainerNonBlocking attaches to a container and returns a docker.CloseWaiter, using given options.
func (*Cluster) BuildImage ¶
BuildImage build an image and pushes it to registry
func (*Cluster) CommitContainer ¶
CommitContainer commits a container and returns the image id.
func (*Cluster) CreateContainer ¶
func (c *Cluster) CreateContainer(opts docker.CreateContainerOptions, inactivityTimeout time.Duration, nodes ...string) (string, *docker.Container, error)
CreateContainer creates a container in the specified node. If no node is specified, it will create the container in a node selected by the scheduler.
It returns the container, or an error, in case of failures.
func (*Cluster) CreateContainerPullOptsSchedulerOpts ¶
func (c *Cluster) CreateContainerPullOptsSchedulerOpts(opts docker.CreateContainerOptions, pullOpts docker.PullImageOptions, pullAuth docker.AuthConfiguration, schedulerOpts SchedulerOptions, nodes ...string) (string, *docker.Container, error)
Similar to CreateContainer but allows arbritary options to be passed to the scheduler and to the pull image call.
func (*Cluster) CreateContainerSchedulerOpts ¶
func (c *Cluster) CreateContainerSchedulerOpts(opts docker.CreateContainerOptions, schedulerOpts SchedulerOptions, inactivityTimeout time.Duration, nodes ...string) (string, *docker.Container, error)
Similar to CreateContainer but allows arbritary options to be passed to the scheduler.
func (*Cluster) CreateExec ¶
func (*Cluster) DownloadFromContainer ¶
func (*Cluster) ExportContainer ¶
ExportContainer exports a container as a tar and writes the result in out.
func (*Cluster) ImageHistory ¶
ImageHistory returns the history of a given image
func (*Cluster) ImportImage ¶
ImportImage imports an image from a url or stdin
func (*Cluster) InspectContainer ¶
InspectContainer returns information about a container by its ID, getting the information from the right node.
func (*Cluster) InspectExec ¶
func (*Cluster) InspectImage ¶
InspectImage inspects an image based on its repo name
func (*Cluster) KillContainer ¶
KillContainer kills a container, returning an error in case of failure.
func (*Cluster) ListContainers ¶
ListContainers returns a slice of all containers in the cluster matching the given criteria.
func (*Cluster) ListImages ¶
ListImages lists images existing in each cluster node
func (*Cluster) NodesForMetadata ¶
func (*Cluster) PauseContainer ¶
PauseContainer changes the container to the paused state.
func (*Cluster) PullImage ¶
func (c *Cluster) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration, nodes ...string) error
PullImage pulls an image from a remote registry server, returning an error in case of failure.
It will pull all images in parallel, so users need to make sure that the given buffer is safe.
func (*Cluster) PushImage ¶
PushImage pushes an image to a remote registry server, returning an error in case of failure.
func (*Cluster) RemoveContainer ¶
RemoveContainer removes a container from the cluster.
func (*Cluster) RemoveImage ¶
RemoveImage removes an image from the nodes where this images exists, returning an error in case of failure. Will wait for the image to be removed on all nodes.
func (*Cluster) ResizeContainerTTY ¶
func (*Cluster) ResizeExecTTY ¶
func (*Cluster) RestartContainer ¶
RestartContainer restarts a container, killing it after the given timeout, if it fails to stop nicely.
func (*Cluster) StartActiveMonitoring ¶
func (*Cluster) StartContainer ¶
func (*Cluster) StopActiveMonitoring ¶
func (c *Cluster) StopActiveMonitoring()
func (*Cluster) StopContainer ¶
StopContainer stops a container, killing it after the given timeout, if it fails to stop nicely.
func (*Cluster) StopDryMode ¶
func (c *Cluster) StopDryMode()
func (*Cluster) TagImage ¶
TagImage adds a tag to the given image, returning an error in case of failure.
func (*Cluster) TopContainer ¶
TopContainer returns information about running processes inside a container by its ID, getting the information from the right node.
func (*Cluster) UnfilteredNodes ¶
func (*Cluster) UnfilteredNodesForMetadata ¶
func (*Cluster) UnpauseContainer ¶
UnpauseContainer removes the container from the paused state.
func (*Cluster) Unregister ¶
Unregister removes nodes from the cluster.
func (*Cluster) UnregisterNodes ¶
func (*Cluster) UploadToContainer ¶
type ContainerStorage ¶
type ContainerStorage interface { StoreContainer(container, host string) error RetrieveContainer(container string) (host string, err error) RemoveContainer(container string) error RetrieveContainers() ([]Container, error) }
ContainerStorage provides methods to store and retrieve information about the relation between the node and the container. It can be easily represented as a key-value storage.
The relevant information is: in which host the given container is running?
type DefaultHealer ¶
type DefaultHealer struct{}
func (DefaultHealer) HandleError ¶
func (DefaultHealer) HandleError(node *Node) time.Duration
type DockerNodeError ¶
type DockerNodeError struct {
// contains filtered or unexported fields
}
func (DockerNodeError) BaseError ¶
func (n DockerNodeError) BaseError() error
func (DockerNodeError) Error ¶
func (n DockerNodeError) Error() string
type ExecStorage ¶
type ExecStorage interface { StoreExec(execID, containerID string) error RetrieveExec(execID string) (host string, err error) }
ExecStorage works like ContainerStorage, but stores information about execID and containerID.
type HealingData ¶
type Image ¶
type Image struct { Repository string `bson:"_id"` LastNode string LastId string LastDigest string History []ImageHistory }
type ImageHistory ¶
type ImageStorage ¶
type ImageStorage interface { StoreImage(repo, id, host string) error RetrieveImage(repo string) (Image, error) RemoveImage(repo, id, host string) error RetrieveImages() ([]Image, error) SetImageDigest(repo, digest string) error }
ImageStorage works like ContainerStorage, but stores information about images and hosts.
type MapStorage ¶
type MapStorage struct {
// contains filtered or unexported fields
}
func (*MapStorage) ExtendNodeLock ¶
func (s *MapStorage) ExtendNodeLock(address string, timeout time.Duration) error
func (*MapStorage) LockNodeForHealing ¶
func (*MapStorage) RemoveContainer ¶
func (s *MapStorage) RemoveContainer(containerID string) error
func (*MapStorage) RemoveImage ¶
func (s *MapStorage) RemoveImage(repo, id, host string) error
func (*MapStorage) RemoveNode ¶
func (s *MapStorage) RemoveNode(addr string) error
func (*MapStorage) RemoveNodes ¶
func (s *MapStorage) RemoveNodes(addresses []string) error
func (*MapStorage) RetrieveContainer ¶
func (s *MapStorage) RetrieveContainer(containerID string) (string, error)
func (*MapStorage) RetrieveContainers ¶
func (s *MapStorage) RetrieveContainers() ([]Container, error)
func (*MapStorage) RetrieveExec ¶
func (s *MapStorage) RetrieveExec(execID string) (containerID string, err error)
func (*MapStorage) RetrieveImage ¶
func (s *MapStorage) RetrieveImage(repo string) (Image, error)
func (*MapStorage) RetrieveImages ¶
func (s *MapStorage) RetrieveImages() ([]Image, error)
func (*MapStorage) RetrieveNode ¶
func (s *MapStorage) RetrieveNode(address string) (Node, error)
func (*MapStorage) RetrieveNodes ¶
func (s *MapStorage) RetrieveNodes() ([]Node, error)
func (*MapStorage) RetrieveNodesByMetadata ¶
func (s *MapStorage) RetrieveNodesByMetadata(metadata map[string]string) ([]Node, error)
func (*MapStorage) SetImageDigest ¶
func (s *MapStorage) SetImageDigest(repo, digest string) error
func (*MapStorage) StoreContainer ¶
func (s *MapStorage) StoreContainer(containerID, hostID string) error
func (*MapStorage) StoreExec ¶
func (s *MapStorage) StoreExec(execID, containerID string) error
func (*MapStorage) StoreImage ¶
func (s *MapStorage) StoreImage(repo, id, host string) error
func (*MapStorage) StoreNode ¶
func (s *MapStorage) StoreNode(node Node) error
func (*MapStorage) UnlockNode ¶
func (s *MapStorage) UnlockNode(address string) error
func (*MapStorage) UpdateNode ¶
func (s *MapStorage) UpdateNode(node Node) error
type Node ¶
type Node struct { Address string `bson:"_id"` Healing HealingData Metadata map[string]string CreationStatus string CaCert []byte ClientCert []byte ClientKey []byte // contains filtered or unexported fields }
Node represents a host running Docker. Each node has an Address (in the form <scheme>://<host>:<port>/) and a map with arbritary metadata.
func (*Node) CleanMetadata ¶
func (*Node) ExtraMetadata ¶
func (*Node) FailureCount ¶
func (*Node) HasSuccess ¶
func (Node) MarshalJSON ¶
func (*Node) ResetFailures ¶
func (n *Node) ResetFailures()
type NodeStorage ¶
type NodeStorage interface { StoreNode(node Node) error RetrieveNodesByMetadata(metadata map[string]string) ([]Node, error) RetrieveNodes() ([]Node, error) RetrieveNode(address string) (Node, error) UpdateNode(node Node) error RemoveNode(address string) error RemoveNodes(addresses []string) error LockNodeForHealing(address string, isFailure bool, timeout time.Duration) (bool, error) ExtendNodeLock(address string, timeout time.Duration) error UnlockNode(address string) error }
type Scheduler ¶
type Scheduler interface { // Schedule creates a new container, returning the ID of the node where // the container is running, and the container, or an error. Schedule(c *Cluster, opts *docker.CreateContainerOptions, schedulerOpts SchedulerOptions) (Node, error) }
Scheduler represents a scheduling strategy, that will be used when creating new containers.
type SchedulerOptions ¶
type SchedulerOptions interface{}
Arbitrary options to be sent to the scheduler. This options will be only read and interpreted by the scheduler itself.
type Storage ¶
type Storage interface { ContainerStorage ImageStorage NodeStorage ExecStorage }