action

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ItemErrEmpty     = "empty parameter"
	ItemErrOperation = "failed to generate operations"
	ItemErrScript    = "invalid script"

	ItemHelperEmpty     = "please input suitable check item"
	ItemHelperOperation = "please check your operations"
	ItemHelperScript    = "please check your script"

	CheckPassed = "check passed"
	CheckFailed = "check failed"
)

constant value for check

View Source
const (
	InitPassed = "init passed"
	InitFailed = "init failed"
)

Variables

This section is empty.

Functions

func CheckCPUExecutor

func CheckCPUExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check CPU

func CheckDistributionExecutor

func CheckDistributionExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check distribution

func CheckDockerExecutor

func CheckDockerExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check docker

func CheckKernelExecutor

func CheckKernelExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check kernel

func CheckMemoryExecutor

func CheckMemoryExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check memory

func CheckPortOccupiedExecutor

func CheckPortOccupiedExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for port occupied check

func CheckRootDiskExecutor

func CheckRootDiskExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check disk

func CheckSysManagerExecutor

func CheckSysManagerExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check system manager

func CheckSysPrefExecutor

func CheckSysPrefExecutor(ncAction *NodeCheckAction, wg *sync.WaitGroup)

goroutine as executor for check system preference

func ExecuteAction

func ExecuteAction(act Action, wg *sync.WaitGroup)

ExecuteAction creates and run the executor for an action, a *sync.WaitGroup should be passed in.

func GenActionLogFilePath

func GenActionLogFilePath(basePath, actionName string, nodeName string) string

GenActionLogFilePath is a helper to return a file path based on the base path and aciton name

func GenActionName

func GenActionName(actionType Type) string

GenActionName generates a unique action name with the action type as prefix.

func InitAsyncExecutor

func InitAsyncExecutor(item it.ItemEnum, ncAction *NodeInitAction, wg *sync.WaitGroup)

goroutine exec item init event

func RegisterExecutor

func RegisterExecutor(actionType Type, exec Executor) error

RegisterExecutor is to register an Executor for an action type

func UpdateInitItems

func UpdateInitItems(initAction *NodeInitAction, report *NodeInitItem)

update init items with matching name

Types

type Action

type Action interface {
	GetName() string
	GetStatus() Status
	SetStatus(Status)
	GetType() Type
	GetErr() *pb.Error
	SetErr(*pb.Error)
	GetLogFilePath() string
	SetLogFilePath(string)
	GetCreationTimestamp() time.Time
	GetNode() *pb.Node
	GetExecuteLogBuffer() io.ReadWriter
	SetExecuteLogBuffer(io.ReadWriter)
}

Action repsents the definition of executable command(s) in a node, multiple actions can be executed concurrently.

func NewConnectivityCheckAction

func NewConnectivityCheckAction(cfg *ConnectivityCheckActionConfig) (Action, error)

NewConnectivityCheckAction creates an action to check connectivity from soruce to destination.

func NewDeployEtcdAction

func NewDeployEtcdAction(cfg *DeployEtcdActionConfig) (Action, error)

NewDeployEtcdAction returns a deploy etcd action based on the config. User should use this function to create a deploy etcd action.

func NewDeployWorkerAction

func NewDeployWorkerAction(config *DeployWorkerActionConfig) (Action, error)

func NewFetchKubeConfigAction

func NewFetchKubeConfigAction(cfg *FetchKubeConfigActionConfig) (Action, error)

NewFetchKubeConfigAction returns a fetch-kube-config action based on the config. User should use this function to create a fetch-kube-config action.

func NewInitMasterAction

func NewInitMasterAction(cfg *InitMasterActionConfig) (Action, error)

func NewJoinMasterAction

func NewJoinMasterAction(cfg *JoinMasterActionConfig) (Action, error)

func NewNodeCheckAction

func NewNodeCheckAction(cfg *NodeCheckActionConfig) (Action, error)

NewNodeCheckAction returns a node check action based on the config. User should use this function to create a node check action.

func NewNodeInitAction

func NewNodeInitAction(cfg *NodeInitActionConfig) (Action, error)

NewNodeInitAction returns a node init action based on the config. User should use this function to create a node init action.

func NewTestConnectionAction

func NewTestConnectionAction(cfg *TestConnectionActionConfig) (Action, error)

NewTestConnectionAction returns a test-connection action based on the config. User should use this function to create a test-connection action.

type Base

type Base struct {
	Name              string
	ActionType        Type
	Status            Status
	Err               *pb.Error
	LogFilePath       string
	CreationTimestamp time.Time
	Node              *pb.Node
	ExecuteLogBuffer  io.ReadWriter
}

Base is the basic metadata of an action

func (*Base) GetCreationTimestamp

func (b *Base) GetCreationTimestamp() time.Time

func (*Base) GetErr

func (b *Base) GetErr() *pb.Error

func (*Base) GetExecuteLogBuffer

func (b *Base) GetExecuteLogBuffer() io.ReadWriter

func (*Base) GetLogFilePath

func (b *Base) GetLogFilePath() string

func (*Base) GetName

func (b *Base) GetName() string

func (*Base) GetNode

func (b *Base) GetNode() *pb.Node

func (*Base) GetStatus

func (b *Base) GetStatus() Status

func (*Base) GetType

func (b *Base) GetType() Type

func (*Base) SetErr

func (b *Base) SetErr(err *pb.Error)

func (*Base) SetExecuteLogBuffer

func (b *Base) SetExecuteLogBuffer(buf io.ReadWriter)

func (*Base) SetLogFilePath

func (b *Base) SetLogFilePath(path string)

func (*Base) SetStatus

func (b *Base) SetStatus(status Status)

type ConnectivityCheckAction

type ConnectivityCheckAction struct {
	Base

	SourceNode      *pb.Node
	DestinationNode *pb.Node
	CheckItems      []ConnectivityCheckItem
}

type ConnectivityCheckActionConfig

type ConnectivityCheckActionConfig struct {
	SourceNode             *pb.Node
	DestinationNode        *pb.Node
	ConnectivityCheckItems []ConnectivityCheckItem
	LogFileBasePath        string
}

ConnectivityCheckActionConfig configuration of checking connectivity from soruce to destination.

type ConnectivityCheckItem

type ConnectivityCheckItem struct {
	Protocol    consts.Protocol
	Port        uint16
	CheckResult *pb.ItemCheckResult
}

ConnectivityCheckItem an item representing one check item of checking whether a node can connect to another by the protocol and port.

type DeployEtcdAction

type DeployEtcdAction struct {
	Base

	CACrt        *x509.Certificate
	CAKey        crypto.Signer
	ClusterNodes []*pb.Node
}

type DeployEtcdActionConfig

type DeployEtcdActionConfig struct {
	CaCrt           *x509.Certificate
	CaKey           crypto.Signer
	Node            *pb.Node
	ClusterNodes    []*pb.Node
	LogFileBasePath string
}

DeployEtcdActionConfig represents the config for a ectd deploy in a node

type DeployWorkerAction

type DeployWorkerAction struct {
	Base
	// contains filtered or unexported fields
}

type DeployWorkerActionConfig

type DeployWorkerActionConfig struct {
	NodeCfg         *pb.NodeDeployConfig
	ClusterConfig   *pb.ClusterConfig
	MasterNodes     []*pb.Node
	LogFileBasePath string
}

type Executor

type Executor interface {
	Execute(act Action) *pb.Error
}

Executor represents the interface of an action executor. Concrete executors implements the logic of actions.

func NewExecutor

func NewExecutor(actionType Type) (Executor, error)

NewExecutor is a simple factory method to return an action executor based on action type.

type FetchKubeConfigAction

type FetchKubeConfigAction struct {
	Base

	KubeConfig []byte
}

type FetchKubeConfigActionConfig

type FetchKubeConfigActionConfig struct {
	Node            *pb.Node
	LogFileBasePath string
}

FetchKubeConfigActionConfig represents the config for a action to fetch the kube config

type InitMasterAction

type InitMasterAction struct {
	Base
	CertKey       string
	MasterNodes   []*pb.Node
	EtcdNodes     []*pb.Node
	ClusterConfig *pb.ClusterConfig
}

type InitMasterActionConfig

type InitMasterActionConfig struct {
	CertKey         string
	Node            *pb.Node
	MasterNodes     []*pb.Node
	EtcdNodes       []*pb.Node
	ClusterConfig   *pb.ClusterConfig
	LogFileBasePath string
}

type ItemStatus

type ItemStatus string

ItemStatus represents the status of an action item

const (
	ItemPending ItemStatus = "pending"
	ItemDoing   ItemStatus = "doing"
	ItemDone    ItemStatus = "done" // means success
	ItemFailed  ItemStatus = "failed"
)

type JoinMasterAction

type JoinMasterAction struct {
	Base
	CertKey       string
	MasterNodes   []*pb.Node
	ClusterConfig *pb.ClusterConfig
}

type JoinMasterActionConfig

type JoinMasterActionConfig struct {
	CertKey         string
	Node            *pb.Node
	MasterNodes     []*pb.Node
	ClusterConfig   *pb.ClusterConfig
	LogFileBasePath string
}

type NodeCheckAction

type NodeCheckAction struct {
	Base
	sync.RWMutex

	NodeCheckConfig *pb.NodeCheckConfig
	CheckItems      []*NodeCheckItem
}

type NodeCheckActionConfig

type NodeCheckActionConfig struct {
	NodeCheckConfig *pb.NodeCheckConfig
	LogFileBasePath string
}

NodeCheckActionConfig represents the config for a node check action

type NodeCheckItem

type NodeCheckItem struct {
	Name        string
	Description string
	Status      ItemStatus
	Err         *pb.Error
}

func ExecuteCheckScript

func ExecuteCheckScript(item check.ItemEnum, config *pb.NodeCheckConfig, checkItemReport *NodeCheckItem) (string, *NodeCheckItem, error)

due to items, ItemsCheckScripts exec remote scripts and return std, report, error

type NodeInitAction

type NodeInitAction struct {
	Base
	sync.RWMutex

	NodeInitConfig *pb.NodeDeployConfig
	NodesConfig    []*pb.NodeDeployConfig
	ClusterConfig  *pb.ClusterConfig
	InitItems      []*NodeInitItem
}

type NodeInitActionConfig

type NodeInitActionConfig struct {
	NodeInitConfig  *pb.NodeDeployConfig
	NodesConfig     []*pb.NodeDeployConfig
	ClusterConfig   *pb.ClusterConfig
	LogFileBasePath string
}

NodeInitActionConfig represents the config for a node init action

type NodeInitItem

type NodeInitItem struct {
	Name        string
	Description string
	Status      ItemStatus
	Err         *pb.Error
}

func ExecuteInitScript

func ExecuteInitScript(item it.ItemEnum, action *NodeInitAction, initItemReport *NodeInitItem) (string, *NodeInitItem, error)

due to items, ItemInitScripts exec remote scripts and return std, report, error

type Status

type Status string

Status represents the status of an action

const (
	ActionPending Status = "pending"
	ActionDoing   Status = "doing"
	ActionDone    Status = "done" // means success
	ActionFailed  Status = "failed"
)

type TestConnectionAction

type TestConnectionAction struct {
	Base
}

type TestConnectionActionConfig

type TestConnectionActionConfig struct {
	Node            *pb.Node
	LogFileBasePath string
}

TestConnectionActionConfig represents the config for a test-connection action

type Type

type Type string

Type represents the type of an action

const ActionTypeConnectivityCheck Type = "ConnectivityCheck"
const ActionTypeDeployEtcd Type = "DeployEtcd"
const ActionTypeDeployWorker Type = "DeployWorker"
const ActionTypeFetchKubeConfig Type = "FetchKubeConfig"
const ActionTypeInitMaster Type = "InitMaster"
const ActionTypeJoinMaster Type = "JoinMaster"
const ActionTypeNodeCheck Type = "NodeCheck"
const ActionTypeNodeInit Type = "NodeInit"
const ActionTypeTestConnection Type = "TestConnection"

Jump to

Keyboard shortcuts

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