Skip to content

Commit 36a2ecc

Browse files
Fix port-forward logic with Rancher URL in kubeconfig (#18)
Signed-off-by: Davide Rutigliano <davide.rutigliano@suse.com>
1 parent 104a483 commit 36a2ecc

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

internal/clients/k8s/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"net/url"
1111
"os"
12+
"path"
1213
"path/filepath"
1314

1415
appsv1 "k8s.io/api/apps/v1"
@@ -104,13 +105,14 @@ func (c *Client) PortForwardService(namespace, serviceName string, localPort, re
104105

105106
// PortForwardPod creates a port-forward to a specific pod
106107
func (c *Client) PortForwardPod(namespace, podName string, localPort, remotePort int) (chan struct{}, chan struct{}, error) {
107-
path := fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/portforward", namespace, podName)
108+
reqPath := fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/portforward", namespace, podName)
108109
hostIP := c.restConfig.Host
109110
pfURL, err := url.Parse(hostIP)
110111
if err != nil {
111112
return nil, nil, fmt.Errorf("failed to parse host: %w", err)
112113
}
113-
pfURL.Path = path
114+
// Preserve any existing path prefix (e.g. from Rancher/OpenShift proxy URLs)
115+
pfURL.Path = path.Join(pfURL.Path, reqPath)
114116

115117
transport, upgrader, err := spdy.RoundTripperFor(c.restConfig)
116118
if err != nil {

0 commit comments

Comments
 (0)