code: func GetFirstPod(client coreclient.PodsGetter, namespace string, selector string, timeout time.Duration, sortBy func([]*corev1.Pod) sort.Interface) (*corev1.Pod, int, error) {
  	options := metav1.ListOptions{LabelSelector: selector}
  
  	podList, err := client.Pods(namespace).List(options)
  	if err != nil {
  		return nil, 0, err
  	}
  	pods := []*corev1.Pod{}
  	for i := range podList.Items {
  		pod := podList.Items[i]
  		pods = append(pods, &pod)
  	}
  	if len(pods) > 0 {
  		sort.Sort(sortBy(pods))
  		return pods[0], len(podList.Items), nil
  	}
  
  	// Watch until we observe a pod
  	options.ResourceVersion = podList.ResourceVersion
  	w, err := client.Pods(namespace).Watch(options)
  	if err != nil {
  		return nil, 0, err
  	}
  	defer w.Stop()
  
  	condition := func(event watch.Event) (bool, error) {
  		return event.Type == watch.Added || event.Type == watch.Modified, nil
  	}
  
  	ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), timeout)
  	defer cancel()
  	event, err := watchtools.UntilWithoutRetry(ctx, w, condition)
  	if err != nil {
  		return nil, 0, err
  	}
  	pod, ok := event.Object.(*corev1.Pod)
  	if !ok {
  		return nil, 0, fmt.Errorf("%#v is not a pod event", event)
  	}
  	return pod, 1, nil
  }
docs: // GetFirstPod returns a pod matching the namespace and label selector
  // and the number of all pods that match the label selector.