code: func (dc *DeploymentController) getReplicaSetsForDeployment(d *apps.Deployment) ([]*apps.ReplicaSet, error) {
  	// List all ReplicaSets to find those we own but that no longer match our
  	// selector. They will be orphaned by ClaimReplicaSets().
  	rsList, err := dc.rsLister.ReplicaSets(d.Namespace).List(labels.Everything())
  	if err != nil {
  		return nil, err
  	}
  	deploymentSelector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
  	if err != nil {
  		return nil, fmt.Errorf("deployment %s/%s has invalid label selector: %v", d.Namespace, d.Name, err)
  	}
  	// If any adoptions are attempted, we should first recheck for deletion with
  	// an uncached quorum read sometime after listing ReplicaSets (see #42639).
  	canAdoptFunc := controller.RecheckDeletionTimestamp(func() (metav1.Object, error) {
  		fresh, err := dc.client.AppsV1().Deployments(d.Namespace).Get(d.Name, metav1.GetOptions{})
  		if err != nil {
  			return nil, err
  		}
  		if fresh.UID != d.UID {
  			return nil, fmt.Errorf("original Deployment %v/%v is gone: got uid %v, wanted %v", d.Namespace, d.Name, fresh.UID, d.UID)
  		}
  		return fresh, nil
  	})
  	cm := controller.NewReplicaSetControllerRefManager(dc.rsControl, d, deploymentSelector, controllerKind, canAdoptFunc)
  	return cm.ClaimReplicaSets(rsList)
  }
docs: // getReplicaSetsForDeployment uses ControllerRefManager to reconcile
  // ControllerRef by adopting and orphaning.
  // It returns the list of ReplicaSets that this Deployment should manage.