states

package
v0.4.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

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 Mode

type Mode string
const (
	Managed Mode = "managed"
	Drifted Mode = "drifted"
)

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) Delete

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

func (*OssState) GetLatestState

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

type ResourceState

type ResourceState struct {
	// ID is the unique key of this resource in the whole State. ApiVersion/Kind/Namespace/Name is an idiomatic way of Kubernetes resources.
	ID         string                 `json:"id"`
	Mode       Mode                   `json:"mode"`
	Attributes map[string]interface{} `json:"attributes"`
	DependsOn  []string               `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
}

func (*ResourceState) ResourceKey

func (r *ResourceState) ResourceKey() string

type Resources

type Resources []ResourceState

func (Resources) Index

func (rs Resources) Index() map[string]*ResourceState

func (Resources) Len

func (rs Resources) Len() int

func (Resources) Less

func (rs Resources) Less(i, j int) bool

func (Resources) Swap

func (rs Resources) Swap(i, j int)

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) Delete

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

func (*S3State) GetLatestState

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

type State

type State struct {
	ID            int64     `json:"id"`
	Tenant        string    `json:"tenant"`
	Stack         string    `json:"stack"`
	Project       string    `json:"project"`
	Version       int       `json:"version"`
	KusionVersion string    `json:"kusionVersion"`
	Serial        uint64    `json:"serial"`
	Operator      string    `json:"operator"`
	Resources     Resources `json:"resources"`
	CreatTime     time.Time `json:"creatTime"`
	ModifiedTime  time.Time `json:"modifiedTime,omitempty"`
}

State represent all resources state in one apply operation.

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(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