From 56ed1919e2447280dcc3e61ce971075745f152ec Mon Sep 17 00:00:00 2001 From: Daniel F B Morinigo Date: Fri, 7 Feb 2025 14:39:11 +0800 Subject: [PATCH] fix: Issue in eventlisteners e2e when kubernetes host has a path Previously having a prefix into the server url would generate an error during testing due to url parsing of host with embeded path: parse "https://k8s.example.com%2Fkubernetes%2Fpath/api/v1/namespaces/arrakis-t7ss8/pods/el-my-eventlistener-848756bd88-sg8fv/portforward": invalid URL escape "%2F" Previously having a prefix into the server url would generate an error during testing due to url parsing of host with embeded path: --- test/eventlistener_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/eventlistener_test.go b/test/eventlistener_test.go index 420cbf1ab..c569e4857 100644 --- a/test/eventlistener_test.go +++ b/test/eventlistener_test.go @@ -29,7 +29,6 @@ import ( "os" "path/filepath" "strconv" - "strings" "testing" "time" @@ -429,9 +428,17 @@ func TestEventListenerCreate(t *testing.T) { return } - path := fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/portforward", namespace, podName) - hostIP := strings.TrimPrefix(config.Host, "https://") - serverURL := url.URL{Scheme: "https", Path: path, Host: hostIP} + // parsing the host to split host and path for + // cases where the host has a path prefix like https://host:8433/some/path + hostURL, err := url.Parse(config.Host) + if err != nil { + errChan <- err + return + } + + // adds back the already present path if it exists + path := fmt.Sprintf("%s/api/v1/namespaces/%s/pods/%s/portforward", hostURL.Path, namespace, podName) + serverURL := url.URL{Scheme: "https", Path: path, Host: hostURL.Host} dialer := spdy.NewDialer(upgrader, &http.Client{Transport: roundTripper}, http.MethodPost, &serverURL) out, errOut := new(Buffer), new(Buffer) readyChan := make(chan struct{}, 1)