Search: Fix field selector parsing (#114940)

This commit is contained in:
Ryan McKinley
2025-12-06 16:45:18 +03:00
committed by GitHub
parent 592c599ca6
commit 78b1ae4f27
2 changed files with 44 additions and 1 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ func toListRequest(k *resourcepb.ResourceKey, opts storage.ListOptions) (*resour
if r.Value != "" {
requirement.Values = append(requirement.Values, r.Value)
}
req.Options.Labels = append(req.Options.Labels, requirement)
req.Options.Fields = append(req.Options.Fields, requirement)
}
}
+43
View File
@@ -117,6 +117,49 @@ func TestToListRequest(t *testing.T) {
},
wantErr: nil,
},
{
name: "with field selector",
key: &resourcepb.ResourceKey{
Group: "test",
Resource: "test",
Namespace: "default",
},
opts: storage.ListOptions{
Predicate: storage.SelectionPredicate{
Label: labels.SelectorFromSet(labels.Set{"label": "A"}),
Field: fields.SelectorFromSet(fields.Set{"field": "B"}),
},
},
want: &resourcepb.ListRequest{
VersionMatchV2: 1,
Options: &resourcepb.ListOptions{
Key: &resourcepb.ResourceKey{
Group: "test",
Resource: "test",
Namespace: "default",
},
Labels: []*resourcepb.Requirement{
{
Key: "label",
Operator: string(selection.Equals),
Values: []string{"A"},
},
},
Fields: []*resourcepb.Requirement{
{
Key: "field",
Operator: string(selection.Equals),
Values: []string{"B"},
},
},
},
},
wantPredicate: storage.SelectionPredicate{
Label: labels.SelectorFromSet(labels.Set{"label": "A"}),
Field: fields.SelectorFromSet(fields.Set{"field": "B"}),
},
wantErr: nil,
},
{
name: "with trash label",
key: &resourcepb.ResourceKey{