provision

package
v0.0.0-...-47649f3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 27 Imported by: 33

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 (
	LabelIsBuild = "is-build"

	LabelAppName      = "app-name"
	LabelAppProcess   = "app-process"
	LabelAppPool      = "app-pool"
	LabelAppPlatform  = "app-platform"
	LabelAppVersion   = "app-version"
	LabelAppTeamOwner = "app-team"

	LabelIsJob        = "is-job"
	LabelJobName      = "job-name"
	LabelJobPool      = "job-pool"
	LabelJobTeamOwner = "job-team"
	LabelJobIsManual  = "job-manual"

	LabelNodePool = PoolMetadataName
)
View Source
const (
	DefaultHealthcheckScheme = "http"

	PoolMetadataName = "pool"
	WebProcessName   = "web"
)
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.
	StatusStarted = Status("started")

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

	// StatusSucceeded is for alternete cases where the unit has been
	// stopped with succeeded end.
	StatusSucceeded = Status("succeeded")
)

+---------+ +----------+ +---------+ | Created | +---------> | Starting | +-------------> | Started | +---------+ +----------+ +---------+

^                         + +
|                         | |
|                         | |
|                         | |
v                         | |
+-------+                 | |
| Error | +---------------+ |
+-------+ ------------------+

Variables

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

	ErrLogsUnavailable = errors.New("logs from provisioner are unavailable")
	DefaultProvisioner = defaultKubernetesProvisioner
)

Functions

func AppProcessName

func AppProcessName(a App, process string, version int, suffix string) string

func DefaultWebPortEnvs

func DefaultWebPortEnvs() []bindTypes.EnvVar

func EnvsForApp

func EnvsForApp(a App, process string, version appTypes.AppVersion) []bindTypes.EnvVar

func ExtendServiceLabels

func ExtendServiceLabels(set *LabelSet, opts ServiceLabelExtendedOpts)

func InitializeAll

func InitializeAll() error

func MainAppProcess

func MainAppProcess(processes []string) string

func Register

func Register(name string, pFunc provisionerFactory)

Register registers a new provisioner in the Provisioner registry.

func Unregister

func Unregister(name string)

Unregister unregisters a provisioner.

func ValidKubeName

func ValidKubeName(name string) string

func WebProcessDefaultPort

func WebProcessDefaultPort() string

Types

type App

type App interface {
	Named

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

	// GetPlatformVersion returns the locked platform version of the app.
	GetPlatformVersion() string

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

	Envs() map[string]bindTypes.EnvVar

	GetUpdatePlatform() bool

	GetRouters() []appTypes.AppRouter

	GetTeamOwner() string
	GetTeamsName() []string

	GetPlan() appTypes.Plan
	GetPool() string
	GetProcess(process string) *appTypes.Process

	ListTags() []string

	GetMetadata(process string) appTypes.Metadata

	GetRegistry() (imgTypes.ImageRegistry, error)
}

App represents a tsuru app.

It contains only relevant information for provisioning.

type AppFilterProvisioner

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

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

type AppInternalAddress

type AppInternalAddress struct {
	Domain   string
	Protocol string
	Port     int32
	Version  string
	Process  string
}

type AutoScalePrometheus

type AutoScalePrometheus struct {
	Name                string  `json:"name"`
	Query               string  `json:"query"`
	Threshold           float64 `json:"threshold"`
	ActivationThreshold float64 `json:"activationThreshold,omitempty"`
	PrometheusAddress   string  `json:"prometheusAddress,omitempty"`
}

type AutoScaleProvisioner

type AutoScaleProvisioner interface {
	GetAutoScale(ctx context.Context, a App) ([]AutoScaleSpec, error)
	GetVerticalAutoScaleRecommendations(ctx context.Context, a App) ([]RecommendedResources, error)
	SetAutoScale(ctx context.Context, a App, spec AutoScaleSpec) error
	RemoveAutoScale(ctx context.Context, a App, process string) error
}

type AutoScaleSchedule

type AutoScaleSchedule struct {
	Name        string `json:"name,omitempty"`
	MinReplicas int    `json:"minReplicas"`
	Start       string `json:"start"`
	End         string `json:"end"`
	Timezone    string `json:"timezone,omitempty"`
}

type AutoScaleSpec

type AutoScaleSpec struct {
	Process    string                `json:"process"`
	MinUnits   uint                  `json:"minUnits"`
	MaxUnits   uint                  `json:"maxUnits"`
	AverageCPU string                `json:"averageCPU,omitempty"`
	Schedules  []AutoScaleSchedule   `json:"schedules,omitempty"`
	Prometheus []AutoScalePrometheus `json:"prometheus,omitempty"`
	Version    int                   `json:"version"`
}

func (AutoScaleSpec) ToCPUValue

func (s AutoScaleSpec) ToCPUValue(a App) (int, error)

func (AutoScaleSpec) Validate

func (s AutoScaleSpec) Validate(quotaLimit int, a App) error

type BuilderDeploy

type BuilderDeploy interface {
	Deploy(context.Context, DeployArgs) (string, error)
}

BuilderDeploy is a provisioner that allows deploy builded image.

type DeployArgs

type DeployArgs struct {
	App              App
	Version          appTypes.AppVersion
	Event            *event.Event
	PreserveVersions bool
	OverrideVersions bool
}

type ErrUnitStartup

type ErrUnitStartup struct {
	CrashedUnits     []string
	CrashedUnitsLogs []appTypes.Applog
	Err              error
}

func IsStartupError

func IsStartupError(err error) (*ErrUnitStartup, bool)

func (ErrUnitStartup) Cause

func (e ErrUnitStartup) Cause() error

func (ErrUnitStartup) Error

func (e ErrUnitStartup) Error() string

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 ExecOptions

type ExecOptions struct {
	App    App
	Stdout io.Writer
	Stderr io.Writer
	Stdin  io.Reader
	Width  int
	Height int
	Term   string
	Cmds   []string
	Units  []string
}

type ExecutableProvisioner

type ExecutableProvisioner interface {
	ExecuteCommand(ctx context.Context, opts ExecOptions) error
}

type HCProvisioner

type HCProvisioner interface {
	// HandlesHC returns true if the provisioner will handle healthchecking
	// instead of the router.
	HandlesHC() bool
}

HCProvisioner is a provisioner that may handle loadbalancing healthchecks.

type ImageBuildLabelsOpts

type ImageBuildLabelsOpts struct {
	Name         string
	CustomLabels map[string]string
	Prefix       string
	IsBuild      bool
}

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 InspectData

type InspectData struct {
	Image     docker.Image
	TsuruYaml provTypes.TsuruYamlData
	Procfile  string
}

type InterAppProvisioner

type InterAppProvisioner interface {
	InternalAddresses(ctx context.Context, a App) ([]AppInternalAddress, error)
}

InterAppProvisioner is a provisioner that allows an app to comunicate with each other using internal dns and own load balancers provided by provisioner.

type InvalidProcessError

type InvalidProcessError struct {
	Msg string
}

func (InvalidProcessError) Error

func (e InvalidProcessError) Error() string

type JobProvisioner

type JobProvisioner interface {
	// JobUnits returns information about units related to a specific Job or CronJob
	JobUnits(context.Context, *jobTypes.Job) ([]Unit, error)

	// EnsureJob creates/update a cronjob object in the cluster
	EnsureJob(context.Context, *jobTypes.Job) error

	DestroyJob(context.Context, *jobTypes.Job) error
	TriggerCron(ctx context.Context, name, pool string) error
	KillJobUnit(ctx context.Context, job *jobTypes.Job, unitName string, force bool) error
}

type KillUnitProvisioner

type KillUnitProvisioner interface {
	KillUnit(ctx context.Context, app App, unit string, force bool) error
}

type LabelSet

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

func ImageBuildLabels

func ImageBuildLabels(opts ImageBuildLabelsOpts) *LabelSet

func JobLabels

func JobLabels(ctx context.Context, job *jobTypes.Job) *LabelSet

func NodeLabels

func NodeLabels(opts NodeLabelsOpts) *LabelSet

func PDBLabels

func PDBLabels(opts PDBLabelsOpts) *LabelSet

func ProcessLabels

func ProcessLabels(ctx context.Context, opts ProcessLabelsOpts) (*LabelSet, error)

func ServiceAccountLabels

func ServiceAccountLabels(opts ServiceAccountLabelsOpts) *LabelSet

func ServiceLabelSet

func ServiceLabelSet(prefix string) *LabelSet

func ServiceLabels

func ServiceLabels(ctx context.Context, opts ServiceLabelsOpts) (*LabelSet, error)

func TsuruJobLabelSet

func TsuruJobLabelSet(prefix string) *LabelSet

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

func (s *LabelSet) AppPool() string

func (*LabelSet) AppProcess

func (s *LabelSet) AppProcess() string

func (*LabelSet) AppVersion

func (s *LabelSet) AppVersion() int

func (*LabelSet) DeepCopy

func (s *LabelSet) DeepCopy() *LabelSet

func (*LabelSet) IsBase

func (s *LabelSet) IsBase() bool

func (*LabelSet) IsHeadlessService

func (s *LabelSet) IsHeadlessService() bool

func (*LabelSet) IsIsolatedRun

func (s *LabelSet) IsIsolatedRun() bool

func (*LabelSet) IsRoutable

func (s *LabelSet) IsRoutable() bool

func (*LabelSet) IsService

func (s *LabelSet) IsService() bool

func (*LabelSet) IsStopped

func (s *LabelSet) IsStopped() bool

func (*LabelSet) JobName

func (s *LabelSet) JobName() string

func (*LabelSet) Merge

func (s *LabelSet) Merge(override *LabelSet) *LabelSet

func (*LabelSet) NodeAddr

func (s *LabelSet) NodeAddr() string

func (*LabelSet) NodeExtraData

func (s *LabelSet) NodeExtraData(cluster string) map[string]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) PodLabels

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

func (*LabelSet) ReplaceIsIsolatedNewRunWithBase

func (s *LabelSet) ReplaceIsIsolatedNewRunWithBase()

func (*LabelSet) ReplaceIsIsolatedRunWithNew

func (s *LabelSet) ReplaceIsIsolatedRunWithNew()

func (*LabelSet) Restarts

func (s *LabelSet) Restarts() int

func (*LabelSet) SetIsHeadlessService

func (s *LabelSet) SetIsHeadlessService()

func (*LabelSet) SetIsRoutable

func (s *LabelSet) SetIsRoutable()

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

func (s *LabelSet) SetVersion(version int)

func (*LabelSet) ToAllVersionsSelector

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

func (*LabelSet) ToAppSelector

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

func (*LabelSet) ToBaseSelector

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

func (*LabelSet) ToHPASelector

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

func (*LabelSet) ToIsServiceSelector

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

func (*LabelSet) ToIsTsuruSelector

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

func (*LabelSet) ToJobSelector

func (s *LabelSet) ToJobSelector() 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) ToPDBSelector

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

func (*LabelSet) ToRoutableSelector

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

func (*LabelSet) ToVersionSelector

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

func (*LabelSet) ToVolumeSelector

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

func (*LabelSet) ToggleIsRoutable

func (s *LabelSet) ToggleIsRoutable(isRoutable bool)

func (*LabelSet) WithoutIsolated

func (s *LabelSet) WithoutIsolated() *LabelSet

func (*LabelSet) WithoutRoutable

func (s *LabelSet) WithoutRoutable() *LabelSet

func (*LabelSet) WithoutVersion

func (s *LabelSet) WithoutVersion() *LabelSet

type LogsProvisioner

type LogsProvisioner interface {
	ListLogs(ctx context.Context, obj logTypes.LogabbleObject, args appTypes.ListLogArgs) ([]appTypes.Applog, error)
	WatchLogs(ctx context.Context, obj logTypes.LogabbleObject, args appTypes.ListLogArgs) (appTypes.LogWatcher, error)
}

LogsProvisioner is a provisioner that is self responsible for storage logs.

type MessageProvisioner

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

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

type MetricsProvisioner

type MetricsProvisioner interface {
	// Units returns information about cpu and memory usage by App.
	UnitsMetrics(ctx context.Context, a App) ([]UnitMetric, error)
}

MetricsProvisioner is a provisioner that have capability to view metrics of workloads

type MultiRegistryProvisioner

type MultiRegistryProvisioner interface {
	RegistryForPool(ctx context.Context, pool string) (imgTypes.ImageRegistry, error)
}

type Named

type Named interface {
	GetName() string
}

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

type NodeCheckResult

type NodeCheckResult struct {
	Name       string
	Err        string
	Successful bool
}

type NodeLabelsOpts

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

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 PDBLabelsOpts

type PDBLabelsOpts struct {
	App     App
	Prefix  string
	Process string
}

type ProcessLabelsOpts

type ProcessLabelsOpts struct {
	App     App
	Process string
	Prefix  string
}

type Provisioner

type Provisioner interface {
	Named

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

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

	// DestroyVersion is called when tsuru is destroying an app version.
	DestroyVersion(context.Context, App, appTypes.AppVersion) 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(context.Context, App, uint, string, appTypes.AppVersion, io.Writer) error

	// RemoveUnits "undoes" AddUnits, removing the given number of units
	// from the app.
	RemoveUnits(context.Context, App, uint, string, appTypes.AppVersion, 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(context.Context, App, string, appTypes.AppVersion, 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(context.Context, App, string, appTypes.AppVersion, io.Writer) 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(context.Context, App, string, appTypes.AppVersion, io.Writer) error

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

	// RoutableAddresses returns the addresses used to access an application.
	RoutableAddresses(context.Context, App) ([]appTypes.RoutableAddresses, 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 RecommendedProcessResources

type RecommendedProcessResources struct {
	Type   string `json:"type"`
	CPU    string `json:"cpu"`
	Memory string `json:"memory"`
}

type RecommendedResources

type RecommendedResources struct {
	Process         string                        `json:"process"`
	Recommendations []RecommendedProcessResources `json:"recommendations"`
}

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
	Job               *jobTypes.Job
	NodeContainerName string
	Prefix            string
}

type ServiceLabelExtendedOpts

type ServiceLabelExtendedOpts struct {
	Prefix        string
	IsIsolatedRun bool
	IsBuild       bool
}

type ServiceLabelsOpts

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

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 Unit

type Unit struct {
	ID           string
	Name         string
	AppName      string
	ProcessName  string
	Type         string
	IP           string
	InternalIP   string
	Status       Status
	StatusReason string
	Address      *url.URL  // TODO: deprecate after drop docker provisioner
	Addresses    []url.URL // TODO: deprecate after drop docker provisioner
	Version      int
	Routable     bool
	Restarts     *int32
	CreatedAt    *time.Time
	Ready        *bool
}

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(context.Context, 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 UnitMetric

type UnitMetric struct {
	ID     string
	CPU    string
	Memory string
}

UnitMetric represents a a related metrics for an unit.

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 UpdatableProvisioner

type UpdatableProvisioner interface {
	UpdateApp(ctx context.Context, old, new App, w io.Writer) error
}

UpdatableProvisioner is a provisioner that stores data about applications and must be notified when they are updated

type VersionsProvisioner

type VersionsProvisioner interface {
	ToggleRoutable(context.Context, App, appTypes.AppVersion, bool) error
	DeployedVersions(context.Context, App) ([]int, error)
}

type VolumeLabelsOpts

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

type VolumeProvisioner

type VolumeProvisioner interface {
	ValidateVolume(context.Context, *volumeTypes.Volume) error
	IsVolumeProvisioned(ctx context.Context, volumeName, pool string) (bool, error)
	DeleteVolume(ctx context.Context, volumeName, pool string) error
}

Directories

Path Synopsis
pkg/apis/tsuru/v1
Package v1 is the v1 version of the API.
Package v1 is the v1 version of the API.
pkg/client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
pkg/client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
pkg/client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
pkg/client/clientset/versioned/typed/tsuru/v1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
pkg/client/clientset/versioned/typed/tsuru/v1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

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