func (t *Tunnel) findSuitablePodForService() (*corev1.Pod, error) {
	clientSet := kubernetes.New(t.client)
	service, err := clientSet.CoreV1().Services(t.Namespace).
		Get(context.TODO(), t.Target, meta.GetOptions{})
	if k8serrors.IsNotFound(err) {
		return nil, errors.NewNotFound(err, "can't find service "+t.Target)
	} else if err != nil {
		return nil, errors.Trace(err)
	}

	pods, err := clientSet.CoreV1().Pods(t.Namespace).
		List(context.TODO(), meta.ListOptions{
			LabelSelector: labels.SelectorFromSet(service.Spec.Selector).String(),
		})

	if err != nil {
		return nil, errors.Trace(err)
	}

	podCount := len(pods.Items)
	if podCount == 0 {
		return nil, errors.NotFoundf("pods for service %s", t.Target)
	} else if podCount == 1 {
		return &pods.Items[0], nil
	}

	return &pods.Items[rand.Intn(podCount-1)], nil
}
// findSuitablePodForService when tunneling to a kubernetes service we need to
// introspection.
findSuitablePodForService when tunneling to a kubernetes service we need to
introspection.
// findSuitablePodForService when tunneling to a kubernetes service we need to // introspection .
func (t *Tunnel) findSuitablePodForService() (*corev1.Pod, error) {
	clientSet := kubernetes.New(t.client)
	service, err := clientSet.CoreV1().Services(t.Namespace).
		Get(context.TODO(), t.Target, meta.GetOptions{})
	if k8serrors.IsNotFound(err) {
		return nil, errors.NewNotFound(err, "can't find service "+t.Target)
	} else if err != nil {
		return nil, errors.Trace(err)
	}
	pods, err := clientSet.CoreV1().Pods(t.Namespace).
		List(context.TODO(), meta.ListOptions{
			LabelSelector: labels.SelectorFromSet(service.Spec.Selector).String(),
		})
	if err != nil {
		return nil, errors.Trace(err)
	}
	podCount := len(pods.Items)
	if podCount == 0 {
		return nil, errors.NotFoundf("pods for service %s", t.Target)
	} else if podCount == 1 {
		return &pods.Items[0], nil
	}
	return &pods.Items[rand.Intn(podCount-1)], nil
}
func ( t * Tunnel ) findSuitablePodForService ( ) ( * corev1 . Pod , error ) { clientSet := kubernetes . New ( t . client ) service , err := clientSet . CoreV1 ( ) . Services ( t . Namespace ) . Get ( context . TODO ( ) , t . Target , meta . GetOptions { } ) if k8serrors . IsNotFound ( err ) { return nil , errors . NewNotFound ( err , " " + t . Target ) } else if err != nil { return nil , errors . Trace ( err ) } pods , err := clientSet . CoreV1 ( ) . Pods ( t . Namespace ) . List ( context . TODO ( ) , meta . ListOptions { LabelSelector : labels . SelectorFromSet ( service . Spec . Selector ) . String ( ) , } ) if err != nil { return nil , errors . Trace ( err ) } podCount := len ( pods . Items ) if podCount == 0 { return nil , errors . NotFoundf ( " " , t . Target ) } else if podCount == 1 { return & pods . Items [ 0 ] , nil } return & pods . Items [ rand . Intn ( podCount - 1 ) ] , nil }
findSuitablePodForService when tunneling to a kubernetes service we need to
introspection.
findSuitablePodForService when tunneling to a kubernetes service we need to introspection .