...

Source file src/github.com/redhat-developer/odo/pkg/kclient/port_forwarding.go

Documentation: github.com/redhat-developer/odo/pkg/kclient

     1  package kclient
     2  
     3  import (
     4  	"io"
     5  	"net/http"
     6  
     7  	corev1 "k8s.io/api/core/v1"
     8  	"k8s.io/client-go/tools/portforward"
     9  	"k8s.io/client-go/transport/spdy"
    10  )
    11  
    12  func (c *Client) SetupPortForwarding(pod *corev1.Pod, portPairs []string, out io.Writer, errOut io.Writer, stopChan chan struct{}, address string) error {
    13  	if address == "" {
    14  		address = "localhost"
    15  	}
    16  	transport, upgrader, err := spdy.RoundTripperFor(c.GetClientConfig())
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	req := c.GeneratePortForwardReq(pod.Name)
    22  
    23  	dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", req.URL())
    24  	// passing nil for readyChan because it's eventually being closed if it's not nil
    25  	// passing nil for out because we only care for error, not for output messages; we want to print our own messages
    26  	fw, err := portforward.NewOnAddresses(dialer, []string{address}, portPairs, stopChan, nil, out, errOut)
    27  	if err != nil {
    28  		return err
    29  	}
    30  
    31  	// start port-forwarding
    32  	err = fw.ForwardPorts()
    33  	if err != nil {
    34  		// do cleanup when this happens
    35  		// TODO: #5485
    36  		return err
    37  	}
    38  
    39  	return nil
    40  }
    41  

View as plain text