app

package
v0.0.0-...-32701d2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: BSD-3-Clause Imports: 20 Imported by: 56

Documentation

Index

Constants

View Source
const (
	DefaultAppDir = "/home/application/current"
)

Variables

View Source
var (
	ErrAppNotFound            = errors.New("App not found")
	ErrPlanNotFound           = errors.New("plan not found")
	ErrPlanAlreadyExists      = errors.New("plan already exists")
	ErrPlanDefaultAmbiguous   = errors.New("more than one default plan found")
	ErrPlanDefaultNotFound    = errors.New("default plan not found")
	ErrLimitOfMemory          = errors.New("The minimum allowed memory is 4MB")
	ErrPlatformNameMissing    = errors.New("Platform name is required.")
	ErrPlatformImageMissing   = errors.New("Platform image is required.")
	ErrPlatformNotFound       = errors.New("Platform doesn't exist.")
	ErrDuplicatePlatform      = errors.New("Duplicate platform")
	ErrInvalidPlatform        = errors.New("Invalid platform")
	ErrMissingFileContent     = errors.New("Missing file content.")
	ErrDeletePlatformWithApps = errors.New("Platform has apps. You must remove them before remove the platform.")
	ErrInvalidPlatformName    = &tsuruErrors.ValidationError{
		Message: "Invalid platform name, should have at most 40 " +
			"characters, containing only lower case letters, numbers or dashes, " +
			"starting with a letter.",
	}
)
View Source
var (
	ErrNoVersionsAvailable          = errors.New("no versions available for app")
	ErrTransactionCancelledByChange = errors.New("The update has been cancelled by a previous change")
	ErrVersionMarkedToRemoval       = errors.New("the selected version is marked to removal")
)
View Source
var CertIssuerDotReplacement = "_dot_"

Functions

func IsInvalidVersionError

func IsInvalidVersionError(err error) bool

Types

type AddVersionDataArgs

type AddVersionDataArgs struct {
	Processes    map[string][]string
	CustomData   map[string]interface{}
	ExposedPorts []string
}

type App

type App struct {
	Env             map[string]bind.EnvVar
	ServiceEnvs     []bind.ServiceEnvVar
	Platform        string `bson:"framework"`
	PlatformVersion string
	Name            string
	CName           []string
	CertIssuers     CertIssuers
	Teams           []string
	TeamOwner       string
	Owner           string
	Plan            Plan
	UpdatePlatform  bool
	Lock            AppLock
	Pool            string
	Description     string
	Router          string // TODO: drop Router field and use just on inputApp
	RouterOpts      map[string]string
	Deploys         uint
	Tags            []string
	Error           string
	Routers         []AppRouter
	Metadata        Metadata
	Processes       []Process

	// UUID is a v4 UUID lazily generated on the first call to GetUUID()
	UUID string

	Quota quota.Quota
}

App is the main type in tsuru. An app represents a real world application. This struct holds information about the app: its name, address, list of teams that have access to it, used platform, etc.

type AppCreationError

type AppCreationError struct {
	App string
	Err error
}

func (*AppCreationError) Error

func (e *AppCreationError) Error() string

type AppInfo

type AppInfo struct {
	Name        string   `json:"name"`
	Platform    string   `json:"platform"`
	Teams       []string `json:"teams"`
	Plan        *Plan    `json:"plan"`
	CName       []string `json:"cname"`
	Owner       string   `json:"owner"` // we may move this to createdBy
	Pool        string   `json:"pool"`
	Description string   `json:"description"`
	Deploys     uint     `json:"deploys"`
	TeamOwner   string   `json:"teamowner"`
	Lock        AppLock  `json:"lock"`
	Tags        []string `json:"tags"`
	Metadata    Metadata `json:"metadata"`

	Units                   []provision.Unit                 `json:"units"`
	InternalAddresses       []AppInternalAddress             `json:"internalAddresses,omitempty"`
	Autoscale               []provision.AutoScaleSpec        `json:"autoscale,omitempty"`
	UnitsMetrics            []provision.UnitMetric           `json:"unitsMetrics,omitempty"`
	AutoscaleRecommendation []provision.RecommendedResources `json:"autoscaleRecommendation,omitempty"`

	Provisioner          string                     `json:"provisioner,omitempty"`
	Cluster              string                     `json:"cluster,omitempty"`
	Processes            []Process                  `json:"processes,omitempty"`
	Routers              []AppRouter                `json:"routers"`
	VolumeBinds          []volume.VolumeBind        `json:"volumeBinds,omitempty"`
	ServiceInstanceBinds []bind.ServiceInstanceBind `json:"serviceInstanceBinds"`

	IP         string            `json:"ip,omitempty"`
	Router     string            `json:"router,omitempty"`
	RouterOpts map[string]string `json:"routeropts"`
	Quota      *quota.Quota      `json:"quota,omitempty"`
	Error      string            `json:"error,omitempty"`

	DashboardURL string `json:"dashboardURL,omitempty"`
}

type AppInternalAddress

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

type AppLock

type AppLock struct {
	Locked      bool
	Reason      string
	Owner       string
	AcquireDate time.Time
}

AppLock stores information about a lock hold on the app

type AppLogService

type AppLogService interface {
	Enqueue(entry *Applog) error
	Add(appName, message, source, unit string) error
	List(ctx context.Context, args ListLogArgs) ([]Applog, error)
	Watch(ctx context.Context, args ListLogArgs) (LogWatcher, error)
}

type AppLogServiceInstance

type AppLogServiceInstance interface {
	Instance() AppLogService
}

type AppResume

type AppResume struct {
	Name        string           `json:"name"`
	Pool        string           `json:"pool"`
	TeamOwner   string           `json:"teamowner"`
	Plan        Plan             `json:"plan"`
	Units       []provision.Unit `json:"units"`
	CName       []string         `json:"cname"`
	IP          string           `json:"ip"`
	Routers     []AppRouter      `json:"routers"`
	Lock        AppLock          `json:"lock"`
	Tags        []string         `json:"tags"`
	Error       string           `json:"error,omitempty"`
	Platform    string           `json:"platform,omitempty"`
	Description string           `json:"description,omitempty"`
	Metadata    Metadata         `json:"metadata,omitempty"`
}

AppResume is a minimal representation of the app, created to make appList faster and transmit less data.

type AppRouter

type AppRouter struct {
	Name         string            `json:"name"`
	Opts         map[string]string `json:"opts"`
	Address      string            `json:"address" bson:"-"`
	Addresses    []string          `json:"addresses" bson:"-"`
	Type         string            `json:"type" bson:"-"`
	Status       string            `json:"status,omitempty" bson:"-"`
	StatusDetail string            `json:"status-detail,omitempty" bson:"-"`
}

type AppService

type AppService interface {
	GetByName(ctx context.Context, name string) (*App, error)
	List(ctx context.Context, filter *Filter) ([]*App, error)
	GetHealthcheckData(ctx context.Context, app *App) (router.HealthcheckData, error)
	GetAddresses(ctx context.Context, app *App) ([]string, error)
	GetInternalBindableAddresses(ctx context.Context, app *App) ([]string, error)
	EnsureUUID(ctx context.Context, app *App) (string, error)
	GetRegistry(ctx context.Context, app *App) (image.ImageRegistry, error)

	AddInstance(ctx context.Context, app *App, addArgs bind.AddInstanceArgs) error
	RemoveInstance(ctx context.Context, app *App, removeArgs bind.RemoveInstanceArgs) error
}

type AppVersion

type AppVersion interface {
	Version() int
	BuildImageName() (string, error)
	CommitBuildImage() error
	BaseImageName() (string, error)
	CommitBaseImage() error
	CommitSuccessful() error
	MarkToRemoval() error
	VersionInfo() AppVersionInfo
	Processes() (map[string][]string, error)
	TsuruYamlData() (provTypes.TsuruYamlData, error)
	WebProcess() (string, error)
	AddData(AddVersionDataArgs) error
	String() string
	ToggleEnabled(enabled bool, reason string) error
	UpdatePastUnits(process string, replicas int) error
}

type AppVersionInfo

type AppVersionInfo struct {
	Version          int                    `json:"version"`
	Description      string                 `json:"description"`
	BuildImage       string                 `json:"buildImage"`
	DeployImage      string                 `json:"deployImage"`
	CustomBuildTag   string                 `json:"customBuildTag"`
	CustomData       map[string]interface{} `json:"customData"`
	Processes        map[string][]string    `json:"processes"`
	ExposedPorts     []string               `json:"exposedPorts"`
	EventID          string                 `json:"eventID"`
	CreatedAt        time.Time              `json:"createdAt"`
	UpdatedAt        time.Time              `json:"updatedAt"`
	DisabledReason   string                 `json:"disabledReason"`
	Disabled         bool                   `json:"disabled"`
	DeploySuccessful bool                   `json:"deploySuccessful"`
	MarkedToRemoval  bool                   `json:"markedToRemoval"`
	PastUnits        map[string]int         `json:"pastUnits"`
}

type AppVersionService

type AppVersionService interface {
	VersionByPendingImage(ctx context.Context, app *App, imageID string) (AppVersion, error)
	VersionByImageOrVersion(ctx context.Context, app *App, image string) (AppVersion, error)
	LatestSuccessfulVersion(ctx context.Context, app *App) (AppVersion, error)
	NewAppVersion(ctx context.Context, args NewVersionArgs) (AppVersion, error)
	AppVersionFromInfo(context.Context, *App, AppVersionInfo) (AppVersion, error)
	// contains filtered or unexported methods
}

type AppVersionStorage

type AppVersionStorage interface {
	UpdateVersion(ctx context.Context, appName string, vi *AppVersionInfo, opts ...*AppVersionWriteOptions) error
	UpdateVersionSuccess(ctx context.Context, appName string, vi *AppVersionInfo, opts ...*AppVersionWriteOptions) error
	NewAppVersion(ctx context.Context, args NewVersionArgs) (*AppVersionInfo, error)
	// contains filtered or unexported methods
}

type AppVersionWriteOptions

type AppVersionWriteOptions struct {
	// PreviousUpdatedHash is used to avoid a race of updates and loss data by concurrent updates.
	PreviousUpdatedHash string
}

type AppVersions

type AppVersions struct {
	AppName               string                 `json:"appName"`
	Count                 int                    `json:"count"`
	LastSuccessfulVersion int                    `json:"lastSuccessfulVersion"`
	Versions              map[int]AppVersionInfo `json:"versions"`
	UpdatedAt             time.Time              `json:"updatedAt"`
	UpdatedHash           string                 `json:"updatedHash"`
	MarkedToRemoval       bool                   `json:"markedToRemoval"`
}

type Applog

type Applog struct {
	MongoID primitive.ObjectID `bson:"_id,omitempty" json:"-"`
	Date    time.Time
	Message string
	Source  string
	Name    string
	Type    logTypes.LogType
	Unit    string
}

Applog represents a log entry.

type CPUBurst

type CPUBurst struct {
	Default    float64 `json:"default"`
	MaxAllowed float64 `json:"maxAllowed"`
}

type CertIssuers

type CertIssuers map[string]string

type CertificateInfo

type CertificateInfo struct {
	Certificate string `json:"certificate"`
	Issuer      string `json:"issuer,omitempty"`
}

type CertificateSetInfo

type CertificateSetInfo struct {
	Routers map[string]RouterCertificateInfo `json:"routers"`
}

func (*CertificateSetInfo) IsEmpty

func (csi *CertificateSetInfo) IsEmpty() bool

type ErrInvalidVersion

type ErrInvalidVersion struct {
	Version string
}

func (ErrInvalidVersion) Error

func (i ErrInvalidVersion) Error() string

type Filter

type Filter struct {
	Name        string
	NameMatches string
	Platform    string
	TeamOwner   string
	UserOwner   string
	Pool        string
	Pools       []string
	Statuses    []string
	Locked      bool
	Tags        []string
	Extra       map[string][]string
}

type ListLogArgs

type ListLogArgs struct {
	Name         string
	Type         logTypes.LogType
	Source       string
	Units        []string
	Limit        int
	InvertSource bool
}

type LogWatcher

type LogWatcher interface {
	Chan() <-chan Applog
	Close()
}

type ManyTeamsError

type ManyTeamsError struct{}

ManyTeamsError is the error returned when the user has more than one team and tries to create an app without specify a app team owner.

func (ManyTeamsError) Error

func (err ManyTeamsError) Error() string

type Metadata

type Metadata struct {
	Labels      []MetadataItem `json:"labels"`
	Annotations []MetadataItem `json:"annotations"`
}

Metadata represents the user defined labels and annotations

func (Metadata) Annotation

func (m Metadata) Annotation(v string) (string, bool)

func (*Metadata) Empty

func (m *Metadata) Empty() bool

func (Metadata) Label

func (m Metadata) Label(v string) (string, bool)

func (*Metadata) Update

func (m *Metadata) Update(new Metadata)

func (*Metadata) Validate

func (m *Metadata) Validate() error

type MetadataItem

type MetadataItem struct {
	Name   string `json:"name"`
	Value  string `json:"value,omitempty"`
	Delete bool   `json:"delete,omitempty" bson:"-"`
}

MetadataItem is a Name-Value structure

type MockAppLogService

type MockAppLogService struct{}

func (*MockAppLogService) Add

func (m *MockAppLogService) Add(appName, message, source, unit string) error

func (*MockAppLogService) Enqueue

func (m *MockAppLogService) Enqueue(entry *Applog) error

func (*MockAppLogService) List

func (m *MockAppLogService) List(ctx context.Context, args ListLogArgs) ([]Applog, error)

func (*MockAppLogService) Watch

type MockAppService

type MockAppService struct {
	Apps                           []*App
	OnList                         func(filter *Filter) ([]*App, error)
	OnRegistry                     func(app *App) (image.ImageRegistry, error)
	OnGetAddresses                 func(app *App) ([]string, error)
	OnAddInstance                  func(app *App, addArgs bind.AddInstanceArgs) error
	OnRemoveInstance               func(app *App, removeArgs bind.RemoveInstanceArgs) error
	OnGetInternalBindableAddresses func(app *App) ([]string, error)
	OnGetHealthcheckData           func(app *App) (router.HealthcheckData, error)
}

func (*MockAppService) AddInstance

func (m *MockAppService) AddInstance(ctx context.Context, app *App, addArgs bind.AddInstanceArgs) error

func (*MockAppService) EnsureUUID

func (m *MockAppService) EnsureUUID(ctx context.Context, app *App) (string, error)

func (*MockAppService) GetAddresses

func (m *MockAppService) GetAddresses(ctx context.Context, app *App) ([]string, error)

func (*MockAppService) GetByName

func (m *MockAppService) GetByName(ctx context.Context, name string) (*App, error)

func (*MockAppService) GetHealthcheckData

func (m *MockAppService) GetHealthcheckData(ctx context.Context, app *App) (router.HealthcheckData, error)

func (*MockAppService) GetInternalBindableAddresses

func (m *MockAppService) GetInternalBindableAddresses(ctx context.Context, app *App) ([]string, error)

func (*MockAppService) GetRegistry

func (m *MockAppService) GetRegistry(ctx context.Context, app *App) (image.ImageRegistry, error)

func (*MockAppService) List

func (m *MockAppService) List(ctx context.Context, f *Filter) ([]*App, error)

func (*MockAppService) RemoveInstance

func (m *MockAppService) RemoveInstance(ctx context.Context, app *App, removeArgs bind.RemoveInstanceArgs) error

type MockLogWatcher

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

func NewMockLogWatcher

func NewMockLogWatcher() *MockLogWatcher

func (*MockLogWatcher) Chan

func (m *MockLogWatcher) Chan() <-chan Applog

func (*MockLogWatcher) Close

func (m *MockLogWatcher) Close()

func (*MockLogWatcher) Enqueue

func (m *MockLogWatcher) Enqueue(log Applog)

type MockPlanService

type MockPlanService struct {
	Plans []Plan

	OnCreate      func(Plan) error
	OnList        func() ([]Plan, error)
	OnFindByName  func(string) (*Plan, error)
	OnDefaultPlan func() (*Plan, error)
	OnRemove      func(string) error
}

MockPlanService implements PlanService interface

func (*MockPlanService) Create

func (m *MockPlanService) Create(ctx context.Context, plan Plan) error

func (*MockPlanService) DefaultPlan

func (m *MockPlanService) DefaultPlan(ctx context.Context) (*Plan, error)

func (*MockPlanService) FindByName

func (m *MockPlanService) FindByName(ctx context.Context, name string) (*Plan, error)

func (*MockPlanService) List

func (m *MockPlanService) List(ctx context.Context) ([]Plan, error)

func (*MockPlanService) Remove

func (m *MockPlanService) Remove(ctx context.Context, name string) error

type MockPlanStorage

type MockPlanStorage struct {
	OnInsert      func(Plan) error
	OnFindAll     func() ([]Plan, error)
	OnFindDefault func() (*Plan, error)
	OnFindByName  func(string) (*Plan, error)
	OnDelete      func(Plan) error
}

MockPlanStorage implements PlanStorage interface

func (*MockPlanStorage) Delete

func (m *MockPlanStorage) Delete(ctx context.Context, p Plan) error

func (*MockPlanStorage) FindAll

func (m *MockPlanStorage) FindAll(ctx context.Context) ([]Plan, error)

func (*MockPlanStorage) FindByName

func (m *MockPlanStorage) FindByName(ctx context.Context, name string) (*Plan, error)

func (*MockPlanStorage) FindDefault

func (m *MockPlanStorage) FindDefault(ctx context.Context) (*Plan, error)

func (*MockPlanStorage) Insert

func (m *MockPlanStorage) Insert(ctx context.Context, p Plan) error

type MockPlatformService

type MockPlatformService struct {
	OnCreate     func(PlatformOptions) error
	OnList       func(bool) ([]Platform, error)
	OnFindByName func(string) (*Platform, error)
	OnUpdate     func(PlatformOptions) error
	OnRemove     func(string) error
	OnRollback   func(PlatformOptions) error
}

MockPlatformService implements PlatformService interface

func (*MockPlatformService) Create

func (*MockPlatformService) FindByName

func (m *MockPlatformService) FindByName(ctx context.Context, name string) (*Platform, error)

func (*MockPlatformService) List

func (m *MockPlatformService) List(ctx context.Context, enabledOnly bool) ([]Platform, error)

func (*MockPlatformService) Remove

func (m *MockPlatformService) Remove(ctx context.Context, name string) error

func (*MockPlatformService) Rollback

func (m *MockPlatformService) Rollback(ctx context.Context, opts PlatformOptions) error

func (*MockPlatformService) Update

type MockPlatformStorage

type MockPlatformStorage struct {
	OnInsert      func(Platform) error
	OnFindByName  func(string) (*Platform, error)
	OnFindAll     func() ([]Platform, error)
	OnFindEnabled func() ([]Platform, error)
	OnUpdate      func(Platform) error
	OnDelete      func(Platform) error
}

MockPlatformStorage implements PlatformStorage interface

func (*MockPlatformStorage) Delete

func (m *MockPlatformStorage) Delete(ctx context.Context, p Platform) error

func (*MockPlatformStorage) FindAll

func (m *MockPlatformStorage) FindAll(ctx context.Context) ([]Platform, error)

func (*MockPlatformStorage) FindByName

func (m *MockPlatformStorage) FindByName(ctx context.Context, name string) (*Platform, error)

func (*MockPlatformStorage) FindEnabled

func (m *MockPlatformStorage) FindEnabled(ctx context.Context) ([]Platform, error)

func (*MockPlatformStorage) Insert

func (m *MockPlatformStorage) Insert(ctx context.Context, p Platform) error

func (*MockPlatformStorage) Update

func (m *MockPlatformStorage) Update(ctx context.Context, p Platform) error

type NewVersionArgs

type NewVersionArgs struct {
	EventID        string
	App            *App
	CustomBuildTag string
	Description    string
}

type NoTeamsError

type NoTeamsError struct{}

NoTeamsError is the error returned when one tries to create an app without any team.

func (NoTeamsError) Error

func (err NoTeamsError) Error() string

type Plan

type Plan struct {
	Name     string        `json:"name"`
	Memory   int64         `json:"memory"`
	CPUMilli int           `json:"cpumilli"`
	CPUBurst *CPUBurst     `json:"cpuBurst,omitempty"`
	Default  bool          `json:"default,omitempty"`
	Override *PlanOverride `json:"override,omitempty"`
}

func (Plan) GetCPUBurst

func (p Plan) GetCPUBurst() float64

func (Plan) GetMemory

func (p Plan) GetMemory() int64

func (Plan) GetMilliCPU

func (p Plan) GetMilliCPU() int

func (*Plan) MergeOverride

func (p *Plan) MergeOverride(po PlanOverride)

type PlanOverride

type PlanOverride struct {
	Memory   *int64   `json:"memory"`
	CPUMilli *int     `json:"cpumilli"`
	CPUBurst *float64 `json:"cpuBurst"`
}

type PlanService

type PlanService interface {
	Create(ctx context.Context, plan Plan) error
	List(context.Context) ([]Plan, error)
	FindByName(ctx context.Context, name string) (*Plan, error)
	DefaultPlan(context.Context) (*Plan, error)
	Remove(ctx context.Context, planName string) error
}

type PlanStorage

type PlanStorage interface {
	Insert(context.Context, Plan) error
	FindAll(context.Context) ([]Plan, error)
	FindDefault(context.Context) (*Plan, error)
	FindByName(context.Context, string) (*Plan, error)
	Delete(context.Context, Plan) error
}

type PlanValidationError

type PlanValidationError struct {
	Field string
}

func (PlanValidationError) Error

func (p PlanValidationError) Error() string

type Platform

type Platform struct {
	Name     string
	Disabled bool
}

type PlatformOptions

type PlatformOptions struct {
	Name            string
	Version         int
	ExtraTags       []string
	Args            map[string]string
	Output          io.Writer
	Data            []byte
	RollbackVersion int
}

type PlatformStorage

type PlatformStorage interface {
	Insert(context.Context, Platform) error
	FindByName(context.Context, string) (*Platform, error)
	FindAll(context.Context) ([]Platform, error)
	FindEnabled(context.Context) ([]Platform, error)
	Update(context.Context, Platform) error
	Delete(context.Context, Platform) error
}

type Process

type Process struct {
	Name     string   `json:"name"` // name of process, it is like a merge key
	Plan     string   `json:"plan,omitempty"`
	Metadata Metadata `json:"metadata"`
}

func (*Process) Empty

func (p *Process) Empty() bool

type RoutableAddresses

type RoutableAddresses struct {
	Prefix    string
	Addresses []*url.URL
	ExtraData map[string]string
}

type RouterCertificateInfo

type RouterCertificateInfo struct {
	CNames map[string]CertificateInfo `json:"cnames"`
}

func (*RouterCertificateInfo) IsEmpty

func (rci *RouterCertificateInfo) IsEmpty() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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