store

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClusterAnnotationUsedByInstallation is an error returned when user attempts to delete cluster annotation
	// present on the installation scheduled on that cluster.
	ErrClusterAnnotationUsedByInstallation = errors.New("cannot delete cluster annotation, " +
		"it is used by one or more installations scheduled on the cluster")
	// ErrInstallationAnnotationDoNotMatchClusters is an error returned when user attempts to add annotation to the
	// installation, that is not present on any of the clusters on which the installation is scheduled.
	ErrInstallationAnnotationDoNotMatchClusters = errors.New("cannot add annotations to installation, " +
		"one or more clusters on which installation is scheduled do not contain one or more of new annotations")
)

Functions

func CloseConnection added in v0.31.0

func CloseConnection(tb testing.TB, sqlStore *SQLStore)

CloseConnection closes underlying database connection.

func GetMillis

func GetMillis() int64

GetMillis is a convenience method to get milliseconds since epoch.

func LatestVersion

func LatestVersion() semver.Version

LatestVersion returns the version to which the last migration migrates.

Types

type GroupRollingMetadata added in v0.18.0

type GroupRollingMetadata struct {
	InstallationIDsToBeRolled  []string
	InstallationTotalCount     int64
	InstallationStableCount    int64
	InstallationNonStableCount int64
}

GroupRollingMetadata is a batch of information about a group where installatons are being rolled to match a new config.

type RawClusterMetadata added in v0.20.0

type RawClusterMetadata struct {
	ProviderMetadataRaw    []byte
	ProvisionerMetadataRaw []byte
	UtilityMetadataRaw     []byte
}

RawClusterMetadata is the raw byte metadata for a cluster.

type SQLStore

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

SQLStore abstracts access to the database.

func MakeTestSQLStore

func MakeTestSQLStore(tb testing.TB, logger log.FieldLogger) *SQLStore

MakeTestSQLStore creates a SQLStore for use with unit tests.

func New

func New(dsn string, logger logrus.FieldLogger) (*SQLStore, error)

New constructs a new instance of SQLStore.

func (*SQLStore) CreateAnnotation added in v0.31.0

func (sqlStore *SQLStore) CreateAnnotation(annotation *model.Annotation) error

CreateAnnotation records the given annotation to the database, assigning it a unique ID.

func (*SQLStore) CreateCluster

func (sqlStore *SQLStore) CreateCluster(cluster *model.Cluster, annotations []*model.Annotation) error

CreateCluster records the given cluster to the database, assigning it a unique ID.

func (*SQLStore) CreateClusterAnnotations added in v0.31.0

func (sqlStore *SQLStore) CreateClusterAnnotations(clusterID string, annotations []*model.Annotation) ([]*model.Annotation, error)

CreateClusterAnnotations maps selected annotations to cluster and stores it in the database.

func (*SQLStore) CreateClusterInstallation

func (sqlStore *SQLStore) CreateClusterInstallation(clusterInstallation *model.ClusterInstallation) error

CreateClusterInstallation records the given cluster installation to the database, assigning it a unique ID.

func (*SQLStore) CreateGroup

func (sqlStore *SQLStore) CreateGroup(group *model.Group) error

CreateGroup records the given group to the database, assigning it a unique ID.

func (*SQLStore) CreateInstallation

func (sqlStore *SQLStore) CreateInstallation(installation *model.Installation, annotations []*model.Annotation) error

CreateInstallation records the given installation to the database, assigning it a unique ID.

func (*SQLStore) CreateInstallationAnnotations added in v0.31.0

func (sqlStore *SQLStore) CreateInstallationAnnotations(installationID string, annotations []*model.Annotation) ([]*model.Annotation, error)

CreateInstallationAnnotations maps selected annotations to installation and stores it in the database. Annotation cannot be added to the Installation if any of the clusters on which the Installation is scheduled is not annotated with it.

func (*SQLStore) CreateMultitenantDatabase added in v0.19.0

func (sqlStore *SQLStore) CreateMultitenantDatabase(multitenantDatabase *model.MultitenantDatabase) error

CreateMultitenantDatabase records the supplied multitenant database to the datastore.

func (*SQLStore) CreateWebhook added in v0.3.0

func (sqlStore *SQLStore) CreateWebhook(webhook *model.Webhook) error

CreateWebhook records the given webhook to the database, assigning it a unique ID.

func (*SQLStore) DeleteCluster

func (sqlStore *SQLStore) DeleteCluster(id string) error

DeleteCluster marks the given cluster as deleted, but does not remove the record from the database.

func (*SQLStore) DeleteClusterAnnotation added in v0.31.0

func (sqlStore *SQLStore) DeleteClusterAnnotation(clusterID string, annotationName string) error

DeleteClusterAnnotation removes an annotation from a given cluster. Annotation cannot be removed if it is present on any of the Installations scheduled on the cluster.

func (*SQLStore) DeleteClusterInstallation

func (sqlStore *SQLStore) DeleteClusterInstallation(id string) error

DeleteClusterInstallation marks the given cluster installation as deleted, but does not remove the record from the database.

func (*SQLStore) DeleteGroup

func (sqlStore *SQLStore) DeleteGroup(id string) error

DeleteGroup marks the given group as deleted, but does not remove the record from the database.

func (*SQLStore) DeleteInstallation

func (sqlStore *SQLStore) DeleteInstallation(id string) error

DeleteInstallation marks the given installation as deleted, but does not remove the record from the database.

func (*SQLStore) DeleteInstallationAnnotation added in v0.31.0

func (sqlStore *SQLStore) DeleteInstallationAnnotation(installationID string, annotationName string) error

DeleteInstallationAnnotation removes annotation from a given Installation.

func (*SQLStore) DeleteWebhook added in v0.3.0

func (sqlStore *SQLStore) DeleteWebhook(id string) error

DeleteWebhook marks the given webhook as deleted, but does not remove the record from the database.

func (*SQLStore) GetAnnotationByName added in v0.31.0

func (sqlStore *SQLStore) GetAnnotationByName(name string) (*model.Annotation, error)

GetAnnotationByName fetches the given annotation by name.

func (*SQLStore) GetAnnotationsForCluster added in v0.31.0

func (sqlStore *SQLStore) GetAnnotationsForCluster(clusterID string) ([]*model.Annotation, error)

GetAnnotationsForCluster fetches all annotations assigned to the cluster.

func (*SQLStore) GetAnnotationsForClusters added in v0.31.0

func (sqlStore *SQLStore) GetAnnotationsForClusters(filter *model.ClusterFilter) (map[string][]*model.Annotation, error)

GetAnnotationsForClusters fetches all annotations assigned to the clusters.

func (*SQLStore) GetAnnotationsForInstallation added in v0.31.0

func (sqlStore *SQLStore) GetAnnotationsForInstallation(installationID string) ([]*model.Annotation, error)

GetAnnotationsForInstallation fetches all annotations assigned to the installation.

func (*SQLStore) GetAnnotationsForInstallations added in v0.31.0

func (sqlStore *SQLStore) GetAnnotationsForInstallations(filter *model.InstallationFilter) (map[string][]*model.Annotation, error)

GetAnnotationsForInstallations fetches all annotations assigned to installations.

func (*SQLStore) GetCluster

func (sqlStore *SQLStore) GetCluster(id string) (*model.Cluster, error)

GetCluster fetches the given cluster by id.

func (*SQLStore) GetClusterDTO added in v0.31.0

func (sqlStore *SQLStore) GetClusterDTO(id string) (*model.ClusterDTO, error)

GetClusterDTO fetches the given cluster by id with data from connected tables.

func (*SQLStore) GetClusterDTOs added in v0.31.0

func (sqlStore *SQLStore) GetClusterDTOs(filter *model.ClusterFilter) ([]*model.ClusterDTO, error)

GetClusterDTOs fetches the given page of clusters with data from connected tables. The first page is 0.

func (*SQLStore) GetClusterInstallation

func (sqlStore *SQLStore) GetClusterInstallation(id string) (*model.ClusterInstallation, error)

GetClusterInstallation fetches the given cluster installation by id.

func (*SQLStore) GetClusterInstallations

func (sqlStore *SQLStore) GetClusterInstallations(filter *model.ClusterInstallationFilter) ([]*model.ClusterInstallation, error)

GetClusterInstallations fetches the given page of created clusters. The first page is 0.

func (*SQLStore) GetClusters

func (sqlStore *SQLStore) GetClusters(filter *model.ClusterFilter) ([]*model.Cluster, error)

GetClusters fetches the given page of created clusters. The first page is 0.

func (*SQLStore) GetCurrentVersion

func (sqlStore *SQLStore) GetCurrentVersion() (semver.Version, error)

GetCurrentVersion queries the System table for the current database version.

func (*SQLStore) GetGroup

func (sqlStore *SQLStore) GetGroup(id string) (*model.Group, error)

GetGroup fetches the given group by id.

func (*SQLStore) GetGroupRollingMetadata added in v0.18.0

func (sqlStore *SQLStore) GetGroupRollingMetadata(groupID string) (*GroupRollingMetadata, error)

GetGroupRollingMetadata returns installation IDs and metadata related to installation configuration reconciliation from group updates.

Note: custom SQL queries are used here instead of calling GetInstallations(). This is done for performance as we don't need the actual installation objects in most cases.

TODO: currently the installations returned are only those that are in the group AND not on the latest sequence AND are in stable state. This is a best-case scenario that probably won't work in the long run. Other non-stable states will probably need to be added once they have been properly tested.

func (*SQLStore) GetGroupStatus added in v0.30.0

func (sqlStore *SQLStore) GetGroupStatus(groupID string) (*model.GroupStatus, error)

GetGroupStatus returns total number of installations in the group as well as number or Installations already rolled out and awaiting rollout.

Note: This function uses the same conditions as GetGroupRollingMetadata to be more accurate with the internal state seen by the Group Supervisor.

func (*SQLStore) GetGroups

func (sqlStore *SQLStore) GetGroups(filter *model.GroupFilter) ([]*model.Group, error)

GetGroups fetches the given page of created groups. The first page is 0.

func (*SQLStore) GetInstallation

func (sqlStore *SQLStore) GetInstallation(id string, includeGroupConfig, includeGroupConfigOverrides bool) (*model.Installation, error)

GetInstallation fetches the given installation by id.

func (*SQLStore) GetInstallationDTO added in v0.31.0

func (sqlStore *SQLStore) GetInstallationDTO(id string, includeGroupConfig, includeGroupConfigOverrides bool) (*model.InstallationDTO, error)

GetInstallationDTO fetches the given installation by id with data from connected tables.

func (*SQLStore) GetInstallationDTOs added in v0.31.0

func (sqlStore *SQLStore) GetInstallationDTOs(filter *model.InstallationFilter, includeGroupConfig, includeGroupConfigOverrides bool) ([]*model.InstallationDTO, error)

GetInstallationDTOs fetches the given page of installation with data from connected tables. The first page is 0.

func (*SQLStore) GetInstallations

func (sqlStore *SQLStore) GetInstallations(filter *model.InstallationFilter, includeGroupConfig, includeGroupConfigOverrides bool) ([]*model.Installation, error)

GetInstallations fetches the given page of created installations. The first page is 0.

func (*SQLStore) GetInstallationsCount added in v0.26.0

func (sqlStore *SQLStore) GetInstallationsCount(includeDeleted bool) (int, error)

GetInstallationsCount returns the number of installations filtered by the deletedat field

func (*SQLStore) GetMultitenantDatabase added in v0.19.0

func (sqlStore *SQLStore) GetMultitenantDatabase(id string) (*model.MultitenantDatabase, error)

GetMultitenantDatabase fetches the given multitenant database by id.

func (*SQLStore) GetMultitenantDatabaseForInstallationID added in v0.19.0

func (sqlStore *SQLStore) GetMultitenantDatabaseForInstallationID(installationID string) (*model.MultitenantDatabase, error)

GetMultitenantDatabaseForInstallationID fetches the multitenant database associated with an installation ID. If more than one multitenant database per installation exists, this function returns an error.

func (*SQLStore) GetMultitenantDatabases added in v0.19.0

func (sqlStore *SQLStore) GetMultitenantDatabases(filter *model.MultitenantDatabaseFilter) ([]*model.MultitenantDatabase, error)

GetMultitenantDatabases fetches the given page of created multitenant database. The first page is 0.

func (*SQLStore) GetOrCreateAnnotations added in v0.31.0

func (sqlStore *SQLStore) GetOrCreateAnnotations(annotations []*model.Annotation) ([]*model.Annotation, error)

GetOrCreateAnnotations fetches annotations by name or creates them if they do not exist.

func (*SQLStore) GetUnlockedClusterInstallationsPendingWork

func (sqlStore *SQLStore) GetUnlockedClusterInstallationsPendingWork() ([]*model.ClusterInstallation, error)

GetUnlockedClusterInstallationsPendingWork returns an unlocked cluster installation in a pending state.

func (*SQLStore) GetUnlockedClustersPendingWork

func (sqlStore *SQLStore) GetUnlockedClustersPendingWork() ([]*model.Cluster, error)

GetUnlockedClustersPendingWork returns an unlocked cluster in a pending state.

func (*SQLStore) GetUnlockedGroupsPendingWork added in v0.17.0

func (sqlStore *SQLStore) GetUnlockedGroupsPendingWork() ([]*model.Group, error)

GetUnlockedGroupsPendingWork returns unlocked groups that have installations that require configuration reconciliation.

func (*SQLStore) GetUnlockedInstallationsPendingWork

func (sqlStore *SQLStore) GetUnlockedInstallationsPendingWork() ([]*model.Installation, error)

GetUnlockedInstallationsPendingWork returns an unlocked installation in a pending state.

func (*SQLStore) GetWebhook added in v0.3.0

func (sqlStore *SQLStore) GetWebhook(id string) (*model.Webhook, error)

GetWebhook fetches the given webhook by id.

func (*SQLStore) GetWebhooks added in v0.3.0

func (sqlStore *SQLStore) GetWebhooks(filter *model.WebhookFilter) ([]*model.Webhook, error)

GetWebhooks fetches the given page of created webhooks. The first page is 0.

func (*SQLStore) LockCluster

func (sqlStore *SQLStore) LockCluster(clusterID, lockerID string) (bool, error)

LockCluster marks the cluster as locked for exclusive use by the caller.

func (*SQLStore) LockClusterAPI added in v0.25.0

func (sqlStore *SQLStore) LockClusterAPI(clusterID string) error

LockClusterAPI locks updates to the cluster from the API.

func (*SQLStore) LockClusterInstallationAPI added in v0.25.0

func (sqlStore *SQLStore) LockClusterInstallationAPI(id string) error

LockClusterInstallationAPI locks updates to the cluster installation from the API.

func (*SQLStore) LockClusterInstallations

func (sqlStore *SQLStore) LockClusterInstallations(clusterInstallationIDs []string, lockerID string) (bool, error)

LockClusterInstallations marks the cluster installation as locked for exclusive use by the caller.

func (*SQLStore) LockGroup added in v0.17.0

func (sqlStore *SQLStore) LockGroup(groupID, lockerID string) (bool, error)

LockGroup marks the group as locked for exclusive use by the caller.

func (*SQLStore) LockGroupAPI added in v0.25.0

func (sqlStore *SQLStore) LockGroupAPI(id string) error

LockGroupAPI locks updates to the group from the API.

func (*SQLStore) LockInstallation

func (sqlStore *SQLStore) LockInstallation(installationID, lockerID string) (bool, error)

LockInstallation marks the installation as locked for exclusive use by the caller.

func (*SQLStore) LockInstallationAPI added in v0.25.0

func (sqlStore *SQLStore) LockInstallationAPI(installationID string) error

LockInstallationAPI locks updates to the installation from the API.

func (*SQLStore) LockMultitenantDatabase added in v0.19.0

func (sqlStore *SQLStore) LockMultitenantDatabase(multitenantDatabaseID, lockerID string) (bool, error)

LockMultitenantDatabase marks the database cluster as locked for exclusive use by the caller.

func (*SQLStore) Migrate

func (sqlStore *SQLStore) Migrate() error

Migrate advances the schema of the configured database to the latest version.

func (*SQLStore) UnlockCluster

func (sqlStore *SQLStore) UnlockCluster(clusterID, lockerID string, force bool) (bool, error)

UnlockCluster releases a lock previously acquired against a caller.

func (*SQLStore) UnlockClusterAPI added in v0.25.0

func (sqlStore *SQLStore) UnlockClusterAPI(clusterID string) error

UnlockClusterAPI unlocks updates to the cluster from the API.

func (*SQLStore) UnlockClusterInstallationAPI added in v0.25.0

func (sqlStore *SQLStore) UnlockClusterInstallationAPI(id string) error

UnlockClusterInstallationAPI unlocks updates to the cluster installation from the API.

func (*SQLStore) UnlockClusterInstallations

func (sqlStore *SQLStore) UnlockClusterInstallations(clusterInstallationIDs []string, lockerID string, force bool) (bool, error)

UnlockClusterInstallations releases a lock previously acquired against a caller.

func (*SQLStore) UnlockGroup added in v0.17.0

func (sqlStore *SQLStore) UnlockGroup(groupID, lockerID string, force bool) (bool, error)

UnlockGroup releases a lock previously acquired against a caller.

func (*SQLStore) UnlockGroupAPI added in v0.25.0

func (sqlStore *SQLStore) UnlockGroupAPI(id string) error

UnlockGroupAPI unlocks updates to the group from the API.

func (*SQLStore) UnlockInstallation

func (sqlStore *SQLStore) UnlockInstallation(installationID, lockerID string, force bool) (bool, error)

UnlockInstallation releases a lock previously acquired against a caller.

func (*SQLStore) UnlockInstallationAPI added in v0.25.0

func (sqlStore *SQLStore) UnlockInstallationAPI(installationID string) error

UnlockInstallationAPI unlocks updates to the installation from the API.

func (*SQLStore) UnlockMultitenantDatabase added in v0.19.0

func (sqlStore *SQLStore) UnlockMultitenantDatabase(multitenantDatabaseID, lockerID string, force bool) (bool, error)

UnlockMultitenantDatabase releases a lock previously acquired against a caller.

func (*SQLStore) UpdateCluster

func (sqlStore *SQLStore) UpdateCluster(cluster *model.Cluster) error

UpdateCluster updates the given cluster in the database.

func (*SQLStore) UpdateClusterInstallation

func (sqlStore *SQLStore) UpdateClusterInstallation(clusterInstallation *model.ClusterInstallation) error

UpdateClusterInstallation updates the given cluster installation in the database.

func (*SQLStore) UpdateGroup

func (sqlStore *SQLStore) UpdateGroup(group *model.Group) error

UpdateGroup updates the given group in the database. If a value was updated that will possibly affect installation config then update the group sequence number.

func (*SQLStore) UpdateInstallation

func (sqlStore *SQLStore) UpdateInstallation(installation *model.Installation) error

UpdateInstallation updates the given installation in the database.

func (*SQLStore) UpdateInstallationGroupSequence added in v0.18.0

func (sqlStore *SQLStore) UpdateInstallationGroupSequence(installation *model.Installation) error

UpdateInstallationGroupSequence updates the given installation GroupSequence to the value stored in the merged group config. The provided installation must have been merged with group config before passing it in.

func (*SQLStore) UpdateInstallationState added in v0.18.0

func (sqlStore *SQLStore) UpdateInstallationState(installation *model.Installation) error

UpdateInstallationState updates the given installation to a new state.

func (*SQLStore) UpdateMultitenantDatabase added in v0.19.0

func (sqlStore *SQLStore) UpdateMultitenantDatabase(multitenantDatabase *model.MultitenantDatabase) error

UpdateMultitenantDatabase updates a already existent multitenant database in the datastore.

type Transaction added in v0.31.0

type Transaction struct {
	*sqlx.Tx
	// contains filtered or unexported fields
}

Transaction is a wrapper around *sqlx.Tx providing convenience methods.

func (*Transaction) Commit added in v0.31.0

func (t *Transaction) Commit() error

Commit commits the pending transaction.

func (*Transaction) RollbackUnlessCommitted added in v0.31.0

func (t *Transaction) RollbackUnlessCommitted()

RollbackUnlessCommitted rollback the transaction if it is not committed.

Jump to

Keyboard shortcuts

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