task

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: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InitMasterOperation Operation = "init"
	InitMasterPriority  Priority  = 10
)
View Source
const (
	JointMasterOperation Operation = "join"
	JoinMasterPriority   Priority  = 20
)

Variables

Functions

func ExecuteTask

func ExecuteTask(t Task) error

ExecuteTask starts the task's execution and wait it to finish.

func GenTaskLogFileDir

func GenTaskLogFileDir(basePath, taskName string) string

GenTaskLogFileDir is a helper to return the log file dir based on base path and task name

func GetAllActions

func GetAllActions(aTask Task) []action.Action

GetAllActions returns all actions of a task, including its direct actions and its subtasks' actions recursively.

func RegisterProcessor

func RegisterProcessor(taskType Type, proc Processor) error

RegisterProcessor is to register a Processor for a task type

func StartTask

func StartTask(t Task) error

StartTask does a basic verification on the task, then starts the task's execution and return immediately

Types

type Base

type Base struct {
	Name              string
	TaskType          Type
	Actions           []action.Action
	Status            Status
	Err               *pb.Error
	LogFileDir        string
	CreationTimestamp time.Time
	SubTasks          []Task
	Priority          int
	Parent            string
}

func (*Base) GetActions

func (b *Base) GetActions() []action.Action

func (*Base) GetCreationTimestamp

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

func (*Base) GetErr

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

func (*Base) GetLogFileDir

func (b *Base) GetLogFileDir() string

func (*Base) GetName

func (b *Base) GetName() string

func (*Base) GetParent

func (b *Base) GetParent() string

func (*Base) GetPriority

func (b *Base) GetPriority() int

func (*Base) GetStatus

func (b *Base) GetStatus() Status

func (*Base) GetSubTasks

func (b *Base) GetSubTasks() []Task

func (*Base) GetType

func (b *Base) GetType() Type

func (*Base) SetErr

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

func (*Base) SetLogFileDir

func (b *Base) SetLogFileDir(path string)

func (*Base) SetStatus

func (b *Base) SetStatus(status Status)

type CheckNetworkRequirementsTask

type CheckNetworkRequirementsTask struct {
	Base

	Nodes          []*pb.Node
	NetworkOptions *pb.NetworkOptions
}

type CheckNetworkRequirementsTaskConfig

type CheckNetworkRequirementsTaskConfig struct {
	Nodes           []*pb.Node
	NetworkOptions  *pb.NetworkOptions
	LogFileBasePath string
}

CheckNetworkRequirementsTaskConfig configuration to create a CheckNetworkRequirements task.

type DeployEtcdTask

type DeployEtcdTask struct {
	Base

	Nodes []*pb.Node
}

type DeployEtcdTaskConfig

type DeployEtcdTaskConfig struct {
	Nodes           []*pb.Node
	LogFileBasePath string
	Priority        int
	Parent          string
}

DeployEtcdTaskConfig represents the config for a deploy etcd task.

type DeployMasterTaskConfig

type DeployMasterTaskConfig struct {
	CertKey         string
	EtcdNodes       []*pb.Node
	Nodes           []*pb.Node
	ClusterConfig   *pb.ClusterConfig
	LogFileBasePath string
	Priority        int
	Parent          string
}

DeploymasterTaskConfig represents the config for a deploy master task.

type DeployTask

type DeployTask struct {
	Base
	NodeConfigs   []*pb.NodeDeployConfig
	ClusterConfig *pb.ClusterConfig
}

type DeployTaskConfig

type DeployTaskConfig struct {
	NodeConfigs     []*pb.NodeDeployConfig
	ClusterConfig   *pb.ClusterConfig
	LogFileBasePath string
	Priority        int
}

DeployTaskConfig represents the config for a deploy task.

type DeployWorkerProcessor

type DeployWorkerProcessor struct {
}

func (*DeployWorkerProcessor) SplitTask

func (processor *DeployWorkerProcessor) SplitTask(task Task) error

Spilt the task into one or more node deploy worker actions

type DeployWorkerTaskConfig

type DeployWorkerTaskConfig struct {
	MasterNodes     []*protos.Node
	Nodes           []*protos.NodeDeployConfig
	ClusterConfig   *protos.ClusterConfig
	LogFileBasePath string
	Priority        int
	Parent          string
}

type ExtraResult

type ExtraResult interface {
	ProcessExtraResult(task Task) error
}

ExtraResult defines the interface to process the task's extra result, Task extra result is the specific output of a task, which is not the task's status and err. Task processor can implment this interface optionally.

type FetchKubeConfigTask

type FetchKubeConfigTask struct {
	Base

	Node *pb.Node
	// KubeConfig stores the task result: content of kube config file.
	KubeConfig []byte
}

type FetchKubeConfigTaskConfig

type FetchKubeConfigTaskConfig struct {
	Node            *pb.Node
	LogFileBasePath string
	Priority        int
}

FetchKubeConfigTaskConfig represents the config for a fetch-kube-config task.

type InitMasterTask

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

type InitMasterTaskConfig

type InitMasterTaskConfig struct {
	MasterNodes []*pb.Node

	Priority int
	// contains filtered or unexported fields
}

type JoinMasterTask

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

type JoinMasterTaskConfig

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

type NodeCheckTask

type NodeCheckTask struct {
	Base
	NodeConfigs    []*pb.NodeCheckConfig
	NetworkOptions *pb.NetworkOptions
}

type NodeCheckTaskConfig

type NodeCheckTaskConfig struct {
	NodeConfigs     []*pb.NodeCheckConfig
	NetworkOptions  *pb.NetworkOptions
	LogFileBasePath string
	Priority        int
}

NodeCheckTaskConfig represents the config for a node check task.

type NodeInitTask

type NodeInitTask struct {
	Base
	NodeConfigs   []*pb.NodeDeployConfig
	ClusterConfig *pb.ClusterConfig
}

type NodeInitTaskConfig

type NodeInitTaskConfig struct {
	NodeConfigs     []*pb.NodeDeployConfig
	ClusterConfig   *pb.ClusterConfig
	LogFileBasePath string
	Priority        int
	Parent          string
}

NodeInitTaskConfig represents the config for a node init task

type Operation

type Operation string

type Priority

type Priority int
const (
	DeployEtcdPriority    Priority = 20
	DeployMasterPriority  Priority = 30
	DeployWorkerPriority  Priority = 40
	DeployIngressPriority Priority = 50
)

type Processor

type Processor interface {
	// No need to set the task status in this method, the caller should do that.
	SplitTask(task Task) error
}

Processor defines the interface for all task processors

func NewProcessor

func NewProcessor(taskType Type) (Processor, error)

NewProcessor is a simple factory method to return a task processor based on task type.

type Status

type Status string

Status represents the status of a task

const (
	TaskPending      Status = "pending"
	TaskInitializing Status = "initializing"
	TaskSplitting    Status = "splitting"
	TaskDoing        Status = "doing"
	TaskSuccessful   Status = "successful"
	TaskFailed       Status = "failed"
)

type Store

type Store interface {
	GetTask(name string) Task
	// Add a task, if the task already exists (task name is same), return an error
	AddTask(task Task) error
	// Update a task, if the task doesn't exist (task name is same), return an error
	UpdateTask(task Task) error
	// Update a task, if the task doesn't exist (task name is same), add it.
	UpdateOrAddTask(task Task) error
}

func GetGlobalCacheStore

func GetGlobalCacheStore() Store

type Task

type Task interface {
	GetName() string
	GetType() Type
	GetStatus() Status
	SetStatus(Status)
	GetErr() *pb.Error
	SetErr(*pb.Error)
	GetLogFileDir() string
	SetLogFileDir(string)
	GetActions() []action.Action
	GetCreationTimestamp() time.Time
	// Sub tasks are Task too.
	GetSubTasks() []Task
	// GetPriority returns the priority of the task: smaller value means higher prioirty.
	// A task should wait until all higher priority tasks are done
	GetPriority() int
	// If a task is not a sub task, this will return ""
	GetParent() string
}

Task represents something to do and typically includes one or more actions.

func NewCheckNetworkRequirementsTask

func NewCheckNetworkRequirementsTask(
	name string, config *CheckNetworkRequirementsTaskConfig) (Task, error)

NewCheckNetworkRequirementsTask create a CheckNetworkRequirements task to check prerequisites of deploying network.

func NewDeployEtcdTask

func NewDeployEtcdTask(taskName string, taskConfig *DeployEtcdTaskConfig) (Task, error)

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

func NewDeployMasterTask

func NewDeployMasterTask(taskName string, taskConfig *DeployMasterTaskConfig) (Task, error)

NewDeploymasterTask returns a deploy master task based on the config. User should use this function to create a deploy master task.

func NewDeployTask

func NewDeployTask(taskName string, taskConfig *DeployTaskConfig) (Task, error)

NewDeployTask returns a deploy task based on the config. User should use this function to create a deploy task.

func NewDeployWorkerTask

func NewDeployWorkerTask(taskName string, taskConfig *DeployWorkerTaskConfig) (Task, error)

NewDeployWorkerTask returns a deploy k8s worker task based on the config. User should use this function to create a deploy worker task.

func NewFetchKubeConfigTask

func NewFetchKubeConfigTask(taskName string, taskConfig *FetchKubeConfigTaskConfig) (Task, error)

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

func NewInitMasterTask

func NewInitMasterTask(taskName string, taskConfig *InitMasterTaskConfig) (Task, error)

func NewJoinMasterTask

func NewJoinMasterTask(taskName string, taskConfig *JoinMasterTaskConfig) (Task, error)

func NewNodeCheckTask

func NewNodeCheckTask(taskName string, taskConfig *NodeCheckTaskConfig) (Task, error)

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

func NewNodeInitTask

func NewNodeInitTask(taskName string, taskConfig *NodeInitTaskConfig) (Task, error)

NewNodeInitTask returns a common node init task based on the config. User should use this function to create a common node init task.

func NewTestConnectionTask

func NewTestConnectionTask(taskName string, taskConfig *TestConnectionTaskConfig) (Task, error)

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

type TestConnectionTask

type TestConnectionTask struct {
	Base

	Node *pb.Node
}

type TestConnectionTaskConfig

type TestConnectionTaskConfig struct {
	Node            *pb.Node
	LogFileBasePath string
	Priority        int
}

TestConnectionTaskConfig represents the config for a test-connection task.

type Type

type Type string

Type represents the type of a task

const TaskTypeCheckNetworkRequirements Type = "CheckNetworkRequirements"
const TaskTypeDeploy Type = "Deploy"
const TaskTypeDeployEtcd Type = "DeployEtcd"
const TaskTypeDeployMaster Type = "DeployMaster"
const TaskTypeDeployWorker Type = "DeployWorker"
const TaskTypeFetchKubeConfig Type = "FetchKubeConfig"
const TaskTypeInitMaster Type = "InitMaster"
const TaskTypeJoinMaster Type = "JoinMaster"
const TaskTypeNodeCheck Type = "NodeCheck"
const TaskTypeNodeInit Type = "NodeInit"
const TaskTypeTestConnection Type = "TestConnection"

Jump to

Keyboard shortcuts

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