1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-16 23:39:16 +00:00

#50914 - Changed ParseQuery projectornamespace Handling (#718)

* changed ParseQuery projectornamespace handling

* addressed comments from eric/chad and tom

* fixing lint error

* added resourceVersion to list

* updated mocks

* updated tests

* Update tests after rebase

---------

Co-authored-by: Tom Lebreux <tom.lebreux@suse.com>
This commit is contained in:
Felipe Gehrke
2025-07-17 14:51:13 -03:00
committed by GitHub
parent 0c2c554c8c
commit b556256ed3
8 changed files with 67 additions and 20 deletions

View File

@@ -4,6 +4,7 @@ package listprocessor
import (
"context"
"fmt"
"net/http"
"regexp"
"strconv"
"strings"
@@ -152,8 +153,9 @@ func ParseQuery(apiOp *types.APIRequest, namespaceCache Cache) (sqltypes.ListOpt
if err != nil {
return opts, err
}
if projOrNSFilters == nil {
return opts, apierror.NewAPIError(validation.NotFound, fmt.Sprintf("could not find any namespaces named [%s] or namespaces belonging to project named [%s]", projectsOrNamespaces, projectsOrNamespaces))
if len(projOrNSFilters) == 0 {
return opts, apierror.NewAPIError(validation.ErrorCode{Code: "No Data", Status: http.StatusNoContent},
fmt.Sprintf("could not find any namespaces named [%s] or namespaces belonging to project named [%s]", projectsOrNamespaces, projectsOrNamespaces))
}
if op == sqltypes.NotEq {
for _, filter := range projOrNSFilters {
@@ -182,7 +184,7 @@ func splitQuery(query string) []string {
}
func parseNamespaceOrProjectFilters(ctx context.Context, projOrNS string, op sqltypes.Op, namespaceInformer Cache) ([]sqltypes.Filter, error) {
var filters []sqltypes.Filter
filters := []sqltypes.Filter{}
for _, pn := range strings.Split(projOrNS, ",") {
uList, _, _, err := namespaceInformer.ListByOptions(ctx, &sqltypes.ListOptions{
Filters: []sqltypes.OrFilter{

View File

@@ -152,25 +152,14 @@ func TestParseQuery(t *testing.T) {
})
tests = append(tests, testCase{
description: "ParseQuery() with no errors returned should returned no errors. If projectsornamespaces is not empty" +
" and nsc does not return namespaces, an error should be returned.",
" and nsc does not return namespaces, it should return an empty filter array",
req: &types.APIRequest{
Request: &http.Request{
URL: &url.URL{RawQuery: "projectsornamespaces=somethin"},
},
},
expectedLO: sqltypes.ListOptions{
Filters: []sqltypes.OrFilter{
{
Filters: []sqltypes.Filter{
{
Field: []string{"metadata", "namespace"},
Matches: []string{"ns1"},
Op: sqltypes.Eq,
Partial: false,
},
},
},
},
Filters: []sqltypes.OrFilter{},
Pagination: sqltypes.Pagination{
Page: 1,
},