store

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFoundOrDirty = errors.New(
	"failed to find requested document. It is possible that this operation was a Dirty Write." +
		"Consider fetching the latest version of the requested document to repeat the read-write cycle",
)

ErrNotFoundOrDirty is returned when the requested document couldn't be found inside the database or a Dirty Write occurred.

Functions

func ConvertFromGRPCCluster added in v0.10.0

func ConvertFromGRPCCluster(k8s *spec.K8Scluster) ([]byte, error)

ConvertFromGRPCCluster deterministically converts the grpc representation to the database representation.

func ConvertFromGRPCLoadBalancers added in v0.10.0

func ConvertFromGRPCLoadBalancers(lbs *spec.LoadBalancers) ([]byte, error)

ConvertFromGRPCLoadBalancers deterministically converts the grpc representation to the database representation.

func ConvertFromGRPCTask added in v0.10.0

func ConvertFromGRPCTask(t *spec.Task) ([]byte, error)

func ConvertToGRPC

func ConvertToGRPC(cfg *Config) (*spec.Config, error)

ConvertToGRPC converts from database representation to GRPC representation. For clusters, it mimics the GRPC unmarshalling style where if a field was not set within a message it will be nil instead of a zero value for that type.

func ConvertToGRPCCluster added in v0.10.0

func ConvertToGRPCCluster(k8s []byte) (*spec.K8Scluster, error)

ConvertToGRPCCluster converts the database representation to the GRPC representation.

func ConvertToGRPCClusterState added in v0.10.0

func ConvertToGRPCClusterState(cluster *ClusterState) (*spec.ClusterState, error)

func ConvertToGRPCClusters added in v0.10.0

func ConvertToGRPCClusters(cluster Clusters) (*spec.Clusters, error)

convertClusters converts the database representation to the GRPC representation. If no error is returned, the result can still be nil. This is so that the GRPC representation will have a nil (essentially mimicking what the GRPC unmarshall does if the respective value is not set) value as well when converted which simplifies checking absence of a specific state (i.e. current, desired).

func ConvertToGRPCLoadBalancers added in v0.10.0

func ConvertToGRPCLoadBalancers(lbs []byte) (*spec.LoadBalancers, error)

ConvertToGRPCLoadBalancers converts the database representation to the GRPC representation.

func ConvertToGRPCStages added in v0.10.0

func ConvertToGRPCStages(stages []Stage) ([]*spec.Stage, error)

func ConvertToGRPCTask added in v0.10.0

func ConvertToGRPCTask(t []byte) (*spec.Task, error)

func ConvertToGRPCTaskEvent

func ConvertToGRPCTaskEvent(te *TaskEvent) (*spec.TaskEvent, error)

func ConvertToGRPCWorkflow

func ConvertToGRPCWorkflow(w Workflow) *spec.Workflow

ConvertToGRPCWorkflow converts the database representation of the workflow state to GRPC.

Types

type ClusterState

type ClusterState struct {
	Current  Clusters   `bson:"current"`
	InFlight *TaskEvent `bson:"inFlight"`
	State    Workflow   `bson:"state"`
}

func ConvertFromGRPCClusterState added in v0.10.0

func ConvertFromGRPCClusterState(cluster *spec.ClusterState) (*ClusterState, error)

func (*ClusterState) Exists added in v0.10.0

func (cs *ClusterState) Exists() bool

type Clusters

type Clusters struct {
	K8s           []byte `bson:"k8s"`
	LoadBalancers []byte `bson:"loadBalancers"`
}

func ConvertFromGRPCClusters added in v0.10.0

func ConvertFromGRPCClusters(cluster *spec.Clusters) (Clusters, error)

type Config

type Config struct {
	Version  uint64                   `bson:"version"`
	Name     string                   `bson:"name"`
	K8SCtx   KubernetesContext        `bson:"kubernetesContext"`
	Manifest Manifest                 `bson:"manifest"`
	Clusters map[string]*ClusterState `bson:"clusters"`
}

func ConvertFromGRPC

func ConvertFromGRPC(cfg *spec.Config) (*Config, error)

ConvertFromGRPC converts the grpc representation to the database representation.

type FinishedWorkflow added in v0.10.0

type FinishedWorkflow struct {
	Status          string    `bson:"status"`
	Stage           StageKind `bson:"stage"`
	TaskDescription string    `bson:"taskDescription"`
	Timestamp       string    `bson:"timestamp"`
}

type InMemoryStore

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

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

func (*InMemoryStore) Close

func (i *InMemoryStore) Close() error

func (*InMemoryStore) CreateConfig

func (i *InMemoryStore) CreateConfig(_ context.Context, config *Config) error

func (*InMemoryStore) DeleteConfig

func (i *InMemoryStore) DeleteConfig(_ context.Context, name string, version uint64) error

func (*InMemoryStore) GetConfig

func (i *InMemoryStore) GetConfig(_ context.Context, name string) (*Config, error)

func (*InMemoryStore) HealthCheck

func (i *InMemoryStore) HealthCheck() error

func (*InMemoryStore) ListConfigs

func (i *InMemoryStore) ListConfigs(_ context.Context, filter *ListFilter) ([]*Config, error)

func (*InMemoryStore) MarkForDeletion

func (i *InMemoryStore) MarkForDeletion(_ context.Context, name string, version uint64) error

func (*InMemoryStore) UpdateConfig

func (i *InMemoryStore) UpdateConfig(_ context.Context, config *Config) error

type KubernetesContext

type KubernetesContext struct {
	Name      string `bson:"name"`
	Namespace string `bson:"namespace"`
}

type ListFilter

type ListFilter struct {
	ManifestState []string
}

ListFilter wraps supported filters for listing configs.

type Manifest

type Manifest struct {
	Raw                 string `bson:"raw"`
	Checksum            []byte `bson:"checksum"`
	LastAppliedChecksum []byte `bson:"lastAppliedChecksum"`
	State               string `bson:"state"`
}

type Mongo

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

func NewMongoClient

func NewMongoClient(ctx context.Context, uri string) (*Mongo, error)

func (*Mongo) Close

func (m *Mongo) Close() error

func (*Mongo) CreateConfig

func (m *Mongo) CreateConfig(ctx context.Context, config *Config) error

func (*Mongo) DeleteConfig

func (m *Mongo) DeleteConfig(ctx context.Context, name string, version uint64) error

func (*Mongo) GetConfig

func (m *Mongo) GetConfig(ctx context.Context, name string) (*Config, error)

func (*Mongo) HealthCheck

func (m *Mongo) HealthCheck() error

func (*Mongo) Init

func (m *Mongo) Init() error

func (*Mongo) ListConfigs

func (m *Mongo) ListConfigs(ctx context.Context, filter *ListFilter) ([]*Config, error)

func (*Mongo) MarkForDeletion

func (m *Mongo) MarkForDeletion(ctx context.Context, name string, version uint64) error

func (*Mongo) UpdateConfig

func (m *Mongo) UpdateConfig(ctx context.Context, config *Config) error

type Stage added in v0.10.0

type Stage struct {
	Kind        StageKind        `bson:"kind"`
	Description StageDescription `bson:"description"`
	SubPasses   []SubPass        `bson:"subPasses"`
}

func ConvertFromGRPCStages added in v0.10.0

func ConvertFromGRPCStages(stages []*spec.Stage) ([]Stage, error)

type StageDescription added in v0.10.0

type StageDescription struct {
	About      string `bson:"about"`
	ErrorLevel string `bson:"errorLevel"`
}

type StageKind added in v0.10.0

type StageKind string
const (
	Unknown     StageKind = ""
	Terraformer StageKind = "TERRAFORMER"
	Ansibler    StageKind = "ANSIBLER"
	KubeEleven  StageKind = "KUBE_ELEVEN"
	Kuber       StageKind = "KUBER"
)

type Store

type Store interface {
	io.Closer
	healthcheck.HealthChecker

	// CreateConfig creates a new config. It is up to the application logic to determine if the
	// config already exists or not. On conflict, the creation will error out. The Version field
	// of the config will always be overwritten to 0 as new configs always start with a version of 0.
	CreateConfig(ctx context.Context, config *Config) error

	// UpdateConfig updates an existing config in the database with the new supplied data. If there is no document
	// that matches the Config.Name and Config.Version the ErrNotFoundOrDirty err is returned. It is up to the application
	// code to determine, if the write was Dirty (i.e. outdated Document version used) or there is no such document with the
	// requested Config.Name and Config.Version combination. Before updating the document, a higher document version
	// number by 1 will replace the supplied number in Config.Version (i.e. Config.Version += 1).
	UpdateConfig(ctx context.Context, config *Config) error

	// GetConfig queries the document with the Config.Name. If no such document is found the ErrNotFoundOrDirty err
	// is returned. In this case it always will be the case that the document is absent. This can be used by the application
	// code to determine an absent document or Dirty Write.
	GetConfig(ctx context.Context, name string) (*Config, error)

	// ListConfigs queries all documents stored that satisfy the passed in ListFilter.
	ListConfigs(ctx context.Context, filter *ListFilter) ([]*Config, error)

	// DeleteConfig will delete the document with the requested Config.Name and Config.Version combination.
	// If No documents with the given combination were deleted the ErrNotFoundOrDirty err is returned. It is up
	// to the application code to handle the case in which a Dirty Write occurred or the document does not exist.
	DeleteConfig(ctx context.Context, name string, version uint64) error

	// MarkForDeletion will mark the infrastructure in the document with the requested Config.Name and Config.Version for
	// deletion. If No documents with the given combination were marked for deletion the ErrNotFoundOrDirty err is returned. It is up
	// to the application code to handle the case in which a Dirty Write occurred or the document does not exist.
	MarkForDeletion(ctx context.Context, name string, version uint64) error
}

type SubPass added in v0.10.0

type SubPass struct {
	Kind        string           `bson:"kind"`
	Description StageDescription `bson:"description"`
}

type TaskEvent

type TaskEvent struct {
	Id            string     `bson:"id"`
	Timestamp     string     `bson:"timestamp"`
	Type          string     `bson:"event"`
	Task          []byte     `bson:"task"`
	Description   string     `bson:"description"`
	Pipeline      []Stage    `bson:"pipeline"`
	CurrentStage  uint32     `bson:"currentStage"`
	LowerPriority *TaskEvent `bson:"lowerPriority"`

	// Deprecated.
	// TODO: remove in future versions.
	OnError []byte `bson:"onError"`
}

func ConvertFromGRPCTaskEvent added in v0.10.0

func ConvertFromGRPCTaskEvent(te *spec.TaskEvent) (*TaskEvent, error)

type Workflow

type Workflow struct {
	Status            string             `bson:"status"`
	Description       string             `bson:"description"`
	Timestamp         string             `bson:"timestamp"`
	Previous          []FinishedWorkflow `bson:"previous"`
	TicksUntilRefresh int32              `bson:"ticksUntilRefresh"`
}

func ConvertFromGRPCWorkflow

func ConvertFromGRPCWorkflow(w *spec.Workflow) Workflow

ConvertFromGRPCWorkflow converts the workflow state data from GRPC to the database representation.

Jump to

Keyboard shortcuts

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