code: func (o *AttachOptions) containerToAttachTo(pod *corev1.Pod) (*corev1.Container, error) {
  	if len(o.ContainerName) > 0 {
  		for i := range pod.Spec.Containers {
  			if pod.Spec.Containers[i].Name == o.ContainerName {
  				return &pod.Spec.Containers[i], nil
  			}
  		}
  		for i := range pod.Spec.InitContainers {
  			if pod.Spec.InitContainers[i].Name == o.ContainerName {
  				return &pod.Spec.InitContainers[i], nil
  			}
  		}
  		return nil, fmt.Errorf("container not found (%s)", o.ContainerName)
  	}
  
  	if len(o.SuggestedCmdUsage) > 0 {
  		fmt.Fprintf(o.ErrOut, "Defaulting container name to %s.\n", pod.Spec.Containers[0].Name)
  		fmt.Fprintf(o.ErrOut, "%s\n", o.SuggestedCmdUsage)
  	}
  
  	klog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)
  	return &pod.Spec.Containers[0], nil
  }
docs: // containerToAttach returns a reference to the container to attach to, given
  // by name or the first container if name is empty.