Skip to content

Commit

Permalink
Skip status update if no changes (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
xychu authored and k8s-ci-robot committed Mar 31, 2019
1 parent bd88c25 commit 41a650b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions pkg/controller.v1beta1/tensorflow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package tensorflow

import (
"fmt"
"reflect"
"time"

kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -339,6 +340,8 @@ func (tc *TFController) reconcileTFJobs(tfjob *tfv1beta1.TFJob) error {
logger := tflogger.LoggerForJob(tfjob)
logger.Infof("Reconcile TFJobs %s", tfjob.Name)

oldStatus := tfjob.Status.DeepCopy()

pods, err := tc.GetPodsForJob(tfjob)

if err != nil {
Expand Down Expand Up @@ -404,8 +407,11 @@ func (tc *TFController) reconcileTFJobs(tfjob *tfv1beta1.TFJob) error {
}
}

// TODO(CPH): Add check here, no need to update the tfjob if the status hasn't changed since last time.
return tc.updateStatusHandler(tfjob)
// no need to update the tfjob if the status hasn't changed since last time.
if !reflect.DeepEqual(*oldStatus, tfjob.Status) {
return tc.updateStatusHandler(tfjob)
}
return nil
}

// satisfiedExpectations returns true if the required adds/dels for the given tfjob have been observed.
Expand Down
10 changes: 8 additions & 2 deletions pkg/controller.v1beta2/tensorflow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package tensorflow

import (
"fmt"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -339,6 +340,8 @@ func (tc *TFController) reconcileTFJobs(tfjob *tfv1beta2.TFJob) error {
logger := tflogger.LoggerForJob(tfjob)
logger.Infof("Reconcile TFJobs %s", tfjob.Name)

oldStatus := tfjob.Status.DeepCopy()

pods, err := tc.GetPodsForJob(tfjob)

if err != nil {
Expand Down Expand Up @@ -455,8 +458,11 @@ func (tc *TFController) reconcileTFJobs(tfjob *tfv1beta2.TFJob) error {
}
}

// TODO(CPH): Add check here, no need to update the tfjob if the status hasn't changed since last time.
return tc.updateStatusHandler(tfjob)
// no need to update the tfjob if the status hasn't changed since last time.
if !reflect.DeepEqual(*oldStatus, tfjob.Status) {
return tc.updateStatusHandler(tfjob)
}
return nil
}

// satisfiedExpectations returns true if the required adds/dels for the given tfjob have been observed.
Expand Down

0 comments on commit 41a650b

Please sign in to comment.