operation

package
v0.4.1-debug.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Apache-2.0 Imports: 30 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ImplicitRefPrefix = "$kusion_path."
)

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 == UnChange }
)
View Source
var ImplicitReplaceFun = func(resourceIndex map[string]*states.ResourceState, refPath string) (reflect.Value, status.Status) {
	const Sep = "."
	split := strings.Split(refPath, Sep)
	key := split[0]
	priorState := resourceIndex[key]
	if priorState == nil {
		msg := fmt.Sprintf("can't find state by key:%s when replacing %s", key, refPath)
		return reflect.Value{}, status.NewErrorStatusWithMsg(status.IllegalManifest, msg)
	}
	attributes := priorState.Attributes
	if attributes == nil {
		msg := fmt.Sprintf("attributes is nil in resource:%s", key)
		return reflect.Value{}, status.NewErrorStatusWithMsg(status.IllegalManifest, msg)
	}
	var valueMap interface{}
	valueMap = attributes
	if len(split) > 1 {
		split := split[1:]
		for _, k := range split {
			if valueMap.(map[string]interface{})[k] == nil {
				msg := fmt.Sprintf("can't find specified value in resource:%s by ref:%s", key, refPath)
				return reflect.Value{}, status.NewErrorStatusWithMsg(status.IllegalManifest, msg)
			}
			valueMap = valueMap.(map[string]interface{})[k]
		}
	}
	return reflect.ValueOf(valueMap), nil
}

Functions

func Deduplicate

func Deduplicate(refNodeKeys []string) []string

func DiffReport

func DiffReport(prior, plan, mode string) (string, error)

func DiffWithRequestResourceAndState

func DiffWithRequestResourceAndState(plan *manifest.Manifest, latest *states.State) (string, error)

func GetVertex

func GetVertex(g *dag.AcyclicGraph, nv dag.NamedVertex) interface{}

func LinkRefNodes

func LinkRefNodes(graph *dag.AcyclicGraph, refNodeKeys []string, resourceIndex map[string]*states.ResourceState,
	rn dag.Vertex, defaultAction ActionType, manifestGraphMap map[string]interface{}) status.Status

func LoadFile

func LoadFile(yaml, location string) (ytbx.InputFile, error)

LoadFile processes the provided input location to load it as one of the supported document formats, or plain text if nothing else works.

func NewApplyGraph

func NewApplyGraph(m *manifest.Manifest, priorState *states.State) (*dag.AcyclicGraph, status.Status)

func NewDestroyGraph

func NewDestroyGraph(resource states.Resources) (*dag.AcyclicGraph, status.Status)

func ParseImplicitRef

func ParseImplicitRef(v reflect.Value, resourceIndex map[string]*states.ResourceState,
	replaceFun func(resourceIndex map[string]*states.ResourceState, refPath string) (reflect.Value, status.Status),
) ([]string, reflect.Value, status.Status)

Types

type ActionType

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
	UnChange                    // nothing to do.
	Create                      // creating a new resource.
	Update                      // updating an existing resource.
	Delete                      // deleting an existing resource.
)

ActionType values

func (ActionType) Ing

func (t ActionType) Ing() string

func (ActionType) PrettyString

func (t ActionType) PrettyString() string

func (ActionType) String

func (t ActionType) String() string

type ApplyOperation

type ApplyOperation struct {
	Operation
}

type ApplyRequest

type ApplyRequest struct {
	Request `json:",inline" yaml:",inline"`
}

type ApplyResponse

type ApplyResponse struct {
	State *states.State
}

type BaseNode

type BaseNode struct {
	ID string
}

func (*BaseNode) Hashcode

func (b *BaseNode) Hashcode() interface{}

func (*BaseNode) Name

func (b *BaseNode) Name() string

type ChangeStep

type ChangeStep struct {
	ID     string      // the resource id
	Action ActionType  // the operation performed by this step.
	Old    interface{} // the state of the resource before performing this step.
	New    interface{} // the state of the resource after performing this step.
}

func NewChangeStep

func NewChangeStep(id string, op ActionType, oldData, newData interface{}) *ChangeStep

func (*ChangeStep) Diff

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

type ChangeStepFilterFunc

type ChangeStepFilterFunc func(*ChangeStep) bool

type Changes

type Changes struct {
	ChangeSteps map[string]*ChangeStep
	// contains filtered or unexported fields
}

func NewChanges

func NewChanges(p *projectstack.Project, s *projectstack.Stack, steps map[string]*ChangeStep) *Changes

func (*Changes) Diffs

func (p *Changes) Diffs() string

func (*Changes) Get

func (p *Changes) Get(key string) *ChangeStep

func (*Changes) OutputDiff

func (p *Changes) OutputDiff(target string)

func (*Changes) Project

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

func (*Changes) PromptDetails

func (p *Changes) PromptDetails() (string, error)

func (*Changes) Stack

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

func (*Changes) Summary

func (p *Changes) Summary()

func (*Changes) Values

func (p *Changes) Values(filters ...ChangeStepFilterFunc) []*ChangeStep

type DeleteResourceParser

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

func NewDeleteResourceParser

func NewDeleteResourceParser(resources states.Resources) *DeleteResourceParser

func (*DeleteResourceParser) Parse

func (d *DeleteResourceParser) Parse(graph *dag.AcyclicGraph) (s status.Status)

type DestroyOperation

type DestroyOperation struct {
	Operation
}

type DestroyRequest

type DestroyRequest struct {
	Request `json:",inline" yaml:",inline"`
}

type Diff

type Diff struct {
	StateStorage states.StateStorage
}

func (*Diff) Diff

func (d *Diff) Diff(request *DiffRequest) (string, error)

type DiffRequest

type DiffRequest struct {
	Request
}

type ExecutableNode

type ExecutableNode interface {
	Execute(operation Operation) status.Status
}

type ManifestParser

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

func NewManifestParser

func NewManifestParser(manifest *manifest.Manifest) *ManifestParser

func (*ManifestParser) Parse

func (m *ManifestParser) Parse(graph *dag.AcyclicGraph) (s status.Status)

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 Type
	StateStorage  states.StateStorage
	// CtxResourceIndex represents resources updated by func apply
	CtxResourceIndex map[string]*states.ResourceState
	// PriorStateResourceIndex represents prior states.StateStorage state
	PriorStateResourceIndex map[string]*states.ResourceState
	// StateResourceIndex represents resources that will be saved in states.StateStorage
	StateResourceIndex map[string]*states.ResourceState
	ChangeStepMap      map[string]*ChangeStep
	Runtime            runtime.Runtime
	MsgCh              chan Message
	// contains filtered or unexported fields
}

func (*Operation) Apply

func (o *Operation) Apply(request *ApplyRequest) (rsp *ApplyResponse, st status.Status)

func (*Operation) Destroy

func (o *Operation) Destroy(request *DestroyRequest) (st status.Status)

func (*Operation) Preview

func (o *Operation) Preview(request *PreviewRequest, operation Type) (rsp *PreviewResponse, s status.Status)

func (*Operation) RefreshResourceIndex

func (o *Operation) RefreshResourceIndex(resourceKey string, resource *states.ResourceState, actionType ActionType) error

RefreshResourceIndex refresh resources in CtxResourceIndex & StateResourceIndex

func (*Operation) UpdateState

func (o *Operation) UpdateState(resourceIndex map[string]*states.ResourceState) error

type Parser

type Parser interface {
	Parse(dag *dag.AcyclicGraph) status.Status
}

type PreviewOperation

type PreviewOperation struct {
	Operation
}

type PreviewRequest

type PreviewRequest struct {
	Request `json:",inline" yaml:",inline"`
}

type PreviewResponse

type PreviewResponse struct {
	ChangeSteps map[string]*ChangeStep
}

type Request

type Request struct {
	Tenant   string             `json:"tenant"`
	Stack    string             `json:"stack"`
	Project  string             `json:"project"`
	Operator string             `json:"operator"`
	Manifest *manifest.Manifest `json:"manifest"`
}

type ResourceNode

type ResourceNode struct {
	BaseNode
	Action ActionType
	// contains filtered or unexported fields
}

func NewResourceNode

func NewResourceNode(key string, state *states.ResourceState, action ActionType) *ResourceNode

func (*ResourceNode) Execute

func (rn *ResourceNode) Execute(operation Operation) status.Status

func (*ResourceNode) State

func (rn *ResourceNode) State() *states.ResourceState

type RootNode

type RootNode struct{}

func (*RootNode) Hashcode

func (r *RootNode) Hashcode() interface{}

func (*RootNode) Name

func (r *RootNode) Name() string

type Type

type Type int64
const (
	UndefinedOperation Type = iota // invalidate value
	Apply
	Preview
	Destroy
)

Operation type

Jump to

Keyboard shortcuts

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