From 22dbab97a8aa5ea0e83da85422cdd48e8950ab1c Mon Sep 17 00:00:00 2001 From: josunect Date: Wed, 19 Nov 2025 13:41:11 +0000 Subject: [PATCH 1/2] Allow kiali url with path Signed-off-by: josunect --- pkg/kiali/kiali.go | 25 +++++++++++++++++++++++-- pkg/kiali/kiali_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/pkg/kiali/kiali.go b/pkg/kiali/kiali.go index cf5c9284..8d40ce7d 100644 --- a/pkg/kiali/kiali.go +++ b/pkg/kiali/kiali.go @@ -53,11 +53,32 @@ func (k *Kiali) validateAndGetURL(endpoint string) (string, error) { if endpoint == "" { return baseURL.String(), nil } - ref, err := url.Parse(endpoint) + // Parse the endpoint to extract path, query, and fragment + endpoint = strings.TrimSpace(endpoint) + endpointURL, err := url.Parse(endpoint) + if err != nil { return "", fmt.Errorf("invalid endpoint path: %w", err) } - return baseURL.ResolveReference(ref).String(), nil + // Get the base path and endpoint path + basePath := strings.TrimSuffix(baseURL.Path, "/") + endpointPath := strings.TrimPrefix(endpointURL.Path, "/") + + // Concatenate paths, avoiding duplicate slashes + var fullPath string + if basePath == "" || basePath == "/" { + fullPath = "/" + endpointPath + } else { + fullPath = basePath + "/" + endpointPath + } + + // Reconstruct the URL with the concatenated path, preserving query and fragment + resultURL := *baseURL + resultURL.Path = fullPath + resultURL.RawQuery = endpointURL.RawQuery + resultURL.Fragment = endpointURL.Fragment + + return resultURL.String(), nil } func (k *Kiali) createHTTPClient() *http.Client { diff --git a/pkg/kiali/kiali_test.go b/pkg/kiali/kiali_test.go index fc08cb9f..5028c32b 100644 --- a/pkg/kiali/kiali_test.go +++ b/pkg/kiali/kiali_test.go @@ -98,6 +98,36 @@ func (s *KialiSuite) TestValidateAndGetURL() { s.Equal("2", u.Query().Get("y"), "Unexpected query parameter y") }) }) + + s.Run("With base URL containing path", func() { + s.Config = test.Must(config.ReadToml([]byte(` + [toolset_configs.kiali] + url = "http://kiali-istio-system.apps-crc.testing/kiali" + insecure = true + `))) + k := NewKiali(s.Config, s.MockServer.Config()) + + s.Run("concatenates base path with endpoint", func() { + full, err := k.validateAndGetURL("/api/namespaces") + s.Require().NoError(err, "Expected no error validating URL") + s.Equal("http://kiali-istio-system.apps-crc.testing/kiali/api/namespaces", full, "Unexpected full URL") + }) + + s.Run("handles endpoint without leading slash", func() { + full, err := k.validateAndGetURL("api/namespaces") + s.Require().NoError(err, "Expected no error validating URL") + s.Equal("http://kiali-istio-system.apps-crc.testing/kiali/api/namespaces", full, "Unexpected full URL") + }) + + s.Run("preserves query parameters with base path", func() { + full, err := k.validateAndGetURL("/api/namespaces?health=true") + s.Require().NoError(err, "Expected no error validating URL") + u, err := url.Parse(full) + s.Require().NoError(err, "Expected to parse full URL") + s.Equal("/kiali/api/namespaces", u.Path, "Unexpected path in parsed URL") + s.Equal("true", u.Query().Get("health"), "Unexpected query parameter health") + }) + }) } // CurrentAuthorizationHeader behavior is now implicit via executeRequest using Manager.BearerToken From b52241c9a724bef24dd54758d85040e3172e14b4 Mon Sep 17 00:00:00 2001 From: Josune Cordoba <49480155+josunect@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:05:15 +0000 Subject: [PATCH 2/2] Update pkg/kiali/kiali.go Co-authored-by: Calum Murray Signed-off-by: josunect --- pkg/kiali/kiali.go | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/pkg/kiali/kiali.go b/pkg/kiali/kiali.go index 8d40ce7d..5d777e8a 100644 --- a/pkg/kiali/kiali.go +++ b/pkg/kiali/kiali.go @@ -60,25 +60,16 @@ func (k *Kiali) validateAndGetURL(endpoint string) (string, error) { if err != nil { return "", fmt.Errorf("invalid endpoint path: %w", err) } - // Get the base path and endpoint path - basePath := strings.TrimSuffix(baseURL.Path, "/") - endpointPath := strings.TrimPrefix(endpointURL.Path, "/") - - // Concatenate paths, avoiding duplicate slashes - var fullPath string - if basePath == "" || basePath == "/" { - fullPath = "/" + endpointPath - } else { - fullPath = basePath + "/" + endpointPath + resultURL, err := url.JoinPath(baseURL.String(), endpointURL.Path) + if err != nil { + return "", fmt.Errorf("failed to join kiali base URL with endpoint path: %w", err) } - // Reconstruct the URL with the concatenated path, preserving query and fragment - resultURL := *baseURL - resultURL.Path = fullPath - resultURL.RawQuery = endpointURL.RawQuery - resultURL.Fragment = endpointURL.Fragment + u, _ := url.Parse(resultURL) + u.RawQuery = endpointURL.RawQuery + u.Fragment = endpointURL.Fragment - return resultURL.String(), nil + return u.String(), nil } func (k *Kiali) createHTTPClient() *http.Client {