mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* Custom address for port forwarding Signed-off-by: Parthvi Vala <pvala@redhat.com> * Add integration tests Signed-off-by: Parthvi Vala <pvala@redhat.com> * Use private variables for custom address and ports Signed-off-by: Parthvi Vala <pvala@redhat.com> * Update pkg/util/util.go Co-authored-by: Armel Soro <armel@rm3l.org> * Assign custom address to HostIP for podman Signed-off-by: Parthvi Vala <pvala@redhat.com> * Add validation for free port when --port-forward is provided in the Validate() method, add integration test for running parallel dev sessions on same platform, same port and different addresses Signed-off-by: Parthvi Vala <pvala@redhat.com> * Fix unit test failure Signed-off-by: Parthvi Vala <pvala@redhat.com> * Attempt at fixing windows failure Signed-off-by: Parthvi Vala <pvala@redhat.com> * Add documentation Signed-off-by: Parthvi Vala <pvala@redhat.com> * Use default value for --address flag Signed-off-by: Parthvi Vala <pvala@redhat.com> * Changes from review Co-authored-by: Armel Soro <asoro@redhat.com> Signed-off-by: Parthvi Vala <pvala@redhat.com> --------- Signed-off-by: Parthvi Vala <pvala@redhat.com> Co-authored-by: Armel Soro <armel@rm3l.org> Co-authored-by: Armel Soro <asoro@redhat.com>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package kclient
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/client-go/tools/portforward"
|
|
"k8s.io/client-go/transport/spdy"
|
|
)
|
|
|
|
func (c *Client) SetupPortForwarding(pod *corev1.Pod, portPairs []string, out io.Writer, errOut io.Writer, stopChan chan struct{}, address string) error {
|
|
if address == "" {
|
|
address = "localhost"
|
|
}
|
|
transport, upgrader, err := spdy.RoundTripperFor(c.GetClientConfig())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
req := c.GeneratePortForwardReq(pod.Name)
|
|
|
|
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", req.URL())
|
|
// passing nil for readyChan because it's eventually being closed if it's not nil
|
|
// passing nil for out because we only care for error, not for output messages; we want to print our own messages
|
|
fw, err := portforward.NewOnAddresses(dialer, []string{address}, portPairs, stopChan, nil, out, errOut)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// start port-forwarding
|
|
err = fw.ForwardPorts()
|
|
if err != nil {
|
|
// do cleanup when this happens
|
|
// TODO: #5485
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|