// DoPortForwarding performs port forwarding for given podname to access test apps in the cluster
DoPortForwarding performs port forwarding for given podname to access test apps in the cluster
// DoPortForwarding performs port forwarding for given podname to access test apps in the cluster
func (m *AppManager) DoPortForwarding(podName string) error {
	podClient := m.client.Pods(m.namespace)
	podList, err := podClient.List(metav1.ListOptions{
		LabelSelector: fmt.Sprintf("%s=%s", TestAppLabelKey, m.app.AppName),
	})
	if err != nil {
		return err
	}
	name := podName
	if name == "" {
		for _, pod := range podList.Items {
			name = pod.Name
			break
		}
	}
	config := m.client.GetClientConfig()
	port, err := freeport.GetFreePort()
	if err != nil {
		return err
	}
	streams := genericclioptions.IOStreams{
		In:     os.Stdin,
		Out:    os.Stdout,
		ErrOut: os.Stderr,
	}
	err = startPortForwarding(PortForwardRequest{
		restConfig: config,
		pod: apiv1.Pod{
			ObjectMeta: metav1.ObjectMeta{
				Name:      name,
				Namespace: m.namespace,
			},
		},
		localPort:    port,
		podPort:      m.app.AppPort,
		streams:      streams,
		stopChannel:  m.stopChannel,
		readyChannel: m.readyChannel,
	})
	if err != nil {
		return err
	}
	<-m.readyChannel
	return nil
}
func ( m * AppManager ) DoPortForwarding ( podName string ) error { podClient := m . client . Pods ( m . namespace ) podList , err := podClient . List ( metav1 . ListOptions { LabelSelector : fmt . Sprintf ( " " , TestAppLabelKey , m . app . AppName ) , } ) if err != nil { return err } name := podName if name == " " { for _ , pod := range podList . Items { name = pod . Name break } } config := m . client . GetClientConfig ( ) port , err := freeport . GetFreePort ( ) if err != nil { return err } streams := genericclioptions . IOStreams { In : os . Stdin , Out : os . Stdout , ErrOut : os . Stderr , } err = startPortForwarding ( PortForwardRequest { restConfig : config , pod : apiv1 . Pod { ObjectMeta : metav1 . ObjectMeta { Name : name , Namespace : m . namespace , } , } , localPort : port , podPort : m . app . AppPort , streams : streams , stopChannel : m . stopChannel , readyChannel : m . readyChannel , } ) if err != nil { return err } <- m . readyChannel return nil }
DoPortForwarding performs port forwarding for given podname to access test apps in the cluster
DoPortForwarding performs port forwarding for given podname to access test apps in the cluster
// Filter only 'testapp=appName' labeled Pods // if given pod name is empty , pick the first matching pod name