Help us shape the future of Go! Take the 2026 Go Developer Survey

statemachine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ObjectLockIns = KubeObjectLock{}

Functions

This section is empty.

Types

type AnonymousStateMainEnter

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

func (*AnonymousStateMainEnter) GetName

func (e *AnonymousStateMainEnter) GetName() string

func (*AnonymousStateMainEnter) MainEnter

func (e *AnonymousStateMainEnter) MainEnter(obj StateResource) error

type Event

type Event struct {
	Name   EventName
	Params map[string]interface{}
}

func CreateEvent

func CreateEvent(name EventName, params map[string]interface{}) *Event

type EventChecker

type EventChecker func(resource StateResource) (*Event, error)

type EventName

type EventName string

type KubeObjectLock

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

func (*KubeObjectLock) GetLock

func (dl *KubeObjectLock) GetLock(obj StateResource) *sync.Mutex

type StableStateMainEnter

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

稳定状态,一直在等待event触发自身状态发生变化,除此以外,不做任何动作

func (*StableStateMainEnter) GetName

func (ss *StableStateMainEnter) GetName() string

func (*StableStateMainEnter) MainEnter

func (ss *StableStateMainEnter) MainEnter(obj StateResource) error

type State

type State string
const (
	StateRunning   State = "Running"
	StateCreating  State = "Creating"
	StateInit      State = "Init"
	StateInterrupt State = "Interrupt"
	StateRebuild   State = "Rebuild"
	StateNil       State = ""
)

type StateMachine

type StateMachine struct {
	Logger       logr.Logger
	ResourceType string
	// contains filtered or unexported fields
}

func CreateStateMachineInstance

func CreateStateMachineInstance(resourceType string) *StateMachine

func (*StateMachine) CheckSetStateTranslate

func (sm *StateMachine) CheckSetStateTranslate(nowState State, obj StateResource) (State, error)

检查当前状态下是否有需要transfer的事件发生. 如果发现 state change, 设置变更后的状态.

func (*StateMachine) DoStateMainEnter

func (sm *StateMachine) DoStateMainEnter(obj StateResource) error

func (*StateMachine) RegisterIgnoreEvents

func (sm *StateMachine) RegisterIgnoreEvents(ignoreEvents []string) *StateMachine

func (*StateMachine) RegisterLogger

func (sm *StateMachine) RegisterLogger(logger logr.Logger) *StateMachine

func (*StateMachine) RegisterStableState

func (sm *StateMachine) RegisterStableState(states ...State)

注册稳定状态, 等待有事件触发,离开当前状态.

func (*StateMachine) RegisterStateMainEnter

func (sm *StateMachine) RegisterStateMainEnter(state State, action func(obj StateResource) error)

注册资源进入某非稳定状态要执行的动作

func (*StateMachine) RegisterStateTranslate

func (sm *StateMachine) RegisterStateTranslate(beforeState State, eventChecker EventChecker, afterState State)

资源处于稳定状态(beforeState),通过eventCheckFunc检查是否发生了更新,发生更新则触发事件,并将资源状态变为非稳定态(afterState) 非稳定态都通过RegisterStateMainEnter注册了入口方法

func (*StateMachine) RegisterStateTranslateMainEnter

func (sm *StateMachine) RegisterStateTranslateMainEnter(beforeState State, eventChecker EventChecker, afterState State, action func(obj StateResource) error)

type StateMainEnter

type StateMainEnter interface {
	MainEnter(obj StateResource) error
	GetName() string
}

type StateResource

type StateResource interface {
	GetName() string
	GetNamespace() string
	Fetch() (StateResource, error)
	GetState() State
	UpdateState(State) (StateResource, error)
	IsCancelled() bool
}

支持状态机的资源

Jump to

Keyboard shortcuts

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