code: func NewRSNewReplicas(deployment *apps.Deployment, allRSs []*apps.ReplicaSet, newRS *apps.ReplicaSet) (int32, error) {
  	switch deployment.Spec.Strategy.Type {
  	case apps.RollingUpdateDeploymentStrategyType:
  		// Check if we can scale up.
  		maxSurge, err := intstrutil.GetValueFromIntOrPercent(deployment.Spec.Strategy.RollingUpdate.MaxSurge, int(*(deployment.Spec.Replicas)), true)
  		if err != nil {
  			return 0, err
  		}
  		// Find the total number of pods
  		currentPodCount := GetReplicaCountForReplicaSets(allRSs)
  		maxTotalPods := *(deployment.Spec.Replicas) + int32(maxSurge)
  		if currentPodCount >= maxTotalPods {
  			// Cannot scale up.
  			return *(newRS.Spec.Replicas), nil
  		}
  		// Scale up.
  		scaleUpCount := maxTotalPods - currentPodCount
  		// Do not exceed the number of desired replicas.
  		scaleUpCount = int32(integer.IntMin(int(scaleUpCount), int(*(deployment.Spec.Replicas)-*(newRS.Spec.Replicas))))
  		return *(newRS.Spec.Replicas) + scaleUpCount, nil
  	case apps.RecreateDeploymentStrategyType:
  		return *(deployment.Spec.Replicas), nil
  	default:
  		return 0, fmt.Errorf("deployment type %v isn't supported", deployment.Spec.Strategy.Type)
  	}
  }
docs: // NewRSNewReplicas calculates the number of replicas a deployment's new RS should have.
  // When one of the followings is true, we're rolling out the deployment; otherwise, we're scaling it.
  // 1) The new RS is saturated: newRS's replicas == deployment's replicas
  // 2) Max number of pods allowed is reached: deployment's replicas + maxSurge == all RSs' replicas