Skip to content

Commit

Permalink
Correctly sort pod to be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxuzhonghu committed May 7, 2020
1 parent b506707 commit 93faf93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/controllers/job/job_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package job
import (
"fmt"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -330,7 +332,11 @@ func (cc *Controller) syncJob(jobInfo *apis.JobInfo, updateStatus state.UpdateSt
// Delete pods when scale down.
// sort pods to be deleted from higher order to lower
sort.Slice(podToDelete, func(i, j int) bool {
return podToDelete[i].Name > podToDelete[j].Name
iName := strings.Split(podToDelete[i].Name, "-")
jName := strings.Split(podToDelete[j].Name, "-")
iIndex, _ := strconv.Atoi(iName[len(iName)-1])
jIndex, _ := strconv.Atoi(jName[len(jName)-1])
return iIndex > jIndex
})
// Delete unnecessary pods.
waitDeletionGroup := sync.WaitGroup{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/job/job_controller_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (cc *Controller) updateJob(oldObj, newObj interface{}) {

// NOTE: Since we only reconcile job based on Spec, we will ignore other attributes
// For Job status, it's used internally and always been updated via our controller.
if reflect.DeepEqual(newJob.Spec, oldJob.Spec) && newJob.Status.State.Phase == oldJob.Status.State.Phase {
if reflect.DeepEqual(newJob.Spec, oldJob.Spec) {
klog.V(6).Infof("Job update event is ignored since no update in 'Spec'.")
return
}
Expand Down

0 comments on commit 93faf93

Please sign in to comment.