Skip to content

Commit

Permalink
Deleted Job when PDB deleted.
Browse files Browse the repository at this point in the history
Signed-off-by: Da K. Ma <klaus1982.cn@gmail.com>
  • Loading branch information
k82cn committed Jul 9, 2018
1 parent 043dce2 commit 6f53327
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/scheduler/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ func MergeErrors(errs ...error) error {

// JobTerminated checkes whether job was terminated.
func JobTerminated(job *JobInfo) bool {
return job.SchedSpec == nil && len(job.Tasks) == 0
return job.SchedSpec == nil &&
job.PDB == nil &&
len(job.Tasks) == 0
}
4 changes: 4 additions & 0 deletions pkg/scheduler/api/job_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func (ps *JobInfo) SetPDB(pbd *policyv1.PodDisruptionBudget) {
ps.PDB = pbd
}

func (ps *JobInfo) UnsetPDB() {
ps.PDB = nil
}

func (ps *JobInfo) GetTasks(statuses ...TaskStatus) []*TaskInfo {
var res []*TaskInfo

Expand Down
19 changes: 15 additions & 4 deletions pkg/scheduler/cache/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ func (sc *SchedulerCache) deleteSchedulingSpec(ss *arbv1.SchedulingSpec) error {
// Unset SchedulingSpec
job.UnsetSchedulingSpec()

// TODO (k82cn): find another way to clean up Job.
sc.deleteJob(job)

return nil
Expand Down Expand Up @@ -456,12 +455,24 @@ func (sc *SchedulerCache) setPDB(pdb *policyv1.PodDisruptionBudget) error {
}

// Assumes that lock is already acquired.
func (sc *SchedulerCache) updatePDB(oldQueue, newQueue *policyv1.PodDisruptionBudget) error {
return sc.setPDB(newQueue)
func (sc *SchedulerCache) updatePDB(oldPDB, newPDB *policyv1.PodDisruptionBudget) error {
return sc.setPDB(newPDB)
}

// Assumes that lock is already acquired.
func (sc *SchedulerCache) deletePDB(queue *policyv1.PodDisruptionBudget) error {
func (sc *SchedulerCache) deletePDB(pdb *policyv1.PodDisruptionBudget) error {
jobID := arbapi.JobID(utils.GetController(pdb))

job, found := sc.Jobs[jobID]
if !found {
return fmt.Errorf("can not found job %v:%v/%v", jobID, pdb.Namespace, pdb.Name)
}

// Unset SchedulingSpec
job.UnsetPDB()

sc.deleteJob(job)

return nil
}

Expand Down

0 comments on commit 6f53327

Please sign in to comment.