From c566e6af4e529036369beb31fdf5be02a59e8b5a Mon Sep 17 00:00:00 2001 From: Stephanie Hingtgen Date: Mon, 6 Jan 2025 14:41:45 -0700 Subject: [PATCH] K8s: Dashboards: Fix search parsing (#98560) --- pkg/registry/apis/dashboard/search.go | 8 +++++++- pkg/services/dashboards/service/dashboard_service.go | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/registry/apis/dashboard/search.go b/pkg/registry/apis/dashboard/search.go index 16e43feaed0..86427079b78 100644 --- a/pkg/registry/apis/dashboard/search.go +++ b/pkg/registry/apis/dashboard/search.go @@ -310,7 +310,13 @@ func (s *SearchHandler) DoSearch(w http.ResponseWriter, r *http.Request) { return } - s.write(w, dashboardsvc.ParseResults(result, searchRequest.Offset)) + parsedResults, err := dashboardsvc.ParseResults(result, searchRequest.Offset) + if err != nil { + errhttp.Write(ctx, err, w) + return + } + + s.write(w, parsedResults) } func (s *SearchHandler) write(w http.ResponseWriter, obj any) { diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index 81a56fb5462..57f708911a5 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -1360,7 +1360,7 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8sRaw(ctx context.Contex return nil, err } - return ParseResults(res, 0), nil + return ParseResults(res, 0) } func (dr *DashboardServiceImpl) searchDashboardsThroughK8s(ctx context.Context, query *dashboards.FindPersistedDashboardsQuery) ([]*dashboards.Dashboard, error) { @@ -1382,9 +1382,13 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8s(ctx context.Context, return result, nil } -func ParseResults(result *resource.ResourceSearchResponse, offset int64) *v0alpha1.SearchResults { +func ParseResults(result *resource.ResourceSearchResponse, offset int64) (*v0alpha1.SearchResults, error) { if result == nil { - return nil + return nil, nil + } else if result.Error != nil { + return nil, fmt.Errorf("%d error searching: %s: %s", result.Error.Code, result.Error.Message, result.Error.Details) + } else if result.Results == nil { + return nil, nil } titleIDX := 0 @@ -1455,7 +1459,7 @@ func ParseResults(result *resource.ResourceSearchResponse, offset int64) *v0alph } } - return sr + return sr, nil } func (dr *DashboardServiceImpl) UnstructuredToLegacyDashboard(ctx context.Context, item *unstructured.Unstructured, orgID int64) (*dashboards.Dashboard, error) {