code: func (dc *DeploymentController) rolloutRecreate(d *apps.Deployment, rsList []*apps.ReplicaSet, podMap map[types.UID]*v1.PodList) error {
  	// Don't create a new RS if not already existed, so that we avoid scaling up before scaling down.
  	newRS, oldRSs, err := dc.getAllReplicaSetsAndSyncRevision(d, rsList, false)
  	if err != nil {
  		return err
  	}
  	allRSs := append(oldRSs, newRS)
  	activeOldRSs := controller.FilterActiveReplicaSets(oldRSs)
  
  	// scale down old replica sets.
  	scaledDown, err := dc.scaleDownOldReplicaSetsForRecreate(activeOldRSs, d)
  	if err != nil {
  		return err
  	}
  	if scaledDown {
  		// Update DeploymentStatus.
  		return dc.syncRolloutStatus(allRSs, newRS, d)
  	}
  
  	// Do not process a deployment when it has old pods running.
  	if oldPodsRunning(newRS, oldRSs, podMap) {
  		return dc.syncRolloutStatus(allRSs, newRS, d)
  	}
  
  	// If we need to create a new RS, create it now.
  	if newRS == nil {
  		newRS, oldRSs, err = dc.getAllReplicaSetsAndSyncRevision(d, rsList, true)
  		if err != nil {
  			return err
  		}
  		allRSs = append(oldRSs, newRS)
  	}
  
  	// scale up new replica set.
  	if _, err := dc.scaleUpNewReplicaSetForRecreate(newRS, d); err != nil {
  		return err
  	}
  
  	if util.DeploymentComplete(d, &d.Status) {
  		if err := dc.cleanupDeployment(oldRSs, d); err != nil {
  			return err
  		}
  	}
  
  	// Sync deployment status.
  	return dc.syncRolloutStatus(allRSs, newRS, d)
  }
docs: // rolloutRecreate implements the logic for recreating a replica set.