diff --git a/pkg/sqlcache/sqltypes/types.go b/pkg/sqlcache/sqltypes/types.go index eecea863..6fae8d7b 100644 --- a/pkg/sqlcache/sqltypes/types.go +++ b/pkg/sqlcache/sqltypes/types.go @@ -25,11 +25,11 @@ const ( // ListOptions represents the query parameters that may be included in a list request. type ListOptions struct { - ChunkSize int - Resume string - Filters []OrFilter - SortList SortList - Pagination Pagination + ChunkSize int `json:"chunkSize"` + Resume string `json:"resume"` + Filters []OrFilter `json:"orFilters"` + SortList SortList `json:"sortList"` + Pagination Pagination `json:"pagination"` } // Filter represents a field to filter by. @@ -40,12 +40,12 @@ type ListOptions struct { // // If more than one value is given for the `Match` field, we do an "IN ()" test type Filter struct { - Field []string - Matches []string - Op Op - Partial bool - IsIndirect bool - IndirectFields []string + Field []string `json:"fields"` + Matches []string `json:"matches"` + Op Op `json:"op"` + Partial bool `json:"partial"` + IsIndirect bool `json:"isIndirect"` + IndirectFields []string `json:"indirectFields"` } // OrFilter represents a set of possible fields to filter by, where an item may match any filter in the set to be included in the result. @@ -59,20 +59,20 @@ type OrFilter struct { // The order is represented by prefixing the sort key by '-', e.g. sort=-metadata.name. // e.g. To sort internal clusters first followed by clusters in alpha order: sort=-spec.internal,spec.displayName type Sort struct { - Fields []string - Order SortOrder - IsIndirect bool - IndirectFields []string + Fields []string `json:"fields"` + Order SortOrder `json:"order"` + IsIndirect bool `json:"isIndirect"` + IndirectFields []string `json:"indirectFields"` } type SortList struct { - SortDirectives []Sort + SortDirectives []Sort `json:"sortDirectives"` } // Pagination represents how to return paginated results. type Pagination struct { - PageSize int - Page int + PageSize int `json:"pageSize"` + Page int `json:"page"` } func NewSortList() *SortList { diff --git a/pkg/stores/sqlpartition/listprocessor/processor.go b/pkg/stores/sqlpartition/listprocessor/processor.go index 7afd54e1..1e6813a3 100644 --- a/pkg/stores/sqlpartition/listprocessor/processor.go +++ b/pkg/stores/sqlpartition/listprocessor/processor.go @@ -73,11 +73,14 @@ func k8sRequirementToOrFilter(requirement queryparser.Requirement) (sqltypes.Fil values := requirement.Values() queryFields := splitQuery(requirement.Key()) op, usePartialMatch, err := k8sOpToRancherOp(requirement.Operator()) + isIndirect, indirectFields := requirement.IndirectInfo() return sqltypes.Filter{ - Field: queryFields, - Matches: values, - Op: op, - Partial: usePartialMatch, + Field: queryFields, + Matches: values, + Op: op, + Partial: usePartialMatch, + IsIndirect: isIndirect, + IndirectFields: indirectFields, }, err } diff --git a/pkg/stores/sqlpartition/listprocessor/processor_test.go b/pkg/stores/sqlpartition/listprocessor/processor_test.go index bc912cc1..92ba8af2 100644 --- a/pkg/stores/sqlpartition/listprocessor/processor_test.go +++ b/pkg/stores/sqlpartition/listprocessor/processor_test.go @@ -370,6 +370,33 @@ func TestParseQuery(t *testing.T) { }, }, }) + tests = append(tests, testCase{ + description: "ParseQuery() with an indirect labels filter param should create an indirect labels-specific filter.", + req: &types.APIRequest{ + Request: &http.Request{ + URL: &url.URL{RawQuery: "filter=metadata.labels[grover.example.com/fish]=>[_v1][Foods][foodCode][country]=japan"}, + }, + }, + expectedLO: sqltypes.ListOptions{ + ChunkSize: defaultLimit, + Filters: []sqltypes.OrFilter{ + { + Filters: []sqltypes.Filter{ + { + Field: []string{"metadata", "labels", "grover.example.com/fish"}, + Matches: []string{"japan"}, + Op: sqltypes.Eq, + IsIndirect: true, + IndirectFields: []string{"_v1", "Foods", "foodCode", "country"}, + }, + }, + }, + }, + Pagination: sqltypes.Pagination{ + Page: 1, + }, + }, + }) tests = append(tests, testCase{ description: "ParseQuery() with multiple filter params, should include multiple or filters.", req: &types.APIRequest{