From 11c1e3d6ce37a5204c1537b8400b5cc0443c7a63 Mon Sep 17 00:00:00 2001 From: xiaoxubeii Date: Mon, 4 Jul 2022 17:22:57 +0800 Subject: [PATCH] Add job suspend semantics. --- pkg/apis/common/v1/interface.go | 3 +++ pkg/controller.v1/common/job.go | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/apis/common/v1/interface.go b/pkg/apis/common/v1/interface.go index 39e95d31..f9113485 100644 --- a/pkg/apis/common/v1/interface.go +++ b/pkg/apis/common/v1/interface.go @@ -70,4 +70,7 @@ type ControllerInterface interface { // It will requeue the job in case of an error while creating/deleting services. // Common implementation will be provided and User can still override this to implement their own reconcile logic ReconcileServices(job metav1.Object, services []*v1.Service, rtype ReplicaType, spec *ReplicaSpec) error + + // JobSuspended checks jobs whether suspended or not + JobSuspended(job interface{}) (*bool, error) } diff --git a/pkg/controller.v1/common/job.go b/pkg/controller.v1/common/job.go index fe2b836a..39e8b289 100644 --- a/pkg/controller.v1/common/job.go +++ b/pkg/controller.v1/common/job.go @@ -95,7 +95,11 @@ func (jc *JobController) ReconcileJobs( } oldStatus := jobStatus.DeepCopy() - if commonutil.IsSucceeded(jobStatus) || commonutil.IsFailed(jobStatus) { + jobSuspended, err := jc.Controller.JobSuspended(job) + if err != nil { + return err + } + if commonutil.IsSucceeded(jobStatus) || commonutil.IsFailed(jobStatus) || (jobSuspended != nil && *jobSuspended) { // If the Job is succeed or failed, delete all pods and services. if err := jc.DeletePodsAndServices(runPolicy, job, pods); err != nil { return err @@ -357,3 +361,8 @@ func (jc *JobController) CleanupJob(runPolicy *apiv1.RunPolicy, jobStatus apiv1. func (jc *JobController) calcPGMinResources(minMember int32, replicas map[apiv1.ReplicaType]*apiv1.ReplicaSpec) *v1.ResourceList { return CalcPGMinResources(minMember, replicas, jc.PriorityClassLister.Get) } + +func (jc *JobController) JobSuspended(job interface{}) (*bool, error) { + log.Infof("Not implemented.") + return nil, nil +}