citadel

package module
v0.0.0-...-3d3f5d9 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2014 License: MIT Imports: 7 Imported by: 0

README

Citadel

A docker centric package for scheduling containers on a docker cluster.

Workflow

  1. User provides a container type to the scheduler specifying the image, cpus, memory, and other constraints required in the decision making of where this container should be run on the cluster. This is the json representation of what a sample request would look like:
{
    "image": "crosbymichael/redis",
    "cpus": "0.2",
    "memory": 512,
    "type": "service"
}
  1. Depending on the container type, service, batch, etc..., a specific scheduler is passed the container information for making the scheduling decision. After the scheduler has made the decision it will send it's decison on where this container should run to the cluster manager. Schedulers can run in parallel to make decisions but the cluster manager keeps the most up to date state of the cluster and gives the scheduler and yes/no if the container can run on that resource.

  2. After the cluster manager approves the change in state of the cluster then decision is returned back to the original requester along with information about the resource that can run the container. They are free to act on that information as they please. A sample response json representation of a response will look like:

{
    "container":{
        "image": "crosbymichael/redis",
        "cpus": "0.2",
        "memory": 512,
        "type": "service"
    },
    "resource": {
        "id": "12345abc",
        "addr": "192.168.56.8:4243",
        "total_cpus": 8,
        "total_memory": 32000
   }
}
  1. The cluster manager will need a way to receive and modify the cluster state. This will be provided by a Registry that the consumer of the library provides.

Concepts

Cluster Manager

The cluster manager is responsible to for making changes to the state of the cluster.

Registry

The registry stores the state of the cluster and can be queried and modified by the cluster manager. Th registry is not implemented by citadel

Scheduler

A cluster can have more than one scheduler. Schedulers can be used together or alone. Decisions by the schedulers can be made in parallel with disputes about resource placement handled when the scheduler wishes to modify the cluster state with the cluster manager.

The scheduler chosen for a specific container is dependent on the type of container being run. A resource manager maybe needed because the schedulers can make decisions about eligble resources where the container should run but the resource manager needs to have the say if that resource is able to run the container and how to best utilize resources in the cluster.

Design questions
  • Should disk and volumes be a resource like memory and cpu?
  • Are ports a resource like memory and cpu or is this not our problem?
  • Should the runs be abstracted into the package so that the cluster manager knows of a failure?
  • Should we only return one resource of where the container should run or should we return all available resources?
Wish list
  • Monitor live resource usage instead of basing information off of a static reservation.
  • Monitor live container metrics in the cluster to learn how specific images are using resources and if they match the resources requested.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterInfo

type ClusterInfo struct {
	Cpus           float64 `json:"cpus,omitempty"`
	Memory         float64 `json:"memory,omitempty"`
	ContainerCount int     `json:"container_count,omitempty"`
	EngineCount    int     `json:"engine_count,omitempty"`
	ImageCount     int     `json:"image_count,omitempty"`
	ReservedCpus   float64 `json:"reserved_cpus,omitempty"`
	ReservedMemory float64 `json:"reserved_memory,omitempty"`
}

type Container

type Container struct {
	// ID is the container's id
	ID string `json:"id,omitempty"`

	// Name is the container's name
	Name string `json:"name,omitempty"`

	// Image is the configuration from which the container was created
	Image *Image `json:"image,omitempty"`

	// Engine is the engine that is runnnig the container
	Engine *Engine `json:"engine,omitempty"`

	// State is the container state ( running stopped )
	State string `json:"state,omitempty"`

	// Ports are the public port mappings for the container
	Ports []*Port `json:"ports,omitempty"`
}

Container is a running instance

func FromDockerContainer

func FromDockerContainer(id, image string, engine *Engine) (*Container, error)

func (*Container) String

func (c *Container) String() string

type Engine

type Engine struct {
	ID     string   `json:"id,omitempty"`
	Addr   string   `json:"addr,omitempty"`
	Cpus   float64  `json:"cpus,omitempty"`
	Memory float64  `json:"memory,omitempty"`
	Labels []string `json:"labels,omitempty"`
	// contains filtered or unexported fields
}

func (*Engine) Connect

func (e *Engine) Connect(config *tls.Config) error

func (*Engine) Events

func (e *Engine) Events(h EventHandler) error

func (*Engine) IsConnected

func (e *Engine) IsConnected() bool

IsConnected returns true if the engine is connected to a remote docker API

func (*Engine) Kill

func (e *Engine) Kill(container *Container, sig int) error

func (*Engine) ListContainers

func (e *Engine) ListContainers(all bool) ([]*Container, error)

func (*Engine) ListImages

func (e *Engine) ListImages() ([]string, error)

func (*Engine) Logs

func (e *Engine) Logs(container *Container, stdout bool, stderr bool) (io.ReadCloser, error)

func (*Engine) Pull

func (e *Engine) Pull(image string) error

func (*Engine) Remove

func (e *Engine) Remove(container *Container) error

func (*Engine) Restart

func (e *Engine) Restart(container *Container, timeout int) error

func (*Engine) SetClient

func (e *Engine) SetClient(c *dockerclient.DockerClient)

func (*Engine) Start

func (e *Engine) Start(c *Container, pullImage bool) error

func (*Engine) Stop

func (e *Engine) Stop(container *Container) error

func (*Engine) String

func (e *Engine) String() string

func (*Engine) Version

func (e *Engine) Version() (*dockerclient.Version, error)

type EngineSnapshot

type EngineSnapshot struct {
	// ID is the engines id
	ID string `json:"id,omitempty"`

	Cpus float64 `json:"cpus,omitempty"`

	Memory float64 `json:"memory,omitempty"`

	// ReservedCpus is the total amount of cpus that is reserved
	ReservedCpus float64 `json:"reserved_cpus,omitempty"`

	// ReservedMemory is the total amount of memory that is reserved
	ReservedMemory float64 `json:"reserved_memory,omitempty"`

	// CurrentMemory is the current system's used memory at the time of the snapshot
	CurrentMemory float64 `json:"current_memory,omitempty"`

	// CurrentCpu is the current system's cpu usage at the time of the snapshot
	CurrentCpu float64 `json:"current_cpu,omitempty"`
}

type Event

type Event struct {
	Type      string     `json:"type,omitempty"`
	Container *Container `json:"container,omitempty"`
	Engine    *Engine    `json:"engine,omitempty"`
	Time      time.Time  `json:"time,omitempty"`
}

type EventHandler

type EventHandler interface {
	Handle(*Event) error
}

type Image

type Image struct {
	// Name is the docker image to base the container off of
	Name string `json:"name,omitempty"`

	// Cpus is the number of cpu resources to give to the container
	Cpus float64 `json:"cpus,omitempty"`

	// Cpuset is the single or multiple set of cpus on which the container can run
	Cpuset string `json:"cpuset,omitempty"`

	// Memory is the amount of memory in MB for the container
	Memory float64 `json:"memory,omitempty"`

	// Entrypoint is the entrypoint in the container
	Entrypoint []string `json:"entrypoint,omitempty"`

	// Envionrment is the environment vars to set on the container
	Environment map[string]string `json:"environment,omitempty"`

	// Hostname is the host name to set for the container
	Hostname string `json:"hostname,omitempty"`

	// Domainname is the domain name to set for the container
	Domainname string `json:"domain,omitempty"`

	// Args are cli arguments to pass to the image
	Args []string `json:"args,omitempty"`

	// Type is the container type, often service, batch, etc...
	Type string `json:"type,omitempty"`

	// Labels are matched with constraints on the engines
	Labels []string `json:"labels,omitempty"`

	// BindPorts ensures that the container has exclusive access to the specified ports
	BindPorts []*Port `json:"bind_ports,omitempty"`

	// UserData is user defined data that is passed to the container
	UserData map[string][]string `json:"user_data,omitempty"`

	// Volumes are volumes on the same engine
	Volumes []string `json:"volumes,omitempty"`

	// Links are mappings to other containers running on the same engine
	Links map[string]string `json:"links,omitempty"`

	// RestartPolicy is the container restart policy if it exits
	RestartPolicy RestartPolicy `json:"restart_policy,omitempty"`

	// Publish tells the engine to expose ports the the container externally
	Publish bool `json:"publish,omitempty"`

	// NetworkMode is the network mode for the container
	NetworkMode string `json:"network_mode,omitempty"`

	// ContainerName is the name set to the container
	ContainerName string `json:"container_name,omitempty"`
}

Image is a template for running a docker container

func (*Image) String

func (i *Image) String() string

type ImageInfo

type ImageInfo struct {
	Name string
	Tag  string
}

func ParseImageName

func ParseImageName(name string) *ImageInfo

type Port

type Port struct {
	Proto         string `json:"proto,omitempty"`
	HostIp        string `json:"host_ip,omitempty"`
	Port          int    `json:"port,omitempty"`
	ContainerPort int    `json:"container_port,omitempty"`
}

type ResourceManager

type ResourceManager interface {
	PlaceContainer(*Container, []*EngineSnapshot) (*EngineSnapshot, error)
}

type RestartPolicy

type RestartPolicy struct {
	Name              string `json:"name,omitempty"`
	MaximumRetryCount int64  `json:"maximum_retry,omitempty"`
}

type Scheduler

type Scheduler interface {
	// Schedule returns true if the engine can run the specified image
	Schedule(*Image, *Engine) (bool, error)
}

Scheduler is able to return a yes or know decision on if the specified Engine is able to run the specified image

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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