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 18, 2023
1 parent 20f58ff commit a915db5
Show file tree
Hide file tree
Showing 4 changed files with 795 additions and 807 deletions.
18 changes: 8 additions & 10 deletions pkg/stores/partition/listprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,15 @@ func getLimit(apiOp *types.APIRequest) int {

// FilterList accepts a channel 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 {
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 len(filters) == 0 {
result = append(result, item)
continue
}
if matchesAll(item.Object, filters) {
result = append(result, item)
}
}
return result
Expand Down
Loading

0 comments on commit a915db5

Please sign in to comment.