Skip to content

Commit

Permalink
Update status only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmichalis committed Jun 20, 2016
1 parent 9dd3f6f commit 3d83c4f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions pkg/deploy/controller/deploymentconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,12 @@ func (c *DeploymentConfigController) reconcileDeployments(existingDeployments []
}

func (c *DeploymentConfigController) updateStatus(config *deployapi.DeploymentConfig) error {
if config.Generation > config.Status.ObservedGeneration {
config.Status.ObservedGeneration = config.Generation
// NOTE: We should update the status of the deployment config only if we need to, otherwise
// we hotloop between updates.
if !needsUpdate(config) {
return nil
}
config.Status.ObservedGeneration = config.Generation
if _, err := c.dn.DeploymentConfigs(config.Namespace).UpdateStatus(config); err != nil {
glog.V(2).Infof("Cannot update the status for %q: %v", deployutil.LabelForDeploymentConfig(config), err)
return transientError(err.Error())
Expand All @@ -300,18 +303,6 @@ func (c *DeploymentConfigController) updateStatus(config *deployapi.DeploymentCo
return nil
}

func deploymentCopy(rc *kapi.ReplicationController) (*kapi.ReplicationController, error) {
objCopy, err := kapi.Scheme.DeepCopy(rc)
if err != nil {
return nil, err
}
copied, ok := objCopy.(*kapi.ReplicationController)
if !ok {
return nil, fmt.Errorf("expected ReplicationController, got %#v", objCopy)
}
return copied, nil
}

func (c *DeploymentConfigController) handleErr(err error, key interface{}) {
if _, isFatal := err.(fatalError); isFatal {
utilruntime.HandleError(err)
Expand All @@ -325,3 +316,19 @@ func (c *DeploymentConfigController) handleErr(err error, key interface{}) {
}
utilruntime.HandleError(err)
}

func needsUpdate(config *deployapi.DeploymentConfig) bool {
return config.Generation > config.Status.ObservedGeneration

This comment has been minimized.

Copy link
@deads2k

deads2k Jun 20, 2016

Contributor

So is it correct/reasonable to do this check before enqueuing the work?

This comment has been minimized.

Copy link
@0xmichalis

0xmichalis Jun 20, 2016

Author Contributor

No because in #6233 we will need to count all pods, available pods, etc. and that needs to happen in the controller loop.

}

func deploymentCopy(rc *kapi.ReplicationController) (*kapi.ReplicationController, error) {
objCopy, err := kapi.Scheme.DeepCopy(rc)
if err != nil {
return nil, err
}
copied, ok := objCopy.(*kapi.ReplicationController)
if !ok {
return nil, fmt.Errorf("expected ReplicationController, got %#v", objCopy)
}
return copied, nil
}

0 comments on commit 3d83c4f

Please sign in to comment.