executor

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LabelWerftMarker is the label applied to all jobs and configmaps. This label can be used
	// to search for werft job objects in Kubernetes.
	LabelWerftMarker = "werft.sh/job"

	// UserDataAnnotationPrefix is prepended to all user annotations added to jobs
	UserDataAnnotationPrefix = "userdata.werft.sh"

	// AnnotationFailureLimit is the annotation denoting the max times a job may fail
	AnnotationFailureLimit = "werft.sh/failureLimit"

	// AnnotationMetadata stores the JSON encoded metadata available at creation
	AnnotationMetadata = "werft.sh/metadata"

	// AnnotationFailed explicitelly fails the job
	AnnotationFailed = "werft.sh/failed"

	// AnnotationResults stores JSON encoded list of a job results
	AnnotationResults = "werft.sh/results"

	// AnnotationCanReplay stores if this job can be replayed
	AnnotationCanReplay = "werft.sh/canReplay"

	// AnnotationWaitUntil stores the start time of waiting job
	AnnotationWaitUntil = "werft.sh/waitUntil"
)
View Source
const (
	// LabelJobName adds the ID of the job to the k8s object
	LabelJobName = "werft.sh/jobName"

	// LabelMutex makes jobs findable via their mutex
	LabelMutex = "werft.sh/mutex"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Namespace       string    `yaml:"namespace"`
	EventTraceLog   string    `yaml:"eventTraceLog,omitempty"`
	JobPrepTimeout  *Duration `yaml:"preperationTimeout"`
	JobTotalTimeout *Duration `yaml:"totalTimeout"`
}

Config configures the executor

type Duration

type Duration struct {
	time.Duration
}

Duration is a JSON un-/marshallable type

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML parses a duration from its JSON representation

type Executor

type Executor struct {
	// OnUpdate is called when the status of a job changes.
	// Beware: this function can be called several times with the same status.
	OnUpdate func(pod *corev1.Pod, status *werftv1.JobStatus)

	Client     kubernetes.Interface
	Config     Config
	KubeConfig *rest.Config
	// contains filtered or unexported fields
}

Executor starts and watches jobs running in Kubernetes

func NewExecutor

func NewExecutor(config Config, kubeConfig *rest.Config) (*Executor, error)

NewExecutor creates a new job center instance

func (*Executor) GetKnownJobs

func (js *Executor) GetKnownJobs() (jobs []v1.JobStatus, err error)

GetKnownJobs returns a list of all jobs the executor knows about

func (*Executor) Logs

func (js *Executor) Logs(name string) io.Reader

Logs provides the log output of a running job. If the job is unknown, nil is returned.

func (*Executor) RegisterResult

func (js *Executor) RegisterResult(jobname string, res *v1.JobResult) error

RegisterResult registers a result produced by a job

func (*Executor) Run

func (js *Executor) Run()

Run starts the executor and returns immediately

func (*Executor) Start

func (js *Executor) Start(podspec corev1.PodSpec, metadata werftv1.JobMetadata, options ...StartOpt) (status *v1.JobStatus, err error)

Start starts a new job

func (*Executor) Stop

func (js *Executor) Stop(name, reason string) error

Stop stops a job

type StartOpt

type StartOpt func(*startOptions)

StartOpt configures a job at startup

func WithAnnotation

func WithAnnotation(key, value string) StartOpt

WithAnnotation sets a single annotation on a job

func WithAnnotations

func WithAnnotations(annotations map[string]string) StartOpt

WithAnnotations sets all annotations of a job

func WithBackoff

func WithBackoff(limit int) StartOpt

WithBackoff configures the backoff behaviour of a job

func WithCanReplay

func WithCanReplay(canReplay bool) StartOpt

WithCanReplay configures the if the job can be replayed

func WithMutex

func WithMutex(name string) StartOpt

WithMutex starts a job with a mutex (i.e. cancels all other jobs with that mutex)

func WithName

func WithName(name string) StartOpt

WithName sets the name of the job

func WithWaitUntil

func WithWaitUntil(t time.Time) StartOpt

WithWaitUntil starts the execution of a job at some later point

Jump to

Keyboard shortcuts

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