models

package
v0.9.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 19 Imported by: 8

Documentation

Overview

Package models contains internal structs of operations todo CLI imports this package directly. We need to make this pkg internal

Index

Constants

This section is empty.

Variables

View Source
var (
	CreateChangeStepFilter   = func(c *ChangeStep) bool { return c.Action == Create }
	UpdateChangeStepFilter   = func(c *ChangeStep) bool { return c.Action == Update }
	DeleteChangeStepFilter   = func(c *ChangeStep) bool { return c.Action == Delete }
	UnChangeChangeStepFilter = func(c *ChangeStep) bool { return c.Action == UnChanged }
)

Functions

This section is empty.

Types

type ActionType added in v0.7.3

type ActionType int64

ActionType represents the kind of operation performed by a plan. It evaluates to its string label.

const (
	Undefined ActionType = iota // invalidate value
	UnChanged                   // nothing to do.
	Create                      // creating a new resource.
	Update                      // updating an existing resource.
	Delete                      // deleting an existing resource.
)

ActionType values

func (ActionType) Ing added in v0.7.3

func (t ActionType) Ing() string

func (ActionType) MarshalJSON added in v0.8.1

func (t ActionType) MarshalJSON() ([]byte, error)

func (ActionType) PrettyString added in v0.7.3

func (t ActionType) PrettyString() string

func (ActionType) String added in v0.7.3

func (t ActionType) String() string

type ChangeOrder

type ChangeOrder struct {
	StepKeys    []string               `json:"stepKeys,omitempty" yaml:"stepKeys,omitempty"`
	ChangeSteps map[string]*ChangeStep `json:"changeSteps,omitempty" yaml:"changeSteps,omitempty"`
}

func (*ChangeOrder) Diffs

func (o *ChangeOrder) Diffs() string

func (*ChangeOrder) Get

func (o *ChangeOrder) Get(key string) *ChangeStep

func (*ChangeOrder) OutputDiff

func (o *ChangeOrder) OutputDiff(target string)

func (*ChangeOrder) PromptDetails

func (o *ChangeOrder) PromptDetails() (string, error)

func (*ChangeOrder) Values

func (o *ChangeOrder) Values(filters ...ChangeStepFilterFunc) []*ChangeStep

type ChangeStep

type ChangeStep struct {
	// the resource id
	ID string `json:"id,omitempty" yaml:"id,omitempty"`
	// the operation performed by this step
	Action ActionType `json:"action,omitempty" yaml:"action,omitempty"`
	// old data
	From interface{} `json:"from,omitempty" yaml:"from,omitempty"`
	// new data
	To interface{} `json:"to,omitempty" yaml:"to,omitempty"`
}

func NewChangeStep

func NewChangeStep(id string, op ActionType, from, to interface{}) *ChangeStep

func (*ChangeStep) Diff

func (cs *ChangeStep) Diff() (string, error)

Diff compares objects(from and to) which stores in ChangeStep, and return a human-readable string report.

type ChangeStepFilterFunc

type ChangeStepFilterFunc func(*ChangeStep) bool

type Changes

type Changes struct {
	*ChangeOrder `json:",inline" yaml:",inline"`
	// contains filtered or unexported fields
}

func NewChanges

func NewChanges(p *project.Project, s *stack.Stack, order *ChangeOrder) *Changes

func (*Changes) AllUnChange added in v0.6.2

func (p *Changes) AllUnChange() bool

func (*Changes) Project

func (p *Changes) Project() *project.Project

func (*Changes) Stack

func (p *Changes) Stack() *stack.Stack

func (*Changes) Summary

func (p *Changes) Summary(writer io.Writer)

type Message

type Message struct {
	ResourceID string   // ResourceNode.ID()
	OpResult   OpResult // Success/Failed/Skip
	OpErr      error    // Operate error detail
}

type OpResult

type OpResult string
const (
	Success OpResult = "Success"
	Failed  OpResult = "Failed"
	Skip    OpResult = "Skip"
)

OpResult values

type Operation

type Operation struct {
	// OperationType represents the OperationType of this operation
	OperationType OperationType

	// StateStorage represents the storage where state will be saved during this operation
	StateStorage states.StateStorage

	// CtxResourceIndex represents resources updated by this operation
	CtxResourceIndex map[string]*intent.Resource

	// PriorStateResourceIndex represents resource state saved during the last operation
	PriorStateResourceIndex map[string]*intent.Resource

	// StateResourceIndex represents resources that will be saved in states.StateStorage
	StateResourceIndex map[string]*intent.Resource

	// IgnoreFields will be ignored in preview stage
	IgnoreFields []string

	// ChangeOrder is resources' change order during this operation
	ChangeOrder *ChangeOrder

	// RuntimeMap contains all infrastructure runtimes involved this operation. The key of this map is the Runtime type
	RuntimeMap map[intent.Type]runtime.Runtime

	// Stack contains info about where this command is invoked
	Stack *stack.Stack

	// MsgCh is used to send operation status like Success, Failed or Skip to Kusion CTl,
	// and this message will be displayed in the terminal
	MsgCh chan Message

	// Lock is the operation-wide mutex
	Lock *sync.Mutex

	// ResultState is the final State build by this operation, and this State will be saved in the StateStorage
	ResultState *states.State
}

Operation is the base model for all operations

func (*Operation) InitStates

func (o *Operation) InitStates(request *Request) (*states.State, *states.State)

func (*Operation) RefreshResourceIndex

func (o *Operation) RefreshResourceIndex(resourceKey string, resource *intent.Resource, actionType ActionType) error

RefreshResourceIndex refresh resources in CtxResourceIndex & StateResourceIndex

func (*Operation) UpdateState

func (o *Operation) UpdateState(resourceIndex map[string]*intent.Resource) error

type OperationType added in v0.7.3

type OperationType int64
const (
	UndefinedOperation OperationType = iota // invalidate value
	Apply
	ApplyPreview
	Destroy
	DestroyPreview
)

Operation type

type Request

type Request struct {
	Tenant   string           `json:"tenant"`
	Project  *project.Project `json:"project"`
	Stack    *stack.Stack     `json:"stack"`
	Cluster  string           `json:"cluster"`
	Operator string           `json:"operator"`
	Intent   *intent.Intent   `json:"intent"`
}

Jump to

Keyboard shortcuts

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