core

package
v0.0.32-pre1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultNamespace = "apps"
View Source
const (
	LoginTypeAPIKey = "APIKey"
)

Variables

View Source
var ErrConflictNewerVersion = errors.New("a newer version of the object exists")
View Source
var ErrNotFound = errors.New("the object could not be found")

Functions

func NewValidationError

func NewValidationError(message string, validationError error) error

NewValidationError creates a ValidationError conditional on the type of error passed in. It is expected that validationError is typically of type ozzo-validation.Errors object, containing a key/value pair of string/errors, but it can be of any type of error that is consumable by a client.

func NewValidationErrorMessage added in v0.0.8

func NewValidationErrorMessage(message string) error

NewValidationErrorMessage creates a ValidationError without an underlying error.

Types

type ApiKey

type ApiKey struct {
	UserId  uuid.UUID `json:"userId"`
	KeyHash []byte    `json:"keyHash"`
}

type ApiKeyRepository

type ApiKeyRepository interface {
	GetByUserId(userId uuid.UUID) ([]ApiKey, error)
	Create(userId uuid.UUID, keyHash []byte) error
}

type App

type App struct {
	Id        uuid.UUID
	Name      string
	Namespace string
}

type AppRepository

type AppRepository interface {
	Get(id uuid.UUID) (*App, error)
	GetByName(*NamespacedName) (*App, error)
	Create(app *App) error
	ListApps() ([]App, error)
}

type AppStatus

type AppStatus struct {
	StageStatuses []StageStatus
	// Deployments returns the whole deployment. We should probably use a different type here with less data, but we can't just pass
	// Deployment.Doc.Status as we also need the DeploymentName and the Stage.
	Deployments []Deployment
}

type Deployment

type Deployment struct {
	DeploymentReservation
	DeploymentRecord
}

Deployment represents a deployment in a particular stage

type DeploymentConfig

type DeploymentConfig struct {
	Name      string
	Namespace string
	Stage     string
	Docker    DeploymentDocker
	// TODO: Move to core and remove api/v1/model dependency
	App           *model.AppConfig
	Traffic       TrafficConfig
	ManualRollout bool
}

type DeploymentContext

type DeploymentContext struct {
	Deployment    *DeploymentConfig
	Stage         *StageConfig
	RiserRevision int64
	Secrets       []SecretMeta
	ManualRollout bool
}

type DeploymentDoc

type DeploymentDoc struct {
	Status  *DeploymentStatus   `json:"status,omitempty"`
	Traffic []TrafficConfigRule `json:"traffic"`
}

func (*DeploymentDoc) Scan

func (a *DeploymentDoc) Scan(value interface{}) error

Needed for sql.Scanner interface

func (*DeploymentDoc) Value

func (a *DeploymentDoc) Value() (driver.Value, error)

Needed for sql.Scanner interface

type DeploymentDocker

type DeploymentDocker struct {
	Tag string `json:"tag"`
}

type DeploymentRecord added in v0.0.10

type DeploymentRecord struct {
	Id            uuid.UUID
	ReservationId uuid.UUID
	StageName     string
	// RiserRevision is for tracking deployment changes and has no relation to a k8s deployment revision
	RiserRevision int64
	DeletedAt     *time.Time
	Doc           DeploymentDoc
}

DeploymentRecord represents the database fields specific for a deployment

type DeploymentRepository

type DeploymentRepository interface {
	Create(newDeployment *DeploymentRecord) error
	Delete(name *NamespacedName, stageName string) error
	GetByReservation(reservationId uuid.UUID, stageName string) (*Deployment, error)
	GetByName(name *NamespacedName, stageName string) (*Deployment, error)
	FindByApp(appId uuid.UUID) ([]Deployment, error)
	UpdateStatus(name *NamespacedName, stageName string, status *DeploymentStatus) error
	UpdateTraffic(name *NamespacedName, stageName string, riserRevision int64, traffic TrafficConfig) error
	IncrementRevision(name *NamespacedName, stageName string) (int64, error)
	RollbackRevision(name *NamespacedName, stageName string, failedRevision int64) (int64, error)
}

type DeploymentReservation added in v0.0.10

type DeploymentReservation struct {
	Id    uuid.UUID
	AppId uuid.UUID
	Name  string
	// At the time of writing the namespace should never be different from the app's namespace as we do not allow a deployment
	// to be deployed to a different namespace than the app. This may change in the future
	Namespace string
}

DeploymentReservation represents a reservation of a deployment name to an app

type DeploymentReservationRepository added in v0.0.10

type DeploymentReservationRepository interface {
	Create(reservation *DeploymentReservation) error
	GetByName(name *NamespacedName) (*DeploymentReservation, error)
}

type DeploymentRevisionStatus added in v0.0.6

type DeploymentRevisionStatus struct {
	Name                 string `json:"name"`
	AvailableReplicas    int32  `json:"availableReplicas"`
	DockerImage          string `json:"dockerImage"`
	RiserRevision        int64  `json:"riserRevision"`
	RevisionStatus       string `json:"revisionStatus"`
	RevisionStatusReason string `json:"revisionStatusReason"`
}

type DeploymentStatus

type DeploymentStatus struct {
	ObservedRiserRevision     int64                      `json:"observedRiserRevision"`
	LastUpdated               time.Time                  `json:"lastUpdated"`
	Revisions                 []DeploymentRevisionStatus `json:"revisions"`
	LatestReadyRevisionName   string                     `json:"latestReadyRevisionName"`
	LatestCreatedRevisionName string                     `json:"latestCreatedRevisionName"`
	Traffic                   []DeploymentTrafficStatus  `json:"traffic"`
}

func (*DeploymentStatus) Value

func (a *DeploymentStatus) Value() (driver.Value, error)

Needed for sql.Scanner interface. Normally this is only needed on the "Doc" object but we need this here since we do status only updates.

type DeploymentTrafficStatus added in v0.0.6

type DeploymentTrafficStatus struct {
	Percent      *int64 `json:"percent,omitempty"`
	RevisionName string `json:"revisionName"`
	Tag          string `json:"tag,omitempty"`
}

type FakeApiKeyRepository

type FakeApiKeyRepository struct {
	GetByUserIdFn   func(uuid.UUID) ([]ApiKey, error)
	CreateFn        func(uuid.UUID, []byte) error
	CreateCallCount int
}

func (*FakeApiKeyRepository) Create

func (r *FakeApiKeyRepository) Create(userId uuid.UUID, keyHash []byte) error

func (*FakeApiKeyRepository) GetByUserId

func (r *FakeApiKeyRepository) GetByUserId(userId uuid.UUID) ([]ApiKey, error)

type FakeAppRepository

type FakeAppRepository struct {
	GetFn              func(id uuid.UUID) (*App, error)
	GetCallCount       int
	GetByNameFn        func(*NamespacedName) (*App, error)
	GetByNameCallCount int
	CreateFn           func(app *App) error
	ListAppsFn         func() ([]App, error)
}

func (*FakeAppRepository) Create

func (fake *FakeAppRepository) Create(app *App) error

func (*FakeAppRepository) Get

func (fake *FakeAppRepository) Get(id uuid.UUID) (*App, error)

func (*FakeAppRepository) GetByName added in v0.0.10

func (fake *FakeAppRepository) GetByName(name *NamespacedName) (*App, error)

func (*FakeAppRepository) ListApps

func (fake *FakeAppRepository) ListApps() ([]App, error)

type FakeDeploymentRepository

type FakeDeploymentRepository struct {
	CreateFn                   func(newDeployment *DeploymentRecord) error
	CreateCallCount            int
	DeleteFn                   func(name *NamespacedName, stageName string) error
	DeleteCallCount            int
	GetByNameFn                func(name *NamespacedName, stageName string) (*Deployment, error)
	GetByReservationFn         func(reservationId uuid.UUID, stageName string) (*Deployment, error)
	GetByReservationCallCount  int
	FindByAppFn                func(uuid.UUID) ([]Deployment, error)
	IncrementRevisionFn        func(name *NamespacedName, stageName string) (int64, error)
	IncrementRevisionCallCount int
	RollbackRevisionFn         func(name *NamespacedName, stageName string, failedRevision int64) (int64, error)
	UpdateStatusFn             func(name *NamespacedName, stageName string, status *DeploymentStatus) error
	UpdateStatusCallCount      int
	UpdateTrafficFn            func(name *NamespacedName, stageName string, riserRevision int64, traffic TrafficConfig) error
	UpdateTrafficCallCount     int
}

func (*FakeDeploymentRepository) Create

func (f *FakeDeploymentRepository) Create(newDeployment *DeploymentRecord) error

func (*FakeDeploymentRepository) Delete added in v0.0.7

func (f *FakeDeploymentRepository) Delete(name *NamespacedName, stageName string) error

func (*FakeDeploymentRepository) FindByApp

func (fake *FakeDeploymentRepository) FindByApp(appId uuid.UUID) ([]Deployment, error)

func (*FakeDeploymentRepository) GetByName added in v0.0.10

func (f *FakeDeploymentRepository) GetByName(name *NamespacedName, stageName string) (*Deployment, error)

func (*FakeDeploymentRepository) GetByReservation added in v0.0.10

func (f *FakeDeploymentRepository) GetByReservation(reservationId uuid.UUID, stageName string) (*Deployment, error)

func (*FakeDeploymentRepository) IncrementRevision added in v0.0.7

func (fake *FakeDeploymentRepository) IncrementRevision(name *NamespacedName, stageName string) (int64, error)

func (*FakeDeploymentRepository) RollbackRevision added in v0.0.7

func (fake *FakeDeploymentRepository) RollbackRevision(name *NamespacedName, stageName string, failedRevision int64) (int64, error)

func (*FakeDeploymentRepository) UpdateStatus

func (fake *FakeDeploymentRepository) UpdateStatus(name *NamespacedName, stageName string, status *DeploymentStatus) error

func (*FakeDeploymentRepository) UpdateTraffic added in v0.0.6

func (fake *FakeDeploymentRepository) UpdateTraffic(name *NamespacedName, stageName string, riserRevision int64, traffic TrafficConfig) error

type FakeDeploymentReservationRepository added in v0.0.10

type FakeDeploymentReservationRepository struct {
	CreateFn        func(reservation *DeploymentReservation) error
	CreateCallCount int
	GetByNameFn     func(name *NamespacedName) (*DeploymentReservation, error)
}

func (*FakeDeploymentReservationRepository) Create added in v0.0.10

func (*FakeDeploymentReservationRepository) GetByName added in v0.0.10

type FakeNamespaceRepository added in v0.0.10

type FakeNamespaceRepository struct {
	CreateFn     func(namespace *Namespace) error
	GetFn        func(namespaceName string) (*Namespace, error)
	GetCallCount int
	ListFn       func() ([]Namespace, error)
}

func (*FakeNamespaceRepository) Create added in v0.0.10

func (fake *FakeNamespaceRepository) Create(namespace *Namespace) error

func (*FakeNamespaceRepository) Get added in v0.0.10

func (fake *FakeNamespaceRepository) Get(namespaceName string) (*Namespace, error)

func (*FakeNamespaceRepository) List added in v0.0.10

func (fake *FakeNamespaceRepository) List() ([]Namespace, error)

type FakeSecretMetaRepository

type FakeSecretMetaRepository struct {
	CommitFn           func(*SecretMeta) error
	CommitCallCount    int
	SaveFn             func(*SecretMeta) (int64, error)
	SaveCallCount      int
	ListByAppInStageFn func(*NamespacedName, string) ([]SecretMeta, error)
}

func (*FakeSecretMetaRepository) Commit added in v0.0.8

func (fake *FakeSecretMetaRepository) Commit(secretMeta *SecretMeta) error

func (*FakeSecretMetaRepository) ListByAppInStage added in v0.0.10

func (fake *FakeSecretMetaRepository) ListByAppInStage(appName *NamespacedName, stageName string) ([]SecretMeta, error)

func (*FakeSecretMetaRepository) Save

func (fake *FakeSecretMetaRepository) Save(secretMeta *SecretMeta) (int64, error)

type FakeStageRepository

type FakeStageRepository struct {
	GetFn         func(string) (*Stage, error)
	GetCallCount  int
	ListFn        func() ([]Stage, error)
	ListCallCount int
	SaveFn        func(*Stage) error
	SaveCallCount int
}

func (*FakeStageRepository) Get

func (fake *FakeStageRepository) Get(name string) (*Stage, error)

func (*FakeStageRepository) List

func (fake *FakeStageRepository) List() ([]Stage, error)

func (*FakeStageRepository) Save

func (fake *FakeStageRepository) Save(stage *Stage) error

type FakeUserRepository

type FakeUserRepository struct {
	GetByApiKeyFn    func(keyHash []byte) (*User, error)
	GetByUsernameFn  func(username string) (*User, error)
	CreateFn         func(newUser *NewUser) error
	CreateCallCount  int
	GetActiveCountFn func() (int, error)
}

func (*FakeUserRepository) Create

func (r *FakeUserRepository) Create(newUser *NewUser) error

func (*FakeUserRepository) GetActiveCount

func (r *FakeUserRepository) GetActiveCount() (int, error)

func (*FakeUserRepository) GetByApiKey

func (r *FakeUserRepository) GetByApiKey(keyHash []byte) (*User, error)

func (*FakeUserRepository) GetByUsername

func (r *FakeUserRepository) GetByUsername(username string) (*User, error)

type Namespace

type Namespace struct {
	Name string
}

type NamespaceRepository added in v0.0.10

type NamespaceRepository interface {
	Create(namespace *Namespace) error
	Get(namespaceName string) (*Namespace, error)
	List() ([]Namespace, error)
}

type NamespacedName added in v0.0.10

type NamespacedName struct {
	Name      string
	Namespace string
}

func NewNamespacedName added in v0.0.10

func NewNamespacedName(name, namespace string) *NamespacedName

func ParseNamespacedName added in v0.0.10

func ParseNamespacedName(namespacedName string) *NamespacedName

func (*NamespacedName) String added in v0.0.10

func (v *NamespacedName) String() string

type NewUser

type NewUser struct {
	Id       uuid.UUID
	Username string
}

type ResourceFile

type ResourceFile struct {
	Name     string `json:"name"`
	Contents []byte `json:"contents"`
	Delete   bool   `json:"delete,omitempty"`
}

type RuntimeConfig

type RuntimeConfig struct {
	BootstrapApikey          string `split_words:"true"`
	BindAddress              string `split_words:"true" default:":8000"`
	DeveloperMode            bool   `split_words:"true"`
	GitUrl                   string `split_words:"true" required:"true"`
	GitDir                   string `split_words:"true" default:"/tmp/riser/git/"`
	GitBranch                string `split_words:"true" default:"master"`
	GitUsername              string `split_words:"true"`
	GitPassword              string `split_words:"true"`
	PostgresUrl              string `split_words:"true" default:"postgres://postgres.riser-system.svc.cluster.local/riserdb?sslmode=disable&connect_timeout=3"`
	PostgresUsername         string `split_words:"true" required:"true"`
	PostgresPassword         string `split_words:"true" required:"true"`
	PostgresMigrateOnStartup bool   `split_words:"true" default:"true"`
}

RuntimeConfig provides config for the srver.

type SecretMeta

type SecretMeta struct {
	Name      string
	App       *NamespacedName
	StageName string
	Revision  int64
}

type SecretMetaRepository

type SecretMetaRepository interface {
	// Commit commits a secretmeta at the specified revision. This is an acknowledgement that the secret has been committed to the underlying
	// resource (e.g. the git state repo)
	Commit(secretMeta *SecretMeta) error
	// Save saves the secret meta and returns a new revision. It is up to the caller to modify the secretMeta with the new revision.
	// Important: You must call r.Commit to validate that the object has been committed. Uncommitted secrets are not applied to deployments
	Save(secretMeta *SecretMeta) (revision int64, err error)
	ListByAppInStage(appName *NamespacedName, stageName string) ([]SecretMeta, error)
}

type Stage

type Stage struct {
	Name string
	Doc  StageDoc
}

type StageConfig

type StageConfig struct {
	SealedSecretCert  []byte `json:"sealedSecretCert"`
	PublicGatewayHost string `json:"publicGatewayHost"`
}

type StageDoc

type StageDoc struct {
	LastPing time.Time   `json:"lastPing"`
	Config   StageConfig `json:"config"`
}

func (*StageDoc) Scan

func (a *StageDoc) Scan(value interface{}) error

Needed for sql.Scanner interface

func (*StageDoc) Value

func (a *StageDoc) Value() (driver.Value, error)

Needed for sql.Scanner interface

type StageRepository

type StageRepository interface {
	Get(name string) (*Stage, error)
	List() ([]Stage, error)
	Save(stage *Stage) error
}

type StageStatus

type StageStatus struct {
	StageName string
	Healthy   bool
	Reason    string
}

type StatusProblem added in v0.0.6

type StatusProblem struct {
	Count   int    `json:"count"`
	Message string `json:"message"`
}

type TrafficConfig added in v0.0.6

type TrafficConfig []TrafficConfigRule

Needed for serialization to postgres since we do partial updates on traffic

func (TrafficConfig) Value added in v0.0.6

func (a TrafficConfig) Value() (driver.Value, error)

Needed for sql.Scanner interface. Normally this is only needed on the "Doc" object but we need this here since we do traffic only updates.

type TrafficConfigRule added in v0.0.6

type TrafficConfigRule struct {
	RiserRevision int64  `json:"riserRevision"`
	RevisionName  string `json:"revisionName"`
	Percent       int    `json:"percent"`
}

type User

type User struct {
	Id       uuid.UUID
	Username string
	Doc      UserDoc
}

type UserDoc

type UserDoc struct {
	Created time.Time `json:"created"`
}

func (*UserDoc) Scan

func (a *UserDoc) Scan(value interface{}) error

Needed for sql.Scanner interface

func (*UserDoc) Value

func (a *UserDoc) Value() (driver.Value, error)

Needed for sql.Scanner interface

type UserRepository

type UserRepository interface {
	GetByApiKey(keyHash []byte) (*User, error)
	GetByUsername(username string) (*User, error)
	Create(newUser *NewUser) error
	GetActiveCount() (int, error)
}

type ValidationError

type ValidationError struct {
	Message string
	// ValidationError represents the validation error that ocurred. See the API errorHandler for how this is returned to the client.
	ValidationError error
	// contains filtered or unexported fields
}

ValidationError provides an error consumable by a client. This is safe to return to the API as the errorHandler is aware of this error

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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