states

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package states contains code for all storage medium supported by Kusion.

Index

Constants

View Source
const KusionState = "kusion_state.json"

Variables

View Source
var Backends = make(map[string]func() StateStorage)
View Source
var ErrOSSNoExist = errors.New("oss: key not exist")
View Source
var ErrS3NoExist = errors.New("s3: key not exist")

Functions

func AddToBackends

func AddToBackends(name string, storage func() StateStorage)

Types

type DBState

type DBState struct {
	DB *sql.DB
}

func (*DBState) Apply

func (s *DBState) Apply(state *State) error

Apply save state in DB by add-only strategy.

func (*DBState) ConfigSchema

func (s *DBState) ConfigSchema() cty.Type

func (*DBState) Configure

func (s *DBState) Configure(obj cty.Value) error

func (*DBState) Delete

func (s *DBState) Delete(id string) error

func (*DBState) GetLatestState

func (s *DBState) GetLatestState(q *StateQuery) (*State, error)

type FileSystemState

type FileSystemState struct {
	// state Path is in the same dir where command line is invoked
	Path string
}

func (*FileSystemState) Apply

func (f *FileSystemState) Apply(state *State) error

func (*FileSystemState) ConfigSchema

func (f *FileSystemState) ConfigSchema() cty.Type

func (*FileSystemState) Configure

func (f *FileSystemState) Configure(obj cty.Value) error

func (*FileSystemState) Delete

func (f *FileSystemState) Delete(id string) error

func (*FileSystemState) GetLatestState

func (f *FileSystemState) GetLatestState(query *StateQuery) (*State, error)

type OssState

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

func NewOSSState

func NewOSSState(endPoint, accessKeyID, accessKeySecret, bucketName string) (*OssState, error)

func (*OssState) Apply

func (s *OssState) Apply(state *State) error

func (*OssState) ConfigSchema added in v0.4.4

func (s *OssState) ConfigSchema() cty.Type

ConfigSchema returns a description of the expected configuration structure for the receiving backend.

func (*OssState) Configure added in v0.4.4

func (s *OssState) Configure(obj cty.Value) error

Configure uses the provided configuration to set configuration fields within the OssState backend.

func (*OssState) Delete

func (s *OssState) Delete(id string) error

func (*OssState) GetLatestState

func (s *OssState) GetLatestState(query *StateQuery) (*State, error)

type S3State

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

func NewS3State

func NewS3State(endPoint, accessKeyID, accessKeySecret, bucketName string, region string) (*S3State, error)

func (*S3State) Apply

func (s *S3State) Apply(state *State) error

func (*S3State) ConfigSchema added in v0.4.4

func (s *S3State) ConfigSchema() cty.Type

ConfigSchema returns a description of the expected configuration structure for the receiving backend.

func (*S3State) Configure added in v0.4.4

func (s *S3State) Configure(obj cty.Value) error

Configure uses the provided configuration to set configuration fields within the S3State backend.

func (*S3State) Delete

func (s *S3State) Delete(id string) error

func (*S3State) GetLatestState

func (s *S3State) GetLatestState(query *StateQuery) (*State, error)

type State

type State struct {
	// State ID
	ID int64 `json:"id"`
	// Tenant is designed for multi-tenant scenario
	Tenant string `json:"tenant,omitempty"`
	// Stack name
	Stack string `json:"stack"`
	// Project name
	Project string `json:"project"`
	// State version
	Version int `json:"version"`
	// KusionVersion represents the Kusion's version when this State is created
	KusionVersion string `json:"kusionVersion"`
	// Serial is an auto-increase number that represents how many times this State is modified
	Serial uint64 `json:"serial"`
	// Operator represents the person who triggered this operation
	Operator string `json:"operator,omitempty"`
	// Resources records all resources in this operation
	Resources models.Resources `json:"resources"`
	// CreatTime is the time State is created
	CreatTime time.Time `json:"creatTime"`
	// ModifiedTime is the time State is modified each time
	ModifiedTime time.Time `json:"modifiedTime,omitempty"`
}

State is a record of an operation's result. It is a mapping between resources in KCL and the actual infra resource and often used as a datasource for 3-way merge/diff in operations like Apply or Preview.

func NewState

func NewState() *State

type StateQuery

type StateQuery struct {
	Tenant  string `json:"tenant"`
	Stack   string `json:"stack"`
	Project string `json:"project"`
}

type StateStorage

type StateStorage interface {
	// ConfigSchema returns a description of the expected configuration
	// structure for the receiving backend.
	ConfigSchema() cty.Type
	// Configure uses the provided configuration to set configuration fields
	// within the backend.
	Configure(obj cty.Value) error
	// GetLatestState return nil if state not exists
	GetLatestState(query *StateQuery) (*State, error)
	// Apply means update this state if it already exists or create a new one
	Apply(state *State) error
	// Delete State by id
	Delete(id string) error
}

StateStorage represents the set of methods required for a State backend

func NewDBState

func NewDBState() StateStorage

func NewFileSystemState

func NewFileSystemState() StateStorage

Jump to

Keyboard shortcuts

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