jobframework

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 33 Imported by: 2

Documentation

Index

Constants

View Source
const (
	FailedToStartFinishedReason = "FailedToStart"
)

Variables

View Source
var (
	ErrChildJobOwnerNotFound = fmt.Errorf("owner isn't set even though %s annotation is set", controllerconsts.ParentWorkloadAnnotation)
	ErrUnknownWorkloadOwner  = errors.New("workload owner is unknown")
	ErrWorkloadOwnerNotFound = errors.New("workload owner not found")
	ErrNoMatchingWorkloads   = errors.New("no matching workloads")
	ErrExtraWorkloads        = errors.New("extra workloads")
)
View Source
var DefaultOptions = Options{}

Functions

func ApplyDefaultForSuspend

func ApplyDefaultForSuspend(job GenericJob, manageJobsWithoutQueueName bool)

func ForEachIntegration added in v0.4.0

func ForEachIntegration(f func(name string, cb IntegrationCallbacks) error) error

ForEachIntegration loops through the registered list of frameworks calling f, if at any point f returns an error the loop is stopped and that error is returned.

func GetEmptyOwnerObject added in v0.4.0

func GetEmptyOwnerObject(owner *metav1.OwnerReference) client.Object

GetEmptyOwnerObject returns an empty object of the owner's type, returns nil if the owner is not manageable by kueue.

func GetIntegrationsList added in v0.4.0

func GetIntegrationsList() []string

GetIntegrationsList returns the list of currently registered frameworks.

func GetWorkloadNameForOwnerRef

func GetWorkloadNameForOwnerRef(owner *metav1.OwnerReference) (string, error)

func GetWorkloadNameForOwnerWithGVK

func GetWorkloadNameForOwnerWithGVK(ownerName string, ownerGVK schema.GroupVersionKind) string

func IsOwnerManagedByKueue added in v0.4.0

func IsOwnerManagedByKueue(owner *metav1.OwnerReference) bool

IsOwnerManagedByKueue returns true if the provided owner can be managed by kueue.

func ParentWorkloadName

func ParentWorkloadName(job GenericJob) string

func QueueName

func QueueName(job GenericJob) string

func QueueNameForObject added in v0.3.2

func QueueNameForObject(object client.Object) string

func RegisterIntegration added in v0.4.0

func RegisterIntegration(name string, cb IntegrationCallbacks) error

RegisterIntegration registers a new framework, returns an error when attempting to register multiple frameworks with the same name of if a mandatory callback is missing.

func SetupWorkloadOwnerIndex

func SetupWorkloadOwnerIndex(ctx context.Context, indexer client.FieldIndexer, gvk schema.GroupVersionKind) error

func ValidateAnnotationAsCRDName

func ValidateAnnotationAsCRDName(job GenericJob, crdNameAnnotation string) field.ErrorList

func ValidateCreateForParentWorkload added in v0.4.0

func ValidateCreateForParentWorkload(job GenericJob) field.ErrorList

func ValidateCreateForQueueName

func ValidateCreateForQueueName(job GenericJob) field.ErrorList

func ValidateUpdateForParentWorkload

func ValidateUpdateForParentWorkload(oldJob, newJob GenericJob) field.ErrorList

func ValidateUpdateForQueueName

func ValidateUpdateForQueueName(oldJob, newJob GenericJob) field.ErrorList

func ValidateUpdateForWorkloadPriorityClassName added in v0.5.0

func ValidateUpdateForWorkloadPriorityClassName(oldJob, newJob GenericJob) field.ErrorList

Types

type GenericJob

type GenericJob interface {
	// Object returns the job instance.
	Object() client.Object
	// IsSuspended returns whether the job is suspended or not.
	IsSuspended() bool
	// Suspend will suspend the job.
	Suspend()
	// RunWithPodSetsInfo will inject the node affinity and podSet counts extracting from workload to job and unsuspend it.
	RunWithPodSetsInfo(podSetsInfo []podset.PodSetInfo) error
	// RestorePodSetsInfo will restore the original node affinity and podSet counts of the job.
	// Returns whether any change was done.
	RestorePodSetsInfo(podSetsInfo []podset.PodSetInfo) bool
	// Finished means whether the job is completed/failed or not,
	// condition represents the workload finished condition.
	Finished() (condition metav1.Condition, finished bool)
	// PodSets will build workload podSets corresponding to the job.
	PodSets() []kueue.PodSet
	// IsActive returns true if there are any running pods.
	IsActive() bool
	// PodsReady instructs whether job derived pods are all ready now.
	PodsReady() bool
	// GVK returns GVK (Group Version Kind) for the job.
	GVK() schema.GroupVersionKind
}

GenericJob if the interface which needs to be implemented by all jobs managed by the kueue's jobframework.

type IntegrationCallbacks added in v0.4.0

type IntegrationCallbacks struct {
	// NewReconciler creates a new reconciler
	NewReconciler ReconcilerFactory
	// SetupWebhook sets up the framework's webhook with the controllers manager
	SetupWebhook func(mgr ctrl.Manager, opts ...Option) error
	// JobType holds an object of the type managed by the integration's webhook
	JobType runtime.Object
	// SetupIndexes registers any additional indexes with the controllers manager
	// (this callback is optional)
	SetupIndexes func(ctx context.Context, indexer client.FieldIndexer) error
	// AddToScheme adds any additional types to the controllers manager's scheme
	// (this callback is optional)
	AddToScheme func(s *runtime.Scheme) error
	// Returns true if the provided owner reference identifies an object
	// managed by this integration
	// (this callback is optional)
	IsManagingObjectsOwner func(ref *metav1.OwnerReference) bool
}

IntegrationCallbacks groups a set of callbacks used to integrate a new framework.

func GetIntegration added in v0.4.0

func GetIntegration(name string) (IntegrationCallbacks, bool)

GetIntegration looks-up the framework identified by name in the currently registered list of frameworks returning it's callbacks and true if found.

type JobReconciler

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

JobReconciler reconciles a GenericJob object

func NewReconciler

func NewReconciler(
	client client.Client,
	record record.EventRecorder,
	opts ...Option) *JobReconciler

func (*JobReconciler) IsParentJobManaged added in v0.4.0

func (r *JobReconciler) IsParentJobManaged(ctx context.Context, jobObj client.Object, namespace string) (bool, error)

IsParentJobManaged checks whether the parent job is managed by kueue.

func (*JobReconciler) ReconcileGenericJob

func (r *JobReconciler) ReconcileGenericJob(ctx context.Context, req ctrl.Request, job GenericJob) (ctrl.Result, error)

type JobReconcilerInterface added in v0.4.0

type JobReconcilerInterface interface {
	reconcile.Reconciler
	SetupWithManager(mgr ctrl.Manager) error
}

type JobWithCustomStop added in v0.4.0

type JobWithCustomStop interface {
	// Stop implements a custom stop procedure.
	// The function should be idempotent: not do any API calls if the job is already stopped.
	// Returns whether the Job stopped with this call or an error
	Stop(ctx context.Context, c client.Client, podSetsInfo []podset.PodSetInfo, eventMsg string) (bool, error)
}

type JobWithFinalize added in v0.5.0

type JobWithFinalize interface {
	Finalize(ctx context.Context, c client.Client) error
}

JobWithFinalize interface should be implemented by generic jobs, when custom finalization logic is needed for a job, after it's finished.

type JobWithPriorityClass added in v0.4.0

type JobWithPriorityClass interface {
	// PriorityClass returns the job's priority class name.
	PriorityClass() string
}

type JobWithReclaimablePods added in v0.4.0

type JobWithReclaimablePods interface {
	// ReclaimablePods returns the list of reclaimable pods.
	ReclaimablePods() []kueue.ReclaimablePod
}

type JobWithSkip added in v0.5.0

type JobWithSkip interface {
	Skip() bool
}

JobWithSkip interface should be implemented by generic jobs, when reconciliation should be skipped depending on the job's state

type Option

type Option func(*Options)

Option configures the reconciler.

func WithKubeServerVersion added in v0.5.0

func WithKubeServerVersion(v *kubeversion.ServerVersionFetcher) Option

func WithManageJobsWithoutQueueName

func WithManageJobsWithoutQueueName(f bool) Option

WithManageJobsWithoutQueueName indicates if the controller should reconcile jobs that don't set the queue name annotation.

func WithPodNamespaceSelector added in v0.5.0

func WithPodNamespaceSelector(s *metav1.LabelSelector) Option

WithPodNamespaceSelector adds rules to reconcile pods only in particular namespaces.

func WithPodSelector added in v0.5.0

func WithPodSelector(s *metav1.LabelSelector) Option

WithPodSelector adds rules to reconcile pods only with particular labels.

func WithWaitForPodsReady

func WithWaitForPodsReady(f bool) Option

WithWaitForPodsReady indicates if the controller should add the PodsReady condition to the workload when the corresponding job has all pods ready or succeeded.

type Options

type Options struct {
	ManageJobsWithoutQueueName bool
	WaitForPodsReady           bool
	KubeServerVersion          *kubeversion.ServerVersionFetcher
	PodNamespaceSelector       *metav1.LabelSelector
	PodSelector                *metav1.LabelSelector
}

type ReconcilerFactory added in v0.4.0

type ReconcilerFactory func(client client.Client, record record.EventRecorder, opts ...Option) JobReconcilerInterface

func NewGenericReconciler added in v0.4.0

func NewGenericReconciler(newJob func() GenericJob, newWorkloadHandler func(client.Client) handler.EventHandler) ReconcilerFactory

NewGenericReconciler creates a new reconciler factory for a concrete GenericJob type. newJob should return a new empty job. newWorkloadHandler it's optional, if added it should return a new workload event handler.

Jump to

Keyboard shortcuts

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