models

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: Apache-2.0 Imports: 18 Imported by: 8

Documentation

Overview

Package models contains internal models 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 == types.Create }
	UpdateChangeStepFilter   = func(c *ChangeStep) bool { return c.Action == types.Update }
	DeleteChangeStepFilter   = func(c *ChangeStep) bool { return c.Action == types.Delete }
	UnChangeChangeStepFilter = func(c *ChangeStep) bool { return c.Action == types.UnChange }
)

Functions

This section is empty.

Types

type ChangeOrder

type ChangeOrder struct {
	StepKeys    []string
	ChangeSteps map[string]*ChangeStep
}

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 {
	ID     string           // the resource id
	Action types.ActionType // the operation performed by this step.
	From   interface{}      // old data
	To     interface{}      // new data
}

func NewChangeStep

func NewChangeStep(id string, op types.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
	// contains filtered or unexported fields
}

func NewChanges

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

func (*Changes) AllUnChange added in v0.6.2

func (p *Changes) AllUnChange() bool

func (*Changes) Project

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

func (*Changes) Stack

func (p *Changes) Stack() *projectstack.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 types.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]*models.Resource

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

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

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

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

	// Runtime is the resource infrastructure runtime of this operation
	Runtime runtime.Runtime

	// 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 *models.Resource, actionType types.ActionType) error

RefreshResourceIndex refresh resources in CtxResourceIndex & StateResourceIndex

func (*Operation) UpdateState

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

type Request

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

Jump to

Keyboard shortcuts

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