code: func (dc *DeploymentController) sync(d *apps.Deployment, rsList []*apps.ReplicaSet) error {
  	newRS, oldRSs, err := dc.getAllReplicaSetsAndSyncRevision(d, rsList, false)
  	if err != nil {
  		return err
  	}
  	if err := dc.scale(d, newRS, oldRSs); err != nil {
  		// If we get an error while trying to scale, the deployment will be requeued
  		// so we can abort this resync
  		return err
  	}
  
  	// Clean up the deployment when it's paused and no rollback is in flight.
  	if d.Spec.Paused && getRollbackTo(d) == nil {
  		if err := dc.cleanupDeployment(oldRSs, d); err != nil {
  			return err
  		}
  	}
  
  	allRSs := append(oldRSs, newRS)
  	return dc.syncDeploymentStatus(allRSs, newRS, d)
  }
docs: // sync is responsible for reconciling deployments on scaling events or when they
  // are paused.