task

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Created      = "Created"
	Ready        = "Ready"
	Postponed    = "Postponed"
	QuotaBlocked = "QuotaBlocked"
	Pending      = "Pending"
	Running      = "Running"
	Succeeded    = "Succeeded"
	Failed       = "Failed"
	Canceled     = "Canceled"
)

States also used as events: - Postponed - QuotaBlocked

View Source
const (
	AddonSelected = "AddonSelected"
	ExtSelected   = "ExtensionSelected"
	ImageError    = "ImageError"
	PodNotFound   = "PodNotFound"
	PodCreated    = "PodCreated"
	PodPending    = "PodPending"
	PodRunning    = "PodRunning"
	Preempted     = "Preempted"
	PodSucceeded  = "PodSucceeded"
	PodFailed     = "PodFailed"
	PodDeleted    = "PodDeleted"
	Escalated     = "Escalated"
	Released      = "Released"
)

Events

View Source
const (
	TaskLabel = "task"
	AppLabel  = "app"
	RoleLabel = "role"
)

k8s labels.

View Source
const (
	Shared = "shared"
	Cache  = "cache"
)
View Source
const (
	Unit = time.Second
)

Variables

View Source
var (
	Settings = &settings.Settings
	Log      = logr.WithName("task-scheduler")
)
View Source
var (
	PredRegex = regexp.MustCompile(`(\w+)\:([\w/=]+)`)
)
View Source
var (
	SeqRegex = regexp.MustCompile(`(\${seq:)([0-9]+)}`)
)

Functions

func ExtEnv added in v0.5.0

func ExtEnv(extension string, envar string) (s string)

ExtEnv returns an environment variable named namespaced to an extension. Format: _EXT_<extension_<var>.

func SoftErr added in v0.5.0

func SoftErr(err error) (matched, retry bool)

SoftErr returns true when the error isA SoftError.

Types

type AddonNotFound

type AddonNotFound struct {
	Name string
}

AddonNotFound used to report addon referenced by a task but cannot be found.

func (*AddonNotFound) Error

func (e *AddonNotFound) Error() string

func (*AddonNotFound) Is

func (e *AddonNotFound) Is(err error) (matched bool)

func (*AddonNotFound) Retry added in v0.5.0

func (e *AddonNotFound) Retry() (r bool)

type AddonNotSelected added in v0.5.0

type AddonNotSelected struct {
}

AddonNotSelected report that an addon has not been selected.

func (*AddonNotSelected) Error added in v0.5.0

func (e *AddonNotSelected) Error() string

func (*AddonNotSelected) Is added in v0.5.0

func (e *AddonNotSelected) Is(err error) (matched bool)

func (*AddonNotSelected) Retry added in v0.5.0

func (e *AddonNotSelected) Retry() (r bool)

type BadRequest added in v0.5.0

type BadRequest struct {
	Reason string
}

BadRequest report bad request.

func (*BadRequest) Error added in v0.5.0

func (e *BadRequest) Error() string

func (*BadRequest) Is added in v0.5.0

func (e *BadRequest) Is(err error) (matched bool)

type Cluster added in v0.5.0

type Cluster struct {
	k8s.Client
	// contains filtered or unexported fields
}

Cluster provides cached cluster resources. Maps must NOT be accessed directly.

func (*Cluster) Addon added in v0.5.0

func (k *Cluster) Addon(name string) (r *crd.Addon, found bool)

Addon returns an addon my name.

func (*Cluster) Addons added in v0.5.0

func (k *Cluster) Addons() (list []*crd.Addon)

Addons returns an addon my name.

func (*Cluster) Extension added in v0.5.0

func (k *Cluster) Extension(name string) (r *crd.Extension, found bool)

Extension returns an extension by name.

func (*Cluster) Extensions added in v0.5.0

func (k *Cluster) Extensions() (list []*crd.Extension)

Extensions returns an addon my name.

func (*Cluster) Pod added in v0.5.0

func (k *Cluster) Pod(name string) (r *core.Pod, found bool)

Pod returns a pod by name.

func (*Cluster) Pods added in v0.5.0

func (k *Cluster) Pods() (list []*core.Pod)

Pods returns a list of pods.

func (*Cluster) Refresh added in v0.5.0

func (k *Cluster) Refresh() (err error)

Refresh the cache.

func (*Cluster) Tackle added in v0.5.0

func (k *Cluster) Tackle() (r *crd.Tackle)

Tackle returns the tackle resource.

func (*Cluster) Task added in v0.5.0

func (k *Cluster) Task(name string) (r *crd.Task, found bool)

Task returns a task by name.

type Event added in v0.5.0

type Event struct {
	Type     string
	Reason   string
	Age      string
	Reporter string
	Message  string
}

Event represents a pod event.

type ExtensionNotFound added in v0.5.0

type ExtensionNotFound struct {
	Name string
}

ExtensionNotFound used to report an extension referenced by a task but cannot be found.

func (*ExtensionNotFound) Error added in v0.5.0

func (e *ExtensionNotFound) Error() string

func (*ExtensionNotFound) Is added in v0.5.0

func (e *ExtensionNotFound) Is(err error) (matched bool)

func (*ExtensionNotFound) Retry added in v0.5.0

func (e *ExtensionNotFound) Retry() (r bool)

type ExtensionNotValid added in v0.5.0

type ExtensionNotValid struct {
	Name  string
	Addon string
}

ExtensionNotValid used to report extension referenced by a task not valid with addon.

func (*ExtensionNotValid) Error added in v0.5.0

func (e *ExtensionNotValid) Error() string

func (*ExtensionNotValid) Is added in v0.5.0

func (e *ExtensionNotValid) Is(err error) (matched bool)

func (*ExtensionNotValid) Retry added in v0.5.0

func (e *ExtensionNotValid) Retry() (r bool)

type Injector added in v0.5.0

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

Injector macro processor.

func (*Injector) Inject added in v0.5.0

func (r *Injector) Inject(container *core.Container)

Inject process macros.

type KindNotFound added in v0.5.0

type KindNotFound struct {
	Name string
}

KindNotFound used to report task (kind) referenced by a task but cannot be found.

func (*KindNotFound) Error added in v0.5.0

func (e *KindNotFound) Error() string

func (*KindNotFound) Is added in v0.5.0

func (e *KindNotFound) Is(err error) (matched bool)

func (*KindNotFound) Retry added in v0.5.0

func (e *KindNotFound) Retry() (r bool)

type Manager

type Manager struct {
	// DB
	DB *gorm.DB
	// k8s client.
	Client k8s.Client
	// Addon token scopes.
	Scopes []string
	// contains filtered or unexported fields
}

Manager provides task management.

func (*Manager) Cancel added in v0.5.0

func (m *Manager) Cancel(db *gorm.DB, id uint) (err error)

Cancel a task.

func (*Manager) Create added in v0.5.0

func (m *Manager) Create(db *gorm.DB, requested *Task) (err error)

Create a task.

func (*Manager) Delete added in v0.5.0

func (m *Manager) Delete(db *gorm.DB, id uint) (err error)

Delete a task.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run the manager.

func (*Manager) Update added in v0.5.0

func (m *Manager) Update(db *gorm.DB, requested *Task) (err error)

Update update task.

type NotReady added in v0.5.0

type NotReady struct {
	Kind   string
	Name   string
	Reason string
}

NotReady report that a resource does not have the ready condition.

func (*NotReady) Error added in v0.5.0

func (e *NotReady) Error() string

func (*NotReady) Is added in v0.5.0

func (e *NotReady) Is(err error) (matched bool)

func (*NotReady) Retry added in v0.5.0

func (e *NotReady) Retry() (r bool)

type NotReconciled added in v0.5.0

type NotReconciled struct {
	Kind string
	Name string
}

NotReconciled report as resource has not been reconciled.

func (*NotReconciled) Error added in v0.5.0

func (e *NotReconciled) Error() string

func (*NotReconciled) Is added in v0.5.0

func (e *NotReconciled) Is(err error) (matched bool)

func (*NotReconciled) Retry added in v0.5.0

func (e *NotReconciled) Retry() (r bool)

type PodRejected added in v0.5.0

type PodRejected struct {
	Reason string
}

PodRejected report pod rejected..

func (*PodRejected) Error added in v0.5.0

func (e *PodRejected) Error() string

func (*PodRejected) Is added in v0.5.0

func (e *PodRejected) Is(err error) (matched bool)

func (*PodRejected) Match added in v0.5.0

func (e *PodRejected) Match(err error) (matched bool)

Match returns true when pod is rejected.

func (*PodRejected) Retry added in v0.5.0

func (e *PodRejected) Retry() (r bool)

type Predicate added in v0.5.0

type Predicate interface {
	Match(ref string) (matched bool, err error)
}

type Preempt added in v0.5.0

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

Preempt request.

type Priority added in v0.5.0

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

Priority escalator.

func (*Priority) Escalate added in v0.5.0

func (p *Priority) Escalate(ready []*Task) (escalated []*Task)

Escalate task dependencies as needed.

type PriorityNotFound added in v0.5.0

type PriorityNotFound struct {
	Name  string
	Value int
}

PriorityNotFound report priority class not found.

func (*PriorityNotFound) Error added in v0.5.0

func (e *PriorityNotFound) Error() string

func (*PriorityNotFound) Is added in v0.5.0

func (e *PriorityNotFound) Is(err error) (matched bool)

func (*PriorityNotFound) Retry added in v0.5.0

func (e *PriorityNotFound) Retry() (r bool)

type QuotaExceeded added in v0.3.2

type QuotaExceeded struct {
	Reason string
}

QuotaExceeded report quota exceeded.

func (*QuotaExceeded) Error added in v0.3.2

func (e *QuotaExceeded) Error() string

func (*QuotaExceeded) Is added in v0.3.2

func (e *QuotaExceeded) Is(err error) (matched bool)

func (*QuotaExceeded) Match added in v0.3.2

func (e *QuotaExceeded) Match(err error) (matched bool)

Match returns true when the error is Forbidden due to quota exceeded.

func (*QuotaExceeded) Retry added in v0.5.0

func (e *QuotaExceeded) Retry() (r bool)

type Rule

type Rule interface {
	Match(ready, other *Task) (matched bool, reason string)
}

Rule defines postpone rules.

type RuleDeps added in v0.5.0

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

RuleDeps - Task kind dependencies.

func (*RuleDeps) Match added in v0.5.0

func (r *RuleDeps) Match(ready, other *Task) (matched bool, reason string)

Match determines the match.

type RuleIsolated

type RuleIsolated struct {
}

RuleIsolated policy.

func (*RuleIsolated) Match

func (r *RuleIsolated) Match(ready, other *Task) (matched bool, reason string)

Match determines the match.

type RulePreempted added in v0.5.0

type RulePreempted struct {
}

RulePreempted - preempted tasks postponed to prevent thrashing.

func (*RulePreempted) Match added in v0.5.0

func (r *RulePreempted) Match(ready, _ *Task) (matched bool, reason string)

Match determines the match. Postpone based on a duration after the last preempted event.

type RuleUnique

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

RuleUnique running tasks must be unique by:

  • application
  • addon.

func (*RuleUnique) Match

func (r *RuleUnique) Match(ready, other *Task) (matched bool, reason string)

Match determines the match.

type Selector added in v0.5.0

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

Selector used to match addons and extensions.

func NewSelector added in v0.5.0

func NewSelector(db *gorm.DB, task *Task) (selector *Selector)

NewSelector returns a selector.

func (*Selector) Match added in v0.5.0

func (r *Selector) Match(selector string) (matched bool, err error)

Match evaluates the selector.

type SelectorNotValid added in v0.5.0

type SelectorNotValid struct {
	Selector  string
	Predicate string
	Reason    string
}

SelectorNotValid reports selector errors.

func (*SelectorNotValid) Error added in v0.5.0

func (e *SelectorNotValid) Error() string

func (*SelectorNotValid) Is added in v0.5.0

func (e *SelectorNotValid) Is(err error) (matched bool)

func (*SelectorNotValid) Retry added in v0.5.0

func (e *SelectorNotValid) Retry() (r bool)

type SeqInjector added in v0.5.0

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

SeqInjector provides ${seq:<pool>} sequence injection.

type SoftError added in v0.5.0

type SoftError interface {
	// Retry determines if the task should be
	// retried or failed immediately.
	Retry() (r bool)
}

SoftError used to report errors specific to one task rather than systemic issues.

type TagPredicate added in v0.5.0

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

TagPredicate evaluates application tag references.

func (*TagPredicate) Match added in v0.5.0

func (r *TagPredicate) Match(ref string) (matched bool, err error)

Match evaluates application tag references. The `ref` has format: category=tag. The tag and behaves like a wildcard when not specified.

type Task

type Task struct {
	// model.
	*model.Task
}

Task is an runtime task.

func (*Task) Cancel

func (r *Task) Cancel(client k8s.Client) (err error)

Cancel the task.

func (*Task) Delete

func (r *Task) Delete(client k8s.Client) (err error)

Delete the associated pod as needed.

func (*Task) Error added in v0.5.0

func (r *Task) Error(severity, description string, x ...any)

Error appends an error.

func (*Task) Event added in v0.5.0

func (r *Task) Event(kind string, p ...any)

Event appends an event. Duplicates result in count incremented and Last updated.

func (*Task) LastEvent added in v0.5.0

func (r *Task) LastEvent(kind string) (event *model.TaskEvent, found bool)

LastEvent returns the last event of the specified kind.

func (*Task) Reflect

func (r *Task) Reflect(cluster *Cluster) (pod *core.Pod, found bool)

Reflect finds the associated pod and updates the task state.

func (*Task) Run

func (r *Task) Run(cluster *Cluster) (started bool, err error)

Run the specified task.

func (*Task) StateIn added in v0.5.0

func (r *Task) StateIn(states ...string) (matched bool)

StateIn returns true matches on of the specified states.

func (*Task) With added in v0.5.0

func (r *Task) With(m *model.Task)

type Validator

type Validator struct {
	// k8s client.
	Client k8s.Client
}

Validator validates task tokens.

func (*Validator) Valid

func (r *Validator) Valid(token *jwt.Token, db *gorm.DB) (err error)

Valid token when:

  • The token references a task.
  • The task is valid and running.
  • The task pod valid and pending|running.

Jump to

Keyboard shortcuts

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