taskrunner

package
v0.36.0-flux.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition string

Condition is a type that defines the types of conditions which a WaitTask can use.

const (
	// AllCurrent Condition means all the provided resources
	// has reached (and remains in) the Current status.
	AllCurrent Condition = "AllCurrent"

	// AllNotFound Condition means all the provided resources
	// has reached the NotFound status, i.e. they are all deleted
	// from the cluster.
	AllNotFound Condition = "AllNotFound"
)

func (Condition) Meets

func (c Condition) Meets(s status.Status) bool

Meets returns true if the provided status meets the condition and false if it does not.

type Options

type Options struct {
	EmitStatusEvents bool
	// RESTScopeStrategy specifies which strategy to use when listing and
	// watching resources. By default, the strategy is selected automatically.
	WatcherRESTScopeStrategy watcher.RESTScopeStrategy
}

Options defines properties that is passed along to the statusPoller.

type Task

type Task interface {
	Name() string
	Action() event.ResourceAction
	Identifiers() object.ObjMetadataSet
	Start(*TaskContext)
	StatusUpdate(*TaskContext, object.ObjMetadata)
	Cancel(*TaskContext)
}

Task is the interface that must be implemented by all tasks that will be executed by the taskrunner.

type TaskContext

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

TaskContext defines a context that is passed between all the tasks that is in a taskqueue.

func NewTaskContext

func NewTaskContext(eventChannel chan event.Event, resourceCache cache.ResourceCache) *TaskContext

NewTaskContext returns a new TaskContext

func (*TaskContext) AbandonedObjects

func (tc *TaskContext) AbandonedObjects() object.ObjMetadataSet

AbandonedObjects returns all the abandoned objects

func (*TaskContext) AddAbandonedObject

func (tc *TaskContext) AddAbandonedObject(id object.ObjMetadata)

AddAbandonedObject registers that the object is abandoned

func (*TaskContext) AddInvalidObject

func (tc *TaskContext) AddInvalidObject(id object.ObjMetadata)

AddInvalidObject registers that the object is abandoned

func (*TaskContext) EventChannel

func (tc *TaskContext) EventChannel() chan event.Event

func (*TaskContext) Graph

func (tc *TaskContext) Graph() *graph.Graph

func (*TaskContext) InvalidObjects

func (tc *TaskContext) InvalidObjects() object.ObjMetadataSet

InvalidObjects returns all the abandoned objects

func (*TaskContext) InventoryManager

func (tc *TaskContext) InventoryManager() *inventory.Manager

func (*TaskContext) IsAbandonedObject

func (tc *TaskContext) IsAbandonedObject(id object.ObjMetadata) bool

IsAbandonedObject returns true if the object is abandoned

func (*TaskContext) IsInvalidObject

func (tc *TaskContext) IsInvalidObject(id object.ObjMetadata) bool

IsInvalidObject returns true if the object is abandoned

func (*TaskContext) ResourceCache

func (tc *TaskContext) ResourceCache() cache.ResourceCache

func (*TaskContext) SendEvent

func (tc *TaskContext) SendEvent(e event.Event)

SendEvent sends an event on the event channel

func (*TaskContext) SetGraph

func (tc *TaskContext) SetGraph(g *graph.Graph)

func (*TaskContext) TaskChannel

func (tc *TaskContext) TaskChannel() chan TaskResult

type TaskResult

type TaskResult struct {
	Err error
}

TaskResult is the type returned from tasks once they have completed or failed. If it has failed or timed out, the Err property will be set.

type TaskStatusRunner

type TaskStatusRunner struct {
	Identifiers   object.ObjMetadataSet
	StatusWatcher watcher.StatusWatcher
}

TaskStatusRunner is a taskRunner that executes a set of tasks while at the same time uses the statusPoller to keep track of the status of the resources.

func NewTaskStatusRunner

func NewTaskStatusRunner(identifiers object.ObjMetadataSet, statusWatcher watcher.StatusWatcher) *TaskStatusRunner

NewTaskStatusRunner returns a new TaskStatusRunner.

func (*TaskStatusRunner) Run

func (tsr *TaskStatusRunner) Run(
	ctx context.Context,
	taskContext *TaskContext,
	taskQueue chan Task,
	opts Options,
) error

Run executes the tasks in the taskqueue, with the statusPoller running in the background.

The tasks run in a loop where a single goroutine will process events from three different channels.

  • taskQueue is read to allow updating the task queue at runtime.
  • statusChannel is read to allow updates to the resource cache and triggering validation of wait conditions.
  • eventChannel is written to with events based on status updates, if emitStatusEvents is true.

type WaitTask

type WaitTask struct {
	// TaskName allows providing a name for the task.
	TaskName string
	// Ids is the full list of resources that we are waiting for.
	Ids object.ObjMetadataSet
	// Condition defines the status we want all resources to reach
	Condition Condition
	// Timeout defines how long we are willing to wait for the condition
	// to be met.
	Timeout time.Duration
	// Mapper is the RESTMapper to update after CRDs have been reconciled
	Mapper meta.RESTMapper
	// contains filtered or unexported fields
}

WaitTask is an implementation of the Task interface that is used to wait for a set of resources (identified by a slice of ObjMetadata) will all meet the condition specified. It also specifies a timeout for how long we are willing to wait for this to happen. Unlike other implementations of the Task interface, the wait task is handled in a special way to the taskrunner and is a part of the core package.

func NewWaitTask

func NewWaitTask(name string, ids object.ObjMetadataSet, cond Condition, timeout time.Duration, mapper meta.RESTMapper) *WaitTask

NewWaitTask creates a new wait task where we will wait until the resources specifies by ids all meet the specified condition.

func (*WaitTask) Action

func (w *WaitTask) Action() event.ResourceAction

func (*WaitTask) Cancel

func (w *WaitTask) Cancel(_ *TaskContext)

Cancel exits early with a timeout error

func (*WaitTask) Identifiers

func (w *WaitTask) Identifiers() object.ObjMetadataSet

func (*WaitTask) Name

func (w *WaitTask) Name() string

func (*WaitTask) Start

func (w *WaitTask) Start(taskContext *TaskContext)

Start kicks off the task. For the wait task, this just means setting up the timeout timer.

func (*WaitTask) StatusUpdate

func (w *WaitTask) StatusUpdate(taskContext *TaskContext, id object.ObjMetadata)

StatusUpdate records objects status updates and sends WaitEvents. If all objects are reconciled or skipped, cancelFunc is called. The pending set is write locked during execution of StatusUpdate.

Jump to

Keyboard shortcuts

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