v1

package
v0.0.0-...-1670326 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package v1 contains API Schema definitions for the batch v1 API group +kubebuilder:object:generate=true +groupName=batch.gresearch.co.uk

Index

Constants

This section is empty.

Variables

View Source
var (
	// GroupVersion is group version used to register these objects
	GroupVersion = schema.GroupVersion{Group: "batch.gresearch.co.uk", Version: "v1"}

	// SchemeBuilder is used to add go types to the GroupVersionKind scheme
	SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

	// AddToScheme adds the types in this group-version to the given scheme.
	AddToScheme = SchemeBuilder.AddToScheme
)

Functions

func CoerceConditionToBoolen

func CoerceConditionToBoolen(condition *metav1.Condition) bool

func FindCondition

func FindCondition(controlledJobStatus ControlledJobStatus, conditionType ControlledJobConditionType) *metav1.Condition

FindCondition returns the condition you're looking for or nil.

func JobConditionToReason

func JobConditionToReason(condition kbatch.JobCondition, prefix string) string

func OptionalStatusAsConditionStatus

func OptionalStatusAsConditionStatus(flag *bool) metav1.ConditionStatus

func RemoveCondition

func RemoveCondition(controlledJob *ControlledJob, conditionType ControlledJobConditionType)

func SetCondition

func SetCondition(controlledJob *ControlledJob, conditionType ControlledJobConditionType, status metav1.ConditionStatus, reason, message string)

SetCondition makes sure the given condition type is set to the given value on the controlledJob Will update a condition if one of that type already exists, otherwise will append a new one Based on https://github.com/kubernetes/kubernetes/blob/d1a2a134c532109540025c990697a6900c2e62fc/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/helpers.go#L29

func SetConditionBasedOnFlag

func SetConditionBasedOnFlag(controlledJob *ControlledJob, conditionType ControlledJobConditionType, flag bool,
	reasonWhenTrue, messageWhenTrue,
	reasonWhenFalse, messageWhenFalse string)

func StatusAsConditionStatus

func StatusAsConditionStatus(flag bool) metav1.ConditionStatus

Types

type ControlledJob

type ControlledJob struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   ControlledJobSpec   `json:"spec,omitempty"`
	Status ControlledJobStatus `json:"status,omitempty"`
}

ControlledJob is the Schema for the controlledjobs API

func (*ControlledJob) DeepCopy

func (in *ControlledJob) DeepCopy() *ControlledJob

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlledJob.

func (*ControlledJob) DeepCopyInto

func (in *ControlledJob) DeepCopyInto(out *ControlledJob)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*ControlledJob) DeepCopyObject

func (in *ControlledJob) DeepCopyObject() runtime.Object

DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.

type ControlledJobActionHistoryEntry

type ControlledJobActionHistoryEntry struct {
	// Type is the action the ControlledJob took
	Type string `json:"type"`
	// Timestamp is the time the condition was last observed
	Timestamp *metav1.Time `json:"timestamp"`
	// Message contains human-readable message indicating details about the action
	// +optional
	Message string `json:"message,omitempty"`
	// The most recent scheduled start time prior to this action. This allows grouping of
	// actions by start time to see a 'history for today'
	// NOW DEPRECATED AND NOT SET ANYMORE
	// +optional
	ScheduledStartTime *metav1.Time `json:"scheduledStartTime,omitempty"`
	// JobIndex is an incrementing number of jobs for the current run period.
	// At a start time in the schedule, a job with index 0 will be created. If that
	// fails and auto-restart is enabled a new job with index 1 will be created in its
	// place. This field records the JobIndex of the affected job
	// +optional
	JobIndex *int `json:"jobIndex,omitempty"`
	// JobName is the name of the job affected by this action (if any). e.g. the job
	// that was started, or stopped
	// +optional
	JobName string `json:"jobName,omitempty"`
}

ControlledJobActionHistoryEntry

func (*ControlledJobActionHistoryEntry) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlledJobActionHistoryEntry.

func (*ControlledJobActionHistoryEntry) DeepCopyInto

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type ControlledJobConditionType

type ControlledJobConditionType string

ControlledJobConditionType is a enum type defining the conditions that ControlledJobs support

const (
	// ConditionTypeShouldBeRunning is set to True when the ControlledJob is between a start and stop time, and False if
	// between a stop and start time. If there are no start times, it will be set to Unknown
	ConditionTypeShouldBeRunning ControlledJobConditionType = "ShouldBeRunning"

	// ConditionTypeSuspended is set to True if the user has marked this ControlledJob as suspended
	ConditionTypeSuspended ControlledJobConditionType = "Suspended"

	// ConditionTypeOutOfDate is True if the spec of the running job does not match the desired JobSpec, and we
	// are not able to recreate the job with the new spec
	ConditionTypeOutOfDate ControlledJobConditionType = "OutOfDate"

	// ConditionTypeJobManuallyScheduled is True if the current job (if any) was manually scheduled by a user, not
	// created based on a start event
	ConditionTypeJobManuallyScheduled ControlledJobConditionType = "JobManuallyScheduled"

	// ConditionTypeJobExists is True if there is a current job that isn't being deleted
	ConditionTypeJobExists ControlledJobConditionType = "JobExists"

	// ConditionTypeJobRunning is True when the job exists, and has reached its expected number of ready pods. That is, all pods have been
	// created and are reporting as ready. This will be False if the Job exists, but hasn't reached this state yet. Staying in a False state
	// for a while is an indication that the Pod is failing to successfully start (image pull failure etc)
	// Note that the 'ready' status of a pod is a beta feature, so if it is not present on the Job, this will always be Unknown
	ConditionTypeJobRunning ControlledJobConditionType = "JobRunning"

	// ConditionTypeJobComplete is True if the current job (if any) reports itself as complete
	ConditionTypeJobComplete ControlledJobConditionType = "JobComplete"

	// ConditionTypeJobFailed is True if the current job (if any) reports itself as failed
	ConditionTypeJobFailed ControlledJobConditionType = "JobFailed"

	// ConditionTypeJobBeingDeleted is True if the current job (if any) is currently being deleted
	ConditionTypeJobBeingDeleted ControlledJobConditionType = "JobBeingDeleted"

	// ConditionTypeJobSuspended is True if the current job (if any) is currently suspended. This often happens at startup
	// so that we can ensure only one Job is running at any time
	ConditionTypeJobSuspended ControlledJobConditionType = "JobSuspended"

	// ConditionTypeJobStoppedByUser is True if the current job (if any) was stopped by the user (using the API)
	ConditionTypeJobStoppedByUser ControlledJobConditionType = "JobStoppedByUser"

	// ConditionTypeFailedToCreateJob occurs if we encountered an error the last time we tried to create a job
	ConditionTypeFailedToCreateJob ControlledJobConditionType = "FailedToCreateJob"

	// ConditionTypeFailedToSuspendJob occurs if we encountered an error the last time we tried to suspend a job
	ConditionTypeFailedToSuspendJob ControlledJobConditionType = "FailedToSuspendJob"

	// ConditionTypeFailedToUnsuspendJob occurs if we encountered an error the last time we tried to unsuspend a job
	ConditionTypeFailedToUnsuspendJob ControlledJobConditionType = "FailedToUnsuspendJob"

	// ConditionTypeFailedToDeleteJob occurs if we encountered an error the last time we tried to delete a job
	ConditionTypeFailedToDeleteJob ControlledJobConditionType = "FailedToDeleteJob"

	// ConditionTypeFailedToDeleteJob occurs if we expect to be starting a job, but the configured StartingDeadline has been exceeded
	ConditionTypeStartingDeadlineExceeded ControlledJobConditionType = "StartingDeadlineExceeded"

	// ConditionTypeRunningExpectedly is true if JobPotentiallyRunning, and either ShouldBeRunning or JobManuallyScheduled
	ConditionTypeRunningExpectedly ControlledJobConditionType = "RunningExpectedly"

	// ConditionTypeRunningUnexpectedly is true if JobPotentiallyRunning, and both NOT ShouldBeRunning and NOT JobManuallyScheduled
	ConditionTypeRunningUnexpectedly ControlledJobConditionType = "RunningUnexpectedly"

	// ConditionTypeNotRunningExpectedly is true if NOT JobPotentiallyRunning, and both NOT ShouldBeRunning and NOT JobManuallyScheduled
	ConditionTypeNotRunningExpectedly ControlledJobConditionType = "NotRunningExpectedly"

	// ConditionTypeNotRunningUnexpectedly is true if NOT JobPotentiallyRunning, and either ShouldBeRunning or JobManuallyScheduled
	ConditionTypeNotRunningUnexpectedly ControlledJobConditionType = "NotRunningUnexpectedly"

	// ConditionTypeError records if the last attempt to reconcile generated an error, and if so what error
	ConditionTypeError ControlledJobConditionType = "Error"
)

type ControlledJobList

type ControlledJobList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []ControlledJob `json:"items"`
}

ControlledJobList contains a list of ControlledJob

func (*ControlledJobList) DeepCopy

func (in *ControlledJobList) DeepCopy() *ControlledJobList

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlledJobList.

func (*ControlledJobList) DeepCopyInto

func (in *ControlledJobList) DeepCopyInto(out *ControlledJobList)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*ControlledJobList) DeepCopyObject

func (in *ControlledJobList) DeepCopyObject() runtime.Object

DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.

type ControlledJobSpec

type ControlledJobSpec struct {

	// Timezone which governs the timing of all Events
	Timezone TimezoneSpec `json:"timezone"`

	// Events are a list of timings and operations to perform at those times. For example, 'start at 09:00', 'stop every hour on the half hour'
	Events []EventSpec `json:"events"`

	// Specifies the job that will be created when executing a CronJob. Uses the native Kubernetes JobTemplateSpec, and so supports all features
	// Kubernetes Jobs natively support
	JobTemplate batchv1beta1.JobTemplateSpec `json:"jobTemplate"`

	// Optional deadline in seconds for starting the job if it misses scheduled
	// time for any reason. In other words, if a new job is expected to be running, but it's more than
	// startingDeadlineSeconds after the scheduled start time, no job will be created.
	// If not set or set to < 1 this has no effect, and jobs will always be started however long after the start
	// time it is.
	// WARNING!!! Be aware that enabling this setting makes it impossible to restart a controlled job this number of seconds after
	// a scheduled start time. For example if the scheduled start time is 9am and this is set to 3600 (1h), then if you try to restart
	// the controlled job by deleting the current Job any time after 10am, it will have no effect.
	// +optional
	StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty"`

	// Specifies options on how to deal with job restart behaviour for various triggers
	// +optional
	RestartStrategy RestartStrategy `json:"restartStrategy,omitempty"`

	// This flag tells the controller to suspend subsequent executions, it does
	// not apply to already started executions.  Defaults to false.
	// Is also set by the controller when a job fails and should not be restarted.
	// +optional
	Suspend *bool `json:"suspend,omitempty"`
}

ControlledJobSpec defines the desired state of ControlledJob

func (*ControlledJobSpec) DeepCopy

func (in *ControlledJobSpec) DeepCopy() *ControlledJobSpec

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlledJobSpec.

func (*ControlledJobSpec) DeepCopyInto

func (in *ControlledJobSpec) DeepCopyInto(out *ControlledJobSpec)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type ControlledJobStatus

type ControlledJobStatus struct {

	// A list of pointers to currently running jobs.
	// +optional
	Active []corev1.ObjectReference `json:"active,omitempty"`

	// The most recent scheduled start time that was actioned
	// +optional
	LastScheduledStartTime *metav1.Time `json:"lastScheduledStartTime,omitempty"`

	// ShouldBeRunning is true if we're between a start/stop event
	// +optional
	ShouldBeRunning *bool `json:"shouldBeRunning,omitempty"`

	// IsRunning is true if there are any active events
	// +optional
	IsRunning *bool `json:"isRunning,omitempty"`

	// Set by the controller when a job fails and we shouldn't
	// restart it. Can be cleared by the user resetting the
	// spec.suspend flag
	// +optional
	IsSuspended *bool `json:"isSuspended,omitempty"`

	// MostRecentAction is the most recent action taken by this ControlledJob
	// +optional
	MostRecentAction *ControlledJobActionHistoryEntry `json:"mostRecentAction,omitempty"`

	// ActionHistory gives the recent history of actions taken by this ControlledJob
	// e.g. job started, job killed etc. in reverse chronological order
	// The number of recent actions is limited to 16
	// +optional
	ActionHistory []ControlledJobActionHistoryEntry `json:"actionHistory,omitempty"`

	// +listType=map
	// +listMapKey=type
	// +patchStrategy=merge
	// +patchMergeKey=type
	// +optional
	Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

ControlledJobStatus defines the observed state of ControlledJob

func (*ControlledJobStatus) DeepCopy

func (in *ControlledJobStatus) DeepCopy() *ControlledJobStatus

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlledJobStatus.

func (*ControlledJobStatus) DeepCopyInto

func (in *ControlledJobStatus) DeepCopyInto(out *ControlledJobStatus)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type EventSpec

type EventSpec struct {
	// Action to take at the specified time(s)
	Action EventType `json:"action"`

	// CronSchedule can contain an arbitrary Golang Cron Schedule
	// (see https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format)
	// If set, takes precedence over Schedule
	// +optional
	CronSchedule string `json:"cronSchedule,omitempty"`

	// Schedule is a more user friendly way to specify an event schedule
	// It's more limited than the format supported by CronSchedule
	Schedule *FriendlyScheduleSpec `json:"schedule,omitempty"`
}

A specific event in the schedule

func (*EventSpec) AsCronSpec

func (e *EventSpec) AsCronSpec() (string, error)

AsCronSpec presents the given EventSpec in CronTab format (as that's how the scheduling code needs to process it in). If a CronSchedule is provided, it is returned unaltered and un-validated. Otherwise we check against some regexes for validation before converting to a cron format

func (*EventSpec) DeepCopy

func (in *EventSpec) DeepCopy() *EventSpec

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EventSpec.

func (*EventSpec) DeepCopyInto

func (in *EventSpec) DeepCopyInto(out *EventSpec)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type EventType

type EventType string
const (
	EventTypeStart EventType = "start"
	EventTypeStop  EventType = "stop"
	// Restart not yet supported
	EventTypeRestart EventType = "restart"
)

type FailurePolicy

type FailurePolicy string
const (
	NeverRestartFailurePolicy  FailurePolicy = "NeverRestart"
	AlwaysRestartFailurePolicy FailurePolicy = "AlwaysRestart"
)

type FriendlyScheduleSpec

type FriendlyScheduleSpec struct {
	// TimeOfDay this event happens on the specified days
	// Format: hh:mm
	// +kubebuilder:validation:Pattern:=`^(\d{2}):(\d{2})$`
	TimeOfDay string `json:"timeOfDay"`

	// DaysOfWeek this event occurs on.
	// Either a comma separated list (MON,TUE,THU)
	// Or a range (MON-FRI)
	// +kubebuilder:validation:Pattern:=`(?:^([a-zA-Z]{3})(?:,([a-zA-Z]{3}))?(?:,([a-zA-Z]{3}))?(?:,([a-zA-Z]{3}))?(?:,([a-zA-Z]{3}))?(?:,([a-zA-Z]{3}))?(?:,([a-zA-Z]{3}))?)$|^(?P<startRange>[a-zA-Z]{3})-(?P<endRange>[a-zA-Z]{3}$)`
	DaysOfWeek string `json:"daysOfWeek"`
}

FriendlyScheduleSpec is a more user friendly way to specify an event schedule It's more limited than the format supported by CronSchedule

func (*FriendlyScheduleSpec) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FriendlyScheduleSpec.

func (*FriendlyScheduleSpec) DeepCopyInto

func (in *FriendlyScheduleSpec) DeepCopyInto(out *FriendlyScheduleSpec)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type RestartStrategy

type RestartStrategy struct {
	// SpecChangePolicy deals with policy to apply when the jobTemplate of the controlled job changes while it's running
	// Valid values are:
	//
	// - "Ignore": (default) Do nothing if spec of a job differs from spec of controlled job (next scheduled creation
	//     pick up the change)
	//
	// - "Recreate": If the job is currently running, stop it and wait for it to have completely stopped before starting
	//     a new job with the updated spec
	//
	// Note - the terminology here consciously mirrors that of a Deployment's Strategy:
	// https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy
	// +optional
	SpecChangePolicy SpecChangePolicy `json:"specChangePolicy,omitempty"`
}

func (*RestartStrategy) DeepCopy

func (in *RestartStrategy) DeepCopy() *RestartStrategy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RestartStrategy.

func (*RestartStrategy) DeepCopyInto

func (in *RestartStrategy) DeepCopyInto(out *RestartStrategy)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type SpecChangePolicy

type SpecChangePolicy string
const (
	// IgnoreSpecChangePolicy ignores changes to the job template while the job is running. The change
	// will be picked up the next time a Job is created
	IgnoreSpecChangePolicy SpecChangePolicy = "Ignore"
	// RecreateSpecChangePolicy will, when a change to the job template is detected, immediately kill any running Jobs,
	// wait for them to fully stop, and then create a new Job running the new specification
	RecreateSpecChangePolicy SpecChangePolicy = "Recreate"
)

type TimezoneSpec

type TimezoneSpec struct {
	// Name of the timezone in the tzData. See https://golang.org/pkg/time/#LoadLocation for possible values
	Name string `json:"name"`

	// Additional offset from UTC on top of the specified timezone. If the timezone is normally UTC-2, and
	// OffsetSeconds is +3600 (1h in seconds), then the overall effect will be UTC-1. If the timezone is
	// normally UTC+2 and OffsetSeconds is +3600, then the overall effect will be UTC+3.
	//
	// In practice - if you set this field to 60s on top of a normally UTC-1 timezone, then you end up with
	// a 'UTC-59m' timezone. In that timezone 10:00 UTC == 09:01 UTC-59m. So if you have a scheduled start time
	// of 09:00 in that UTC-59m timezone, your job will be started at 09:59 UTC
	//
	// +optional
	OffsetSeconds int32 `json:"offset"`
}

TimezoneSpec defines the timezone which governs scheduled times

func (*TimezoneSpec) DeepCopy

func (in *TimezoneSpec) DeepCopy() *TimezoneSpec

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimezoneSpec.

func (*TimezoneSpec) DeepCopyInto

func (in *TimezoneSpec) DeepCopyInto(out *TimezoneSpec)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

Jump to

Keyboard shortcuts

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