cluster

package
v0.0.0-...-f372d8d Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: BSD-3-Clause Imports: 24 Imported by: 10

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

View Source
const (
	HookEventBeforeContainerCreate = iota
	HookEventBeforeNodeRegister
	HookEventBeforeNodeUnregister
)
View Source
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

func New(scheduler Scheduler, storage Storage, caPath string, nodes ...Node) (*Cluster, error)

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

func (c *Cluster) AddHook(evt HookEvent, h Hook)

func (*Cluster) AtomicUpdateNode

func (c *Cluster) AtomicUpdateNode(address string, updateFunc func(Node) (Node, error)) (Node, error)

func (*Cluster) AttachToContainer

func (c *Cluster) AttachToContainer(opts docker.AttachToContainerOptions) error

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

func (c *Cluster) BuildImage(buildOptions docker.BuildImageOptions) error

BuildImage build an image and pushes it to registry

func (*Cluster) CommitContainer

func (c *Cluster) CommitContainer(opts docker.CommitContainerOptions) (*docker.Image, error)

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 (c *Cluster) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error)

func (*Cluster) DownloadFromContainer

func (c *Cluster) DownloadFromContainer(containerId string, opts docker.DownloadFromContainerOptions) error

func (*Cluster) DryMode

func (c *Cluster) DryMode() error

func (*Cluster) ExportContainer

func (c *Cluster) ExportContainer(opts docker.ExportContainerOptions) error

ExportContainer exports a container as a tar and writes the result in out.

func (*Cluster) GetNode

func (c *Cluster) GetNode(address string) (Node, error)

func (*Cluster) Hooks

func (c *Cluster) Hooks(evt HookEvent) []Hook

func (*Cluster) ImageHistory

func (c *Cluster) ImageHistory(repo string) ([]docker.ImageHistory, error)

ImageHistory returns the history of a given image

func (*Cluster) ImportImage

func (c *Cluster) ImportImage(opts docker.ImportImageOptions) error

ImportImage imports an image from a url or stdin

func (*Cluster) InspectContainer

func (c *Cluster) InspectContainer(id string) (*docker.Container, error)

InspectContainer returns information about a container by its ID, getting the information from the right node.

func (*Cluster) InspectExec

func (c *Cluster) InspectExec(execId string) (*docker.ExecInspect, error)

func (*Cluster) InspectImage

func (c *Cluster) InspectImage(repo string) (*docker.Image, error)

InspectImage inspects an image based on its repo name

func (*Cluster) KillContainer

func (c *Cluster) KillContainer(opts docker.KillContainerOptions) error

KillContainer kills a container, returning an error in case of failure.

func (*Cluster) ListContainers

func (c *Cluster) ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)

ListContainers returns a slice of all containers in the cluster matching the given criteria.

func (*Cluster) ListImages

func (c *Cluster) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)

ListImages lists images existing in each cluster node

func (*Cluster) Logs

func (c *Cluster) Logs(opts docker.LogsOptions) error

Logs retrieves the logs of the specified container.

func (*Cluster) Nodes

func (c *Cluster) Nodes() ([]Node, error)

func (*Cluster) NodesForMetadata

func (c *Cluster) NodesForMetadata(metadata map[string]string) ([]Node, error)

func (*Cluster) PauseContainer

func (c *Cluster) PauseContainer(id string) error

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

func (c *Cluster) PushImage(opts docker.PushImageOptions, auth docker.AuthConfiguration) error

PushImage pushes an image to a remote registry server, returning an error in case of failure.

func (*Cluster) Register

func (c *Cluster) Register(node Node) error

Register adds new nodes to the cluster.

func (*Cluster) RemoveContainer

func (c *Cluster) RemoveContainer(opts docker.RemoveContainerOptions) error

RemoveContainer removes a container from the cluster.

func (*Cluster) RemoveImage

func (c *Cluster) RemoveImage(name string) error

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 (c *Cluster) ResizeContainerTTY(containerId string, height, width int) error

func (*Cluster) ResizeExecTTY

func (c *Cluster) ResizeExecTTY(execId string, height, width int) error

func (*Cluster) RestartContainer

func (c *Cluster) RestartContainer(id string, timeout uint) error

RestartContainer restarts a container, killing it after the given timeout, if it fails to stop nicely.

func (*Cluster) StartActiveMonitoring

func (c *Cluster) StartActiveMonitoring(updateInterval time.Duration)

func (*Cluster) StartContainer

func (c *Cluster) StartContainer(id string, hostConfig *docker.HostConfig) error

func (*Cluster) StartExec

func (c *Cluster) StartExec(execId string, opts docker.StartExecOptions) error

func (*Cluster) StopActiveMonitoring

func (c *Cluster) StopActiveMonitoring()

func (*Cluster) StopContainer

func (c *Cluster) StopContainer(id string, timeout uint) error

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

func (c *Cluster) TagImage(name string, opts docker.TagImageOptions) error

TagImage adds a tag to the given image, returning an error in case of failure.

func (*Cluster) TopContainer

func (c *Cluster) TopContainer(id string, psArgs string) (docker.TopResult, error)

TopContainer returns information about running processes inside a container by its ID, getting the information from the right node.

func (*Cluster) UnfilteredNodes

func (c *Cluster) UnfilteredNodes() ([]Node, error)

func (*Cluster) UnfilteredNodesForMetadata

func (c *Cluster) UnfilteredNodesForMetadata(metadata map[string]string) ([]Node, error)

func (*Cluster) UnpauseContainer

func (c *Cluster) UnpauseContainer(id string) error

UnpauseContainer removes the container from the paused state.

func (*Cluster) Unregister

func (c *Cluster) Unregister(address string) error

Unregister removes nodes from the cluster.

func (*Cluster) UnregisterNodes

func (c *Cluster) UnregisterNodes(addresses ...string) error

func (*Cluster) UpdateNode

func (c *Cluster) UpdateNode(node Node) (Node, error)

func (*Cluster) UploadToContainer

func (c *Cluster) UploadToContainer(containerId string, opts docker.UploadToContainerOptions) error

func (*Cluster) WaitContainer

func (c *Cluster) WaitContainer(id string) (int, error)

WaitContainer blocks until the given container stops, returning the exit code of the container command.

type Container

type Container struct {
	Id   string `bson:"_id"`
	Host string
}

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 Healer

type Healer interface {
	HandleError(node *Node) time.Duration
}

type HealingData

type HealingData struct {
	LockedUntil time.Time
	IsFailure   bool
}

type Hook

type Hook interface {
	RunClusterHook(evt HookEvent, node *Node) error
}

type HookEvent

type HookEvent int

type Image

type Image struct {
	Repository string `bson:"_id"`
	LastNode   string
	LastId     string
	LastDigest string
	History    []ImageHistory
}

type ImageHistory

type ImageHistory struct {
	Node    string
	ImageId string
}

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 (s *MapStorage) LockNodeForHealing(address string, isFailure bool, timeout time.Duration) (bool, error)

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 (n *Node) CleanMetadata() map[string]string

func (*Node) Client

func (n *Node) Client() (*docker.Client, error)

func (*Node) ExtraMetadata

func (n *Node) ExtraMetadata() map[string]string

func (*Node) FailureCount

func (n *Node) FailureCount() int

func (*Node) HasSuccess

func (n *Node) HasSuccess() bool

func (Node) MarshalJSON

func (n Node) MarshalJSON() ([]byte, error)

func (*Node) ResetFailures

func (n *Node) ResetFailures()

func (*Node) Status

func (n *Node) Status() string

type NodeList

type NodeList []Node

func (NodeList) Len

func (a NodeList) Len() int

func (NodeList) Less

func (a NodeList) Less(i, j int) bool

func (NodeList) Swap

func (a NodeList) Swap(i, j int)

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.

Jump to

Keyboard shortcuts

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