provision

package
v0.0.0-...-9f1a7a8 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package provision provides interfaces that need to be satisfied in order to implement a new provisioner on tsuru.

Index

Constants

View Source
const (
	PoolMetadataName   = "pool"
	IaaSIDMetadataName = "iaas-id"
	IaaSMetadataName   = "iaas"
)
View Source
const (
	// StatusCreated is the initial status of a unit in the database,
	// it should transition shortly to a more specific status
	StatusCreated = Status("created")

	// StatusBuilding is the status for units being provisioned by the
	// provisioner, like in the deployment.
	StatusBuilding = Status("building")

	// StatusError is the status for units that failed to start, because of
	// an application error.
	StatusError = Status("error")

	// StatusStarting is set when the container is started in docker.
	StatusStarting = Status("starting")

	// StatusStarted is for cases where the unit is up and running, and bound
	// to the proper status, it's set by RegisterUnit and SetUnitStatus.
	StatusStarted = Status("started")

	// StatusStopped is for cases where the unit has been stopped.
	StatusStopped = Status("stopped")

	// StatusAsleep is for cases where the unit has been asleep.
	StatusAsleep = Status("asleep")
)

Flow:

+----------------------------------------------+
|                                              |
|            Start                             |

+----------+ | +---------+ | | Building | +---------------------+| Stopped | | +----------+ | +---------+ |

     ^                        |                           ^                  |
     |                        |                           |                  |
deploy unit                   |                         Stop                 |
     |                        |                           |                  |
     +                        v       RegisterUnit        +                  +
+---------+  app unit   +----------+  SetUnitStatus  +---------+  Sleep  +--------+
| Created | +---------> | Starting | +-------------> | Started |+------->| Asleep |
+---------+             +----------+                 +---------+         +--------+
                              +                         ^ +
                              |                         | |
                        SetUnitStatus                   | |
                              |                         | |
                              v                         | |
                          +-------+     SetUnitStatus   | |
                          | Error | +-------------------+ |
                          +-------+ <---------------------+
View Source
const (
	DefaultHealthcheckScheme = "http"
)

Variables

View Source
var (
	ErrInvalidStatus = errors.New("invalid status")
	ErrEmptyApp      = errors.New("no units for this app")
	ErrNodeNotFound  = errors.New("node not found")

	DefaultProvisioner = defaultDockerProvisioner
)
View Source
var (
	LabelNodePool = PoolMetadataName
)

Functions

func EnvsForApp

func EnvsForApp(a App, process string, isDeploy bool) []bind.EnvVar

func ExtendServiceLabels

func ExtendServiceLabels(set *LabelSet, opts ServiceLabelExtendedOpts)

func FindNode

func FindNode(address string) (Provisioner, Node, error)

func FindNodeSkipProvisioner

func FindNodeSkipProvisioner(address string, skipProv string) (Provisioner, Node, error)

func InitializeAll

func InitializeAll() error

func IsStartupError

func IsStartupError(err error) bool

func NodeToJSON

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

func Register

func Register(name string, pFunc provisionerFactory)

Register registers a new provisioner in the Provisioner registry.

func SplitServiceLabelsAnnotations

func SplitServiceLabelsAnnotations(ls *LabelSet) (labels *LabelSet, ann *LabelSet)

func Unregister

func Unregister(name string)

Unregister unregisters a provisioner.

func WebProcessDefaultPort

func WebProcessDefaultPort() string

Types

type ActionLimiter

type ActionLimiter interface {
	Initialize(uint)
	Start(action string) func()
	Len(action string) int
}

type AddNodeOptions

type AddNodeOptions struct {
	IaaSID     string
	Address    string
	Pool       string
	Metadata   map[string]string
	Register   bool
	CaCert     []byte
	ClientCert []byte
	ClientKey  []byte
	WaitTO     time.Duration
}

type App

type App interface {
	Named

	BindUnit(*Unit) error
	UnbindUnit(*Unit) error

	// GetPlatform returns the platform (type) of the app. It is equivalent
	// to the Unit `Type` field.
	GetPlatform() string

	// GetDeploy returns the deploys that an app has.
	GetDeploys() uint

	Envs() map[string]bind.EnvVar

	GetMemory() int64
	GetSwap() int64
	GetCpuShare() int

	GetUpdatePlatform() bool

	GetRouters() []appTypes.AppRouter

	GetPool() string

	GetTeamOwner() string

	SetQuotaInUse(int) error
}

App represents a tsuru app.

It contains only relevant information for provisioning.

type AppFilterProvisioner

type AppFilterProvisioner interface {
	FilterAppsByUnitStatus([]App, []string) ([]App, error)
}

AppFilterProvisioner is a provisioner that allows filtering apps by the state of its units.

type AppLock

type AppLock interface {
	json.Marshaler

	GetLocked() bool

	GetReason() string

	GetOwner() string

	GetAcquireDate() time.Time
}

type BuilderDeploy

type BuilderDeploy interface {
	Deploy(App, string, *event.Event) (string, error)
}

BuilderDeploy is a provisioner that allows deploy builded image.

type BuilderDeployDockerClient

type BuilderDeployDockerClient interface {
	BuilderDeploy
	GetClient(App) (BuilderDockerClient, error)
}

type BuilderDeployKubeClient

type BuilderDeployKubeClient interface {
	BuilderDeploy
	GetClient(App) (BuilderKubeClient, error)
}

type BuilderDockerClient

type BuilderDockerClient interface {
	PullAndCreateContainer(opts docker.CreateContainerOptions, w io.Writer) (*docker.Container, string, error)
	RemoveContainer(opts docker.RemoveContainerOptions) error
	StartContainer(id string, hostConfig *docker.HostConfig) error
	StopContainer(id string, timeout uint) error
	InspectContainer(id string) (*docker.Container, error)
	CommitContainer(docker.CommitContainerOptions) (*docker.Image, error)
	DownloadFromContainer(string, docker.DownloadFromContainerOptions) error
	UploadToContainer(string, docker.UploadToContainerOptions) error
	AttachToContainerNonBlocking(opts docker.AttachToContainerOptions) (docker.CloseWaiter, error)
	AttachToContainer(opts docker.AttachToContainerOptions) error
	WaitContainer(id string) (int, error)

	BuildImage(opts docker.BuildImageOptions) error
	PushImage(docker.PushImageOptions, docker.AuthConfiguration) error
	InspectImage(string) (*docker.Image, error)
	TagImage(string, docker.TagImageOptions) error
	RemoveImage(name string) error
	ImageHistory(name string) ([]docker.ImageHistory, error)

	SetTimeout(timeout time.Duration)
}

type BuilderKubeClient

type BuilderKubeClient interface {
	BuildPod(App, *event.Event, io.Reader, string) (string, error)
	ImageTagPushAndInspect(App, string, string) (*docker.Image, string, *TsuruYamlData, error)
}

type CleanImageProvisioner

type CleanImageProvisioner interface {
	CleanImage(appName string, image string) error
}

type ErrUnitStartup

type ErrUnitStartup struct {
	Err error
}

func (ErrUnitStartup) Error

func (e ErrUnitStartup) Error() string

func (ErrUnitStartup) IsStartupError

func (e ErrUnitStartup) IsStartupError() bool

type Error

type Error struct {
	Reason string
	Err    error
}

Error represents a provisioning error. It encapsulates further errors.

func (*Error) Error

func (e *Error) Error() string

Error is the string representation of a provisioning error.

type ExecDockerClient

type ExecDockerClient interface {
	CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error)
	StartExec(execId string, opts docker.StartExecOptions) error
	ResizeExecTTY(execId string, height, width int) error
	InspectExec(execId string) (*docker.ExecInspect, error)
}

type ExecutableProvisioner

type ExecutableProvisioner interface {
	// ExecuteCommand runs a command in all units of the app.
	ExecuteCommand(stdout, stderr io.Writer, app App, cmd string, args ...string) error

	// ExecuteCommandOnce runs a command in one unit of the app.
	ExecuteCommandOnce(stdout, stderr io.Writer, app App, cmd string, args ...string) error

	// ExecuteCommandIsolated runs a command in an new and ephemeral container.
	ExecuteCommandIsolated(stdout, stderr io.Writer, app App, cmd string, args ...string) error
}

ExecutableProvisioner is a provisioner that allows executing commands on units.

type InitializableProvisioner

type InitializableProvisioner interface {
	Initialize() error
}

InitializableProvisioner is a provisioner that provides an initialization method that should be called when the app is started

type InvalidProcessError

type InvalidProcessError struct {
	Msg string
}

func (InvalidProcessError) Error

func (e InvalidProcessError) Error() string

type LabelSet

type LabelSet struct {
	Labels map[string]string
	Prefix string
}

func NodeContainerLabels

func NodeContainerLabels(opts NodeContainerLabelsOpts) *LabelSet

func NodeLabels

func NodeLabels(opts NodeLabelsOpts) *LabelSet

func ProcessLabels

func ProcessLabels(opts ProcessLabelsOpts) (*LabelSet, error)

func ServiceAccountLabels

func ServiceAccountLabels(opts ServiceAccountLabelsOpts) *LabelSet

func ServiceLabels

func ServiceLabels(opts ServiceLabelsOpts) (*LabelSet, error)

func VolumeLabels

func VolumeLabels(opts VolumeLabelsOpts) *LabelSet

func (*LabelSet) AppName

func (s *LabelSet) AppName() string

func (*LabelSet) AppPlatform

func (s *LabelSet) AppPlatform() string

func (*LabelSet) AppProcess

func (s *LabelSet) AppProcess() string

func (*LabelSet) AppReplicas

func (s *LabelSet) AppReplicas() int

func (*LabelSet) BuildImage

func (s *LabelSet) BuildImage() string

func (*LabelSet) IsAsleep

func (s *LabelSet) IsAsleep() bool

func (*LabelSet) IsDeploy

func (s *LabelSet) IsDeploy() bool

func (*LabelSet) IsIsolatedRun

func (s *LabelSet) IsIsolatedRun() bool

func (*LabelSet) IsService

func (s *LabelSet) IsService() bool

func (*LabelSet) IsStopped

func (s *LabelSet) IsStopped() bool

func (*LabelSet) NodeAddr

func (s *LabelSet) NodeAddr() string

func (*LabelSet) NodeExtraData

func (s *LabelSet) NodeExtraData(cluster string) map[string]string

func (*LabelSet) NodeIaaSID

func (s *LabelSet) NodeIaaSID() string

func (*LabelSet) NodeMetadata

func (s *LabelSet) NodeMetadata() map[string]string

func (*LabelSet) NodeMetadataNoPrefix

func (s *LabelSet) NodeMetadataNoPrefix() map[string]string

func (*LabelSet) NodePool

func (s *LabelSet) NodePool() string

func (*LabelSet) Restarts

func (s *LabelSet) Restarts() int

func (*LabelSet) SetAsleep

func (s *LabelSet) SetAsleep()

func (*LabelSet) SetBuildImage

func (s *LabelSet) SetBuildImage(image string)

func (*LabelSet) SetIsHeadlessService

func (s *LabelSet) SetIsHeadlessService()

func (*LabelSet) SetIsService

func (s *LabelSet) SetIsService()

func (*LabelSet) SetRestarts

func (s *LabelSet) SetRestarts(count int)

func (*LabelSet) SetStopped

func (s *LabelSet) SetStopped()

func (*LabelSet) ToAppSelector

func (s *LabelSet) ToAppSelector() map[string]string

func (*LabelSet) ToIsServiceSelector

func (s *LabelSet) ToIsServiceSelector() map[string]string

func (*LabelSet) ToLabels

func (s *LabelSet) ToLabels() map[string]string

func (*LabelSet) ToNodeByPoolSelector

func (s *LabelSet) ToNodeByPoolSelector() map[string]string

func (*LabelSet) ToNodeContainerSelector

func (s *LabelSet) ToNodeContainerSelector() map[string]string

func (*LabelSet) ToNodeSelector

func (s *LabelSet) ToNodeSelector() map[string]string

func (*LabelSet) ToSelector

func (s *LabelSet) ToSelector() map[string]string

func (*LabelSet) ToVolumeSelector

func (s *LabelSet) ToVolumeSelector() map[string]string

type LocalLimiter

type LocalLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*LocalLimiter) Initialize

func (l *LocalLimiter) Initialize(i uint)

func (*LocalLimiter) Len

func (l *LocalLimiter) Len(action string) int

func (*LocalLimiter) Start

func (l *LocalLimiter) Start(action string) func()

type MessageProvisioner

type MessageProvisioner interface {
	StartupMessage() (string, error)
}

MessageProvisioner is a provisioner that provides a welcome message for logging.

type MetaWithFrequency

type MetaWithFrequency struct {
	Metadata map[string]string
	Nodes    []Node
}

type MetaWithFrequencyList

type MetaWithFrequencyList []MetaWithFrequency

func (MetaWithFrequencyList) Len

func (l MetaWithFrequencyList) Len() int

func (MetaWithFrequencyList) Less

func (l MetaWithFrequencyList) Less(i, j int) bool

func (MetaWithFrequencyList) Swap

func (l MetaWithFrequencyList) Swap(i, j int)

type MongodbLimiter

type MongodbLimiter struct {
	// contains filtered or unexported fields
}

func (*MongodbLimiter) Initialize

func (l *MongodbLimiter) Initialize(i uint)

func (*MongodbLimiter) Len

func (l *MongodbLimiter) Len(action string) int

func (*MongodbLimiter) Start

func (l *MongodbLimiter) Start(action string) func()

type Named

type Named interface {
	GetName() string
}

Named is something that has a name, providing the GetName method.

type Node

type Node interface {
	Pool() string
	IaaSID() string
	Address() string
	Status() string

	// Metadata returns node metadata exclusively managed by tsuru
	Metadata() map[string]string
	Units() ([]Unit, error)
	Provisioner() NodeProvisioner

	// MetadataNoPrefix returns node metadata managed by tsuru without any
	// tsuru specific prefix. This can be used with iaas providers.
	MetadataNoPrefix() map[string]string
}

func FindNodeByAddrs

func FindNodeByAddrs(p NodeProvisioner, addrs []string) (Node, error)

type NodeCheckResult

type NodeCheckResult struct {
	Name       string
	Err        string
	Successful bool
}

type NodeContainerLabelsOpts

type NodeContainerLabelsOpts struct {
	Name         string
	CustomLabels map[string]string
	Pool         string
	Provisioner  string
	Prefix       string
}

type NodeContainerProvisioner

type NodeContainerProvisioner interface {
	UpgradeNodeContainer(name string, pool string, writer io.Writer) error
	RemoveNodeContainer(name string, pool string, writer io.Writer) error
}

type NodeExtraData

type NodeExtraData interface {
	// ExtraData returns node metadata not managed by tsuru, like metadata
	// added by external sources.
	ExtraData() map[string]string
}

type NodeHealthChecker

type NodeHealthChecker interface {
	Node
	FailureCount() int
	HasSuccess() bool
	ResetFailures()
}

type NodeLabelsOpts

type NodeLabelsOpts struct {
	IaaSID       string
	Addr         string
	Pool         string
	Prefix       string
	CustomLabels map[string]string
}

type NodeList

type NodeList []Node

func (NodeList) SplitMetadata

func (nodes NodeList) SplitMetadata() (MetaWithFrequencyList, map[string]string, error)

type NodeProvisioner

type NodeProvisioner interface {
	Named

	// ListNodes returns a list of all nodes registered in the provisioner.
	ListNodes(addressFilter []string) ([]Node, error)

	// GetNode retrieves an existing node by its address.
	GetNode(address string) (Node, error)

	// AddNode adds a new node in the provisioner.
	AddNode(AddNodeOptions) error

	// RemoveNode removes an existing node.
	RemoveNode(RemoveNodeOptions) error

	// UpdateNode can be used to enable/disable a node and update its metadata.
	UpdateNode(UpdateNodeOptions) error

	// NodeForNodeData finds a node matching the received NodeStatusData.
	NodeForNodeData(NodeStatusData) (Node, error)
}

type NodeRebalanceProvisioner

type NodeRebalanceProvisioner interface {
	RebalanceNodes(RebalanceNodesOptions) (bool, error)
}

type NodeSpec

type NodeSpec struct {
	// BSON tag for bson serialized compatibility with cluster.Node
	Address     string `bson:"_id"`
	IaaSID      string
	Metadata    map[string]string
	Status      string
	Pool        string
	Provisioner string
}

func NodeToSpec

func NodeToSpec(n Node) NodeSpec

type NodeStatusData

type NodeStatusData struct {
	Addrs  []string
	Units  []UnitStatusData
	Checks []NodeCheckResult
}

type OptionalLogsProvisioner

type OptionalLogsProvisioner interface {
	// Checks if logs are enabled for given app.
	LogsEnabled(App) (bool, string, error)
}

OptionalLogsProvisioner is a provisioner that allows optionally disabling logs for a given app.

type ProcessLabelsOpts

type ProcessLabelsOpts struct {
	App         App
	Process     string
	Provisioner string
	Builder     string
	Prefix      string
	IsDeploy    bool
}

type Provisioner

type Provisioner interface {
	Named

	// Provision is called when tsuru is creating the app.
	Provision(App) error

	// Destroy is called when tsuru is destroying the app.
	Destroy(App) error

	// AddUnits adds units to an app. The first parameter is the app, the
	// second is the number of units to be added.
	//
	// It returns a slice containing all added units
	AddUnits(App, uint, string, io.Writer) error

	// RemoveUnits "undoes" AddUnits, removing the given number of units
	// from the app.
	RemoveUnits(App, uint, string, io.Writer) error

	// Restart restarts the units of the application, with an optional
	// string parameter represeting the name of the process to start. When
	// the process is empty, Restart will restart all units of the
	// application.
	Restart(App, string, io.Writer) error

	// Start starts the units of the application, with an optional string
	// parameter representing the name of the process to start. When the
	// process is empty, Start will start all units of the application.
	Start(App, string) error

	// Stop stops the units of the application, with an optional string
	// parameter representing the name of the process to start. When the
	// process is empty, Stop will stop all units of the application.
	Stop(App, string) error

	// Units returns information about units by App.
	Units(...App) ([]Unit, error)

	// RoutableAddresses returns the addresses used to access an application.
	RoutableAddresses(App) ([]url.URL, error)

	// Register a unit after the container has been created or restarted.
	RegisterUnit(App, string, map[string]interface{}) error
}

Provisioner is the basic interface of this package.

Any tsuru provisioner must implement this interface in order to provision tsuru apps.

func Get

func Get(name string) (Provisioner, error)

Get gets the named provisioner from the registry.

func GetDefault

func GetDefault() (Provisioner, error)

func Registry

func Registry() ([]Provisioner, error)

Registry returns the list of registered provisioners.

type ProvisionerNotSupported

type ProvisionerNotSupported struct {
	Prov   Provisioner
	Action string
}

func (ProvisionerNotSupported) Error

func (e ProvisionerNotSupported) Error() string

type RebalanceNodesOptions

type RebalanceNodesOptions struct {
	Event          *event.Event
	Pool           string
	MetadataFilter map[string]string
	AppFilter      []string
	Dry            bool
	Force          bool
}

type RemoveNodeOptions

type RemoveNodeOptions struct {
	Address   string
	Rebalance bool
	Writer    io.Writer
}

type RollbackableDeployer

type RollbackableDeployer interface {
	Rollback(App, string, *event.Event) (string, error)
}

RollbackableDeployer is a provisioner that allows rolling back to a previously deployed version.

type RunArgs

type RunArgs struct {
	Once     bool
	Isolated bool
}

RunArgs groups together the arguments to run an App.

type ServiceAccountLabelsOpts

type ServiceAccountLabelsOpts struct {
	App               App
	NodeContainerName string
	Provisioner       string
	Prefix            string
}

type ServiceLabelExtendedOpts

type ServiceLabelExtendedOpts struct {
	Provisioner   string
	Prefix        string
	BuildImage    string
	IsDeploy      bool
	IsIsolatedRun bool
	IsBuild       bool
	Builder       string
}

type ServiceLabelsOpts

type ServiceLabelsOpts struct {
	App      App
	Process  string
	Replicas int
	ServiceLabelExtendedOpts
}

type ShellOptions

type ShellOptions struct {
	App    App
	Conn   io.ReadWriteCloser
	Width  int
	Height int
	Unit   string
	Term   string
}

ShellOptions is the set of options that can be used when calling the method Shell in the provisioner.

type ShellProvisioner

type ShellProvisioner interface {
	// Open a remote shel in one of the units in the application.
	Shell(ShellOptions) error
}

ShellProvisioner is a provisioner that allows opening a shell to existing units.

type SleepableProvisioner

type SleepableProvisioner interface {
	// Sleep puts the units of the application to sleep, with an optional string
	// parameter representing the name of the process to sleep. When the
	// process is empty, Sleep will put all units of the application to sleep.
	Sleep(App, string) error
}

SleepableProvisioner is a provisioner that allows putting applications to sleep.

type Status

type Status string

Status represents the status of a unit in tsuru.

func ParseStatus

func ParseStatus(status string) (Status, error)

func (Status) String

func (s Status) String() string

type TsuruYamlData

type TsuruYamlData struct {
	Hooks       TsuruYamlHooks       `bson:",omitempty"`
	Healthcheck TsuruYamlHealthcheck `bson:",omitempty"`
}

type TsuruYamlHealthcheck

type TsuruYamlHealthcheck struct {
	Path            string
	Method          string
	Status          int
	Scheme          string
	Match           string `bson:",omitempty"`
	RouterBody      string `json:"router_body" yaml:"router_body" bson:"router_body,omitempty"`
	UseInRouter     bool   `json:"use_in_router" yaml:"use_in_router" bson:"use_in_router,omitempty"`
	AllowedFailures int    `json:"allowed_failures" yaml:"allowed_failures" bson:"allowed_failures,omitempty"`
}

func (TsuruYamlHealthcheck) ToRouterHC

type TsuruYamlHooks

type TsuruYamlHooks struct {
	Restart TsuruYamlRestartHooks `bson:",omitempty"`
	Build   []string              `bson:",omitempty"`
}

type TsuruYamlRestartHooks

type TsuruYamlRestartHooks struct {
	Before []string `bson:",omitempty"`
	After  []string `bson:",omitempty"`
}

type Unit

type Unit struct {
	ID          string
	Name        string
	AppName     string
	ProcessName string
	Type        string
	IP          string
	Status      Status
	Address     *url.URL
}

Unit represents a provision unit. Can be a machine, container or anything IP-addressable.

func (*Unit) Available

func (u *Unit) Available() bool

Available returns true if the unit is available. It will return true whenever the unit itself is available, even when the application process is not.

func (*Unit) GetID

func (u *Unit) GetID() string

GetName returns the name of the unit.

func (*Unit) GetIp

func (u *Unit) GetIp() string

GetIp returns the Unit.IP.

func (*Unit) MarshalJSON

func (u *Unit) MarshalJSON() ([]byte, error)

type UnitFinderProvisioner

type UnitFinderProvisioner interface {
	// GetAppFromUnitID returns an app from unit id
	GetAppFromUnitID(string) (App, error)
}

UnitFinderProvisioner is a provisioner that allows finding a specific unit by its id. New provisioners should not implement this interface, this was only used during events format migration and is exclusive to docker provisioner.

type UnitNotFoundError

type UnitNotFoundError struct {
	ID string
}

func (*UnitNotFoundError) Error

func (e *UnitNotFoundError) Error() string

type UnitStatusData

type UnitStatusData struct {
	ID     string
	Name   string
	Status Status
}

type UnitStatusProvisioner

type UnitStatusProvisioner interface {
	// SetUnitStatus changes the status of a unit.
	SetUnitStatus(Unit, Status) error
}

UnitStatusProvisioner is a provisioner that receive notifications about unit status changes.

type UpdateNodeOptions

type UpdateNodeOptions struct {
	Address  string
	Pool     string
	Metadata map[string]string
	Enable   bool
	Disable  bool
}

type VolumeLabelsOpts

type VolumeLabelsOpts struct {
	Name        string
	Provisioner string
	Pool        string
	Plan        string
	Prefix      string
}

type VolumeProvisioner

type VolumeProvisioner interface {
	DeleteVolume(volumeName, pool string) error
}

Directories

Path Synopsis
Package docker provides a provisioner implementation that use Docker containers.
Package docker provides a provisioner implementation that use Docker containers.
fix

Jump to

Keyboard shortcuts

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