task

package
v1.12.1-RC1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 35 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorUnSupportedTask is used to throw error
	// for the tasks which are not supported by
	// the executor instance(s)
	ErrorUnSupportedTask error = errors.New("task not supported")
)

Functions

func RunFallback

func RunFallback(options *RunOptions) (output []byte, err error)

RunFallback executes the fallback tasks

Types

type Executor

type Executor interface {
	Execute() (err error)
}

Executor provides the contract to execute RunTasks

type K8sTaskSpecFetcher

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

K8sTaskSpecFetcher deals with fetching a task specifications from K8s cluster

NOTE:

A task is a K8s ConfigMap

func NewK8sTaskSpecFetcher

func NewK8sTaskSpecFetcher(searchNamespace string) (*K8sTaskSpecFetcher, error)

NewK8sTaskSpecFetcher returns a new instance of K8sTaskSpecFetcher based on the provided namespace.

NOTE:

SearchNamespace refers to the K8s namespace where a task

is expected to be found

func (*K8sTaskSpecFetcher) Fetch

func (f *K8sTaskSpecFetcher) Fetch(taskName string) (runtask *v1alpha1.RunTask, err error)

Fetch returns specifications of a provided task in yaml string format

NOTE:

This is an implementation of TaskSpecFetcher interface

type MetaExecutor

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

MetaExecutor ...

func NewMetaExecutor

func NewMetaExecutor(metaTaskYml string, values map[string]interface{}) (*MetaExecutor, error)

NewMetaExecutor provides a new instance of MetaExecutor

type MetaTaskAction

type MetaTaskAction string

MetaTaskAction represents the action type of RunTask

const (
	// GetTA flags a action as get. Typically used to fetch
	// an object from its name.
	GetTA MetaTaskAction = "get"
	// ListTA flags a action as list. Typically used to fetch
	// a list of objects based on options.
	ListTA MetaTaskAction = "list"
	// PutTA flags a action as put. Typically used to put
	// an object.
	PutTA MetaTaskAction = "put"
	// DeleteTA flags a action as delete. Typically used to
	// delete an object.
	DeleteTA MetaTaskAction = "delete"
	// PatchTA flags a action as patch. Typically used to
	// patch an object.
	PatchTA MetaTaskAction = "patch"
	// ExecTA flags a action as exec. Typically used to
	// exec inside a container of a pod.
	ExecTA MetaTaskAction = "exec"
	// RolloutstatusTA flags a action as rollouttatus. Typically used to
	// get rollout satus of resource
	RolloutstatusTA MetaTaskAction = "rolloutstatus"
	// OutputTA flags the task action as output. Typically used to
	// provide a schema (i.e. a custom defined) based output after
	// running one or more tasks.
	OutputTA MetaTaskAction = "output"
)

type MetaTaskIdentity

type MetaTaskIdentity struct {
	// Identity provides a unique identification to this
	// task.
	//
	// NOTE:
	//  Usage: There should not be two tasks with same identity
	// in a cas template engine run.
	Identity string `json:"id"`
	// Kind of the task
	Kind string `json:"kind"`
	// APIVersion of the task
	APIVersion string `json:"apiVersion"`
}

MetaTaskIdentity will provide the required identity to a task

type MetaTaskProps

type MetaTaskProps struct {
	// RunNamespace is the namespace where task will get
	// executed
	RunNamespace string `json:"runNamespace"`

	// Owner represents the owner of this task
	Owner string `json:"owner"`

	// ObjectName is the name of the resource that gets
	// created or will get operated by this task
	ObjectName string `json:"objectName"`

	// Options is a set of selectors that can be used for
	// tasks that are get or list based actions
	Options string `json:"options"`

	// Retry specifies the no. of times this particular task (i.e. all properties
	// remains same) can be re-tried. This is typically used along with task
	// result verify options for get or list related actions.
	//
	// A sample retry option:
	//
	// # max of 10 attempts in 20 seconds interval
	// retry: "10,20s"
	Retry string `json:"retry"`

	// Disable will disable execution of this task
	Disable bool `json:"disable"`
}

MetaTaskProps provides properties representing the task's meta information

type MetaTaskSpec

type MetaTaskSpec struct {
	// MetaTaskIdentity provides the identity to this task
	MetaTaskIdentity
	// MetaTaskProps provides the task's meta related properties
	MetaTaskProps
	// Action representing this task
	//
	// e.g. get based task or list based task or put based task and so on
	Action MetaTaskAction `json:"action"`
	// RepeatWith sets one or more resources for repetitive execution.
	// In other words a task template is executed multiple times based on each
	// of the item present here.
	RepeatWith RepeatWithResource `json:"repeatWith"`
}

MetaTaskSpec is the specifications of a MetaTask

type OutputExecutor

type OutputExecutor interface {
	Output() (output []byte, err error)
}

OutputExecutor provides the contract to generate content from a RunTask's specifications

NOTE:

The output format is specified in the

RunTask itself

type PostTaskRunFn

type PostTaskRunFn func(taskResult map[string]interface{})

PostTaskRunFn is a closure definition that provides option to act on an individual task's result

type RepeatWithResource

type RepeatWithResource struct {
	// resources is a list of resources that will drive the repetition logic
	// of task execution
	//
	// NOTE:
	//  This is typically a set of items which does not belong to MetaTask
	// category. Any random list of items that influences the repetition logic
	// should be set here.
	Resources []string `json:"resources"`
	// metas is a list of meta task info that will drive the repetition logic
	// of task execution
	Metas []MetaTaskProps `json:"metas"`
}

RepeatWithResource provides properties that influence task execution's repetition behaviour

type RunOptions

type RunOptions struct {
	TaskGroupRunner
	// contains filtered or unexported fields
}

RunOptions represents the various properties required during run

func NewFallbackRunner

func NewFallbackRunner(template string, values map[string]interface{}) (*RunOptions, error)

NewFallbackRunner returns a new instance of task group runner

type RunOptionsMiddleware

type RunOptionsMiddleware func(given *RunOptions) (updated *RunOptions, err error)

RunOptionsMiddleware abstracts updating the given RunOptions instance

func UpdateTaskRunner

func UpdateTaskRunner(updaters []RunOptionsMiddleware) RunOptionsMiddleware

UpdateTaskRunner updates the task runner instance by executing the instance against the list of updaters

func WithOutputTask

func WithOutputTask(taskName string) RunOptionsMiddleware

WithOutputTask updates the given RunOptions instance with output task

func WithRunTaskList

func WithRunTaskList(taskNames []string) RunOptionsMiddleware

WithRunTaskList updates the given RunOptions instance with list of RunTasks

func WithTaskFetcher

func WithTaskFetcher(namespace string) RunOptionsMiddleware

WithTaskFetcher updates the given RunOptions instance with task fetcher instance

type RunTaskKind

type RunTaskKind string

RunTaskKind represents type of runtask operation

const (
	CommandKind RunTaskKind = "Command"
)

CommandKind is a runtask of type Command.

type TaskGroupRunner

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

TaskGroupRunner helps in running a set of Tasks in sequence

func NewTaskGroupRunner

func NewTaskGroupRunner() *TaskGroupRunner

NewTaskGroupRunner returns a new task group.

func (*TaskGroupRunner) AddRunTask

func (m *TaskGroupRunner) AddRunTask(runtask *v1alpha1.RunTask) (err error)

AddRunTask adds a task to the list of tasks to be run by this group runner.

func (*TaskGroupRunner) Run

func (m *TaskGroupRunner) Run(values map[string]interface{}) (output []byte, err error)

Run will run all the defined tasks & will rollback in case of any error

NOTE: values is mutated (i.e. gets modified after each task execution) to let the task execution result be made available to the next task before execution of this next task

func (*TaskGroupRunner) SetFallback

func (m *TaskGroupRunner) SetFallback(castemplate string)

SetFallback sets this runner with a fallback option in case this runner gets into some specific errors e.g. version mismatch error

func (*TaskGroupRunner) SetOutputTask

func (m *TaskGroupRunner) SetOutputTask(runtask *v1alpha1.RunTask) (err error)

SetOutputTask sets this runner with a run task that will be used to return the output after successful execution of this runner.

NOTE:

This output format is specified in the provided run task.

type TaskPatch

type TaskPatch struct {
	// Type determines the type of patch to be applied
	Type TaskPatchType `json:"type"`
	// Specs is a yaml document that provides the patch specifications
	//
	//  Below is a sample patch as yaml document
	//  “`yaml
	//      spec:
	//        template:
	//          spec:
	//            affinity:
	//              nodeAffinity:
	//                requiredDuringSchedulingIgnoredDuringExecution:
	//                  nodeSelectorTerms:
	//                  - matchExpressions:
	//                    - key: kubernetes.io/hostname
	//                      operator: In
	//                      values:
	//                      - amit-thinkpad-l470
	//              podAntiAffinity: null
	//  “`
	Specs string `json:"pspec"`
}

TaskPatch will consist of patch that gets applied against the task object

type TaskPatchType

type TaskPatchType string

TaskPatchType is a custom type that holds the patch type

const (
	// JsonTPT refers to a generic json patch type that is understood
	// by Kubernetes API as well
	JsonTPT TaskPatchType = "json"
	// MergeTPT refers to a generic json merge patch type that is
	// understood by Kubernetes API as well
	MergeTPT TaskPatchType = "merge"
	// StrategicTPT refers to a patch type that is understood
	// by Kubernetes API only
	StrategicTPT TaskPatchType = "strategic"
)

type TaskSpecFetcher

type TaskSpecFetcher interface {
	Fetch(taskName string) (runtask *v1alpha1.RunTask, err error)
}

TaskSpecFetcher is the contract to fetch task specification that includes the task's meta specification

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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