Skip to content

Commit

Permalink
Merge pull request #919 from Thor-wl/0708-cherrypick
Browse files Browse the repository at this point in the history
UpdateJob when Job annotations or labels changed
  • Loading branch information
volcano-sh-bot authored Jul 8, 2020
2 parents eeb33e7 + 042c351 commit cb4aa33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
14 changes: 10 additions & 4 deletions pkg/controllers/job/job_controller_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ func (cc *Controller) updateJob(oldObj, newObj interface{}) {
return
}

// 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 {
klog.V(6).Infof("Job update event is ignored since no update in 'Spec'.")
// No need to update if ResourceVersion is not changed
if newJob.ResourceVersion == oldJob.ResourceVersion {
klog.V(6).Infof("No need to update because job is not modified.")
return
}

Expand All @@ -95,6 +94,13 @@ func (cc *Controller) updateJob(oldObj, newObj interface{}) {
newJob.Namespace, newJob.Name, err)
}

// 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 {
klog.V(6).Infof("Job update event is ignored since no update in 'Spec'.")
return
}

req := apis.Request{
Namespace: newJob.Namespace,
JobName: newJob.Name,
Expand Down
20 changes: 12 additions & 8 deletions pkg/controllers/job/job_controller_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ func TestUpdateJobFunc(t *testing.T) {
Name: "Job Update Success Case",
oldJob: &batch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job1",
Namespace: namespace,
Name: "job1",
Namespace: namespace,
ResourceVersion: "54467984",
},
Spec: batch.JobSpec{
SchedulerName: "volcano",
Expand All @@ -202,8 +203,9 @@ func TestUpdateJobFunc(t *testing.T) {
},
newJob: &batch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job1",
Namespace: namespace,
Name: "job1",
Namespace: namespace,
ResourceVersion: "54469999",
},
Spec: batch.JobSpec{
SchedulerName: "volcano",
Expand All @@ -220,8 +222,9 @@ func TestUpdateJobFunc(t *testing.T) {
Name: "Job Update Failure Case",
oldJob: &batch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job1",
Namespace: namespace,
Name: "job1",
Namespace: namespace,
ResourceVersion: "54469999",
},
Spec: batch.JobSpec{
SchedulerName: "volcano",
Expand All @@ -235,8 +238,9 @@ func TestUpdateJobFunc(t *testing.T) {
},
newJob: &batch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job1",
Namespace: namespace,
Name: "job1",
Namespace: namespace,
ResourceVersion: "54469999",
},
Spec: batch.JobSpec{
SchedulerName: "volcano",
Expand Down

0 comments on commit cb4aa33

Please sign in to comment.