core

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 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 {
	AppId             uuid.UUID
	EnvironmentStatus []EnvironmentStatus
	// 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 environment.
	Deployments []Deployment
}

type Deployment

type Deployment struct {
	DeploymentReservation
	DeploymentRecord
}

Deployment represents a deployment in a particular environment

type DeploymentConfig

type DeploymentConfig struct {
	Name            string
	Namespace       string
	EnvironmentName 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 {
	DeploymentConfig  *DeploymentConfig
	EnvironmentConfig *EnvironmentConfig
	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
	EnvironmentName 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, envName string) error
	GetByReservation(reservationId uuid.UUID, envName string) (*Deployment, error)
	GetByName(name *NamespacedName, envName string) (*Deployment, error)
	FindByApp(appId uuid.UUID) ([]Deployment, error)
	UpdateStatus(name *NamespacedName, envName string, status *DeploymentStatus) error
	UpdateTraffic(name *NamespacedName, envName string, riserRevision int64, traffic TrafficConfig) error
	IncrementRevision(name *NamespacedName, envName string) (int64, error)
	RollbackRevision(name *NamespacedName, envName 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"`
	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 Environment added in v0.0.17

type Environment struct {
	Name string
	Doc  EnvironmentDoc
}

type EnvironmentConfig added in v0.0.17

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

type EnvironmentDoc added in v0.0.17

type EnvironmentDoc struct {
	LastPing time.Time         `json:"lastPing"`
	Config   EnvironmentConfig `json:"config"`
}

func (*EnvironmentDoc) Scan added in v0.0.17

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

Needed for sql.Scanner interface

func (*EnvironmentDoc) Value added in v0.0.17

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

Needed for sql.Scanner interface

type EnvironmentRepository added in v0.0.17

type EnvironmentRepository interface {
	Get(name string) (*Environment, error)
	List() ([]Environment, error)
	Save(environment *Environment) error
}

type EnvironmentStatus added in v0.0.17

type EnvironmentStatus struct {
	EnvironmentName string
	Healthy         bool
	Reason          string
}

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, envName string) error
	DeleteCallCount            int
	GetByNameFn                func(name *NamespacedName, envName string) (*Deployment, error)
	GetByReservationFn         func(reservationId uuid.UUID, envName string) (*Deployment, error)
	GetByReservationCallCount  int
	FindByAppFn                func(uuid.UUID) ([]Deployment, error)
	IncrementRevisionFn        func(name *NamespacedName, envName string) (int64, error)
	IncrementRevisionCallCount int
	RollbackRevisionFn         func(name *NamespacedName, envName string, failedRevision int64) (int64, error)
	UpdateStatusFn             func(name *NamespacedName, envName string, status *DeploymentStatus) error
	UpdateStatusCallCount      int
	UpdateTrafficFn            func(name *NamespacedName, envName 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, envName 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, envName string) (*Deployment, error)

func (*FakeDeploymentRepository) GetByReservation added in v0.0.10

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

func (*FakeDeploymentRepository) IncrementRevision added in v0.0.7

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

func (*FakeDeploymentRepository) RollbackRevision added in v0.0.7

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

func (*FakeDeploymentRepository) UpdateStatus

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

func (*FakeDeploymentRepository) UpdateTraffic added in v0.0.6

func (fake *FakeDeploymentRepository) UpdateTraffic(name *NamespacedName, envName 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 FakeEnvironmentRepository added in v0.0.17

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

func (*FakeEnvironmentRepository) Get added in v0.0.17

func (fake *FakeEnvironmentRepository) Get(name string) (*Environment, error)

func (*FakeEnvironmentRepository) List added in v0.0.17

func (fake *FakeEnvironmentRepository) List() ([]Environment, error)

func (*FakeEnvironmentRepository) Save added in v0.0.17

func (fake *FakeEnvironmentRepository) Save(environment *Environment) error

type FakeNamespaceRepository added in v0.0.10

type FakeNamespaceRepository struct {
	CreateFn        func(namespace *Namespace) error
	CreateCallCount int
	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
	ListByAppInEnvironmentFn func(*NamespacedName, string) ([]SecretMeta, error)
}

func (*FakeSecretMetaRepository) Commit added in v0.0.8

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

func (*FakeSecretMetaRepository) ListByAppInEnvironment added in v0.0.17

func (fake *FakeSecretMetaRepository) ListByAppInEnvironment(appName *NamespacedName, envName string) ([]SecretMeta, error)

func (*FakeSecretMetaRepository) Save

func (fake *FakeSecretMetaRepository) Save(secretMeta *SecretMeta) (int64, 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 is the temp directory to store the contents of the state repo. Warning: this directory is deleted on Riser server startup
	GitDir                   string `split_words:"true" default:"/tmp/riser/git/"`
	GitBranch                string `split_words:"true" default:"main"`
	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 server.

type SecretMeta

type SecretMeta struct {
	Name            string
	App             *NamespacedName
	EnvironmentName 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)
	ListByAppInEnvironment(appName *NamespacedName, envName string) ([]SecretMeta, error)
}

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