Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateJob when Job annotations or labels changed #919

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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