code: func GetTargetNodeName(pod *v1.Pod) (string, error) {
  	if len(pod.Spec.NodeName) != 0 {
  		return pod.Spec.NodeName, nil
  	}
  
  	// If ScheduleDaemonSetPods was enabled before, retrieve node name of unscheduled pods from NodeAffinity
  	if pod.Spec.Affinity == nil ||
  		pod.Spec.Affinity.NodeAffinity == nil ||
  		pod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution == nil {
  		return "", fmt.Errorf("no spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution for pod %s/%s",
  			pod.Namespace, pod.Name)
  	}
  
  	terms := pod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms
  	if len(terms) < 1 {
  		return "", fmt.Errorf("no nodeSelectorTerms in requiredDuringSchedulingIgnoredDuringExecution of pod %s/%s",
  			pod.Namespace, pod.Name)
  	}
  
  	for _, term := range terms {
  		for _, exp := range term.MatchFields {
  			if exp.Key == schedulerapi.NodeFieldSelectorKeyNodeName &&
  				exp.Operator == v1.NodeSelectorOpIn {
  				if len(exp.Values) != 1 {
  					return "", fmt.Errorf("the matchFields value of '%s' is not unique for pod %s/%s",
  						schedulerapi.NodeFieldSelectorKeyNodeName, pod.Namespace, pod.Name)
  				}
  
  				return exp.Values[0], nil
  			}
  		}
  	}
  
  	return "", fmt.Errorf("no node name found for pod %s/%s", pod.Namespace, pod.Name)
  }
docs: // GetTargetNodeName get the target node name of DaemonSet pods. If `.spec.NodeName` is not empty (nil),
  // return `.spec.NodeName`; otherwise, retrieve node name of pending pods from NodeAffinity. Return error
  // if failed to retrieve node name from `.spec.NodeName` and NodeAffinity.