with selectable fields
CodeQL checks / Detect whether code changed (push) Has been cancelled Details
CodeQL checks / Analyze (actions) (push) Has been cancelled Details
CodeQL checks / Analyze (go) (push) Has been cancelled Details
CodeQL checks / Analyze (javascript) (push) Has been cancelled Details

This commit is contained in:
Ryan McKinley 2025-10-06 17:54:32 +03:00
parent a24398a876
commit b5857ea669
4 changed files with 21 additions and 3 deletions

View File

@ -13,6 +13,9 @@ correlationsv0alpha1: {
type: CorrelationType
}
}
selectableFields: [
"spec.datasource.name"
]
}
DataSourceRef: {

View File

@ -5,13 +5,25 @@
package v0alpha1
import (
"fmt"
"github.com/grafana/grafana-app-sdk/resource"
)
// schema is unexported to prevent accidental overwrites
var (
schemaCorrelation = resource.NewSimpleSchema("correlations.grafana.app", "v0alpha1", &Correlation{}, &CorrelationList{}, resource.WithKind("Correlation"),
resource.WithPlural("correlations"), resource.WithScope(resource.NamespacedScope))
resource.WithPlural("correlations"), resource.WithScope(resource.NamespacedScope), resource.WithSelectableFields([]resource.SelectableField{{
FieldSelector: "spec.datasource.name",
FieldValueFunc: func(o resource.Object) (string, error) {
cast, ok := o.(*Correlation)
if !ok {
return "", fmt.Errorf("provided object must be of type *Correlation")
}
return cast.Spec.Datasource.Name, nil
},
},
}))
kindCorrelation = resource.Kind{
Schema: schemaCorrelation,
Codecs: map[resource.KindEncoding]resource.Codec{

View File

@ -39,6 +39,9 @@ var appManifestData = app.ManifestData{
Scope: "Namespaced",
Conversion: false,
Schema: &versionSchemaCorrelationv0alpha1,
SelectableFields: []string{
"spec.datasource.name",
},
},
},
Routes: app.ManifestVersionRoutes{

View File

@ -65,12 +65,12 @@ func (s *legacyStorage) List(ctx context.Context, options *internalversion.ListO
if options.FieldSelector != nil {
for _, r := range options.FieldSelector.Requirements() {
switch r.Field {
case "spec.datasource":
case "spec.datasource.name":
switch r.Operator {
case selection.Equals, selection.DoubleEquals:
uids = []string{r.Value}
case selection.In:
uids = strings.Split(r.Value, ";")
uids = strings.Split(r.Value, ";") // ??? not sure how/if this supports multiple values
default:
return nil, fmt.Errorf("unsupported operation")
}