Skip to content

Commit

Permalink
Allow for filtering/sorting by reserved fields
Browse files Browse the repository at this point in the history
Certain fields like "type" in an object are reserved by
rancher/apiserver and so are transmuted to an underscore-prefixed
version of the field name, e.g. "_type", which is what appears in the
HTTP response output. Objects like Secrets, which have a built-in Type
field, are subject to this.

Without this patch, filtering and sorting are done on the object prior
to the field renaming, so filtering by "_type" would result in no
filtering happening even though the output returned to the user does
contain "_type". This change ensures that the field name changes happen
before filtering and sorting is started.
  • Loading branch information
cmurphy committed Sep 19, 2023
1 parent 6402cd4 commit 9376bdd
Show file tree
Hide file tree
Showing 4 changed files with 795 additions and 808 deletions.
19 changes: 8 additions & 11 deletions pkg/stores/partition/listprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,16 @@ func getLimit(apiOp *types.APIRequest) int {
return limit
}

// FilterList accepts a channel of unstructured objects and a slice of filters and returns the filtered list.
// FilterList accepts a slice of unstructured objects and a slice of filters and returns the filtered list.
// Filters are ANDed together.
func FilterList(list <-chan []unstructured.Unstructured, filters []OrFilter) []unstructured.Unstructured {
func FilterList(list []unstructured.Unstructured, filters []OrFilter) []unstructured.Unstructured {
if len(filters) == 0 {
return list
}
result := []unstructured.Unstructured{}
for items := range list {
for _, item := range items {
if len(filters) == 0 {
result = append(result, item)
continue
}
if matchesAll(item.Object, filters) {
result = append(result, item)
}
for _, item := range list {
if matchesAll(item.Object, filters) {
result = append(result, item)
}
}
return result
Expand Down
Loading

0 comments on commit 9376bdd

Please sign in to comment.