mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scopes: Add more BE filtering (field selectors) (#85169)
This commit is contained in:
@@ -54,7 +54,7 @@ func (b *ScopeAPIBuilder) InstallSchema(scheme *runtime.Scheme) error {
|
||||
err = scheme.AddFieldLabelConversionFunc(
|
||||
scope.ScopeResourceInfo.GroupVersionKind(),
|
||||
func(label, value string) (string, string, error) {
|
||||
fieldSet := SelectableFields(&scope.Scope{})
|
||||
fieldSet := SelectableScopeFields(&scope.Scope{})
|
||||
for key := range fieldSet {
|
||||
if label == key {
|
||||
return label, value, nil
|
||||
@@ -67,6 +67,22 @@ func (b *ScopeAPIBuilder) InstallSchema(scheme *runtime.Scheme) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = scheme.AddFieldLabelConversionFunc(
|
||||
scope.ScopeDashboardResourceInfo.GroupVersionKind(),
|
||||
func(label, value string) (string, string, error) {
|
||||
fieldSet := SelectableScopeDashboardFields(&scope.ScopeDashboard{})
|
||||
for key := range fieldSet {
|
||||
if label == key {
|
||||
return label, value, nil
|
||||
}
|
||||
}
|
||||
return "", "", fmt.Errorf("field label not supported for %s: %s", scope.ScopeDashboardResourceInfo.GroupVersionKind(), label)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Link this version to the internal representation.
|
||||
// This is used for server-side-apply (PATCH), and avoids the error:
|
||||
// "no kind is registered for the type"
|
||||
|
||||
@@ -101,12 +101,13 @@ func newScopeDashboardStorage(scheme *runtime.Scheme, optsGetter generic.RESTOpt
|
||||
}
|
||||
|
||||
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
|
||||
s, ok := obj.(*scope.Scope)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("not a scope")
|
||||
if s, ok := obj.(*scope.Scope); ok {
|
||||
return labels.Set(s.Labels), SelectableScopeFields(s), nil
|
||||
}
|
||||
|
||||
return labels.Set(s.Labels), SelectableFields(s), nil
|
||||
if s, ok := obj.(*scope.ScopeDashboard); ok {
|
||||
return labels.Set(s.Labels), SelectableScopeDashboardFields(s), nil
|
||||
}
|
||||
return nil, nil, fmt.Errorf("not a scope or scopeDashboard object")
|
||||
}
|
||||
|
||||
// Matcher returns a generic.SelectionPredicate that matches on label and field selectors.
|
||||
@@ -118,8 +119,15 @@ func Matcher(label labels.Selector, field fields.Selector) apistore.SelectionPre
|
||||
}
|
||||
}
|
||||
|
||||
func SelectableFields(obj *scope.Scope) fields.Set {
|
||||
func SelectableScopeFields(obj *scope.Scope) fields.Set {
|
||||
return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), fields.Set{
|
||||
"spec.type": obj.Spec.Type,
|
||||
"spec.type": obj.Spec.Type,
|
||||
"spec.category": obj.Spec.Category,
|
||||
})
|
||||
}
|
||||
|
||||
func SelectableScopeDashboardFields(obj *scope.ScopeDashboard) fields.Set {
|
||||
return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), fields.Set{
|
||||
"spec.scopeUid": obj.Spec.ScopeUID,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user