mirror of
https://github.com/grafana/grafana.git
synced 2026-05-30 19:30:08 +09:00
GlobalVariables: Remove field selectors hack (#125566)
* bump grafana-app-sdk and remove field selectors hack * Regenerate enterprise_imports.go after SDK bump Run generate-enterprise-imports with enterprise main linked so CI go-workspace check passes.
This commit is contained in:
@@ -65,9 +65,6 @@ post-generate-cleanup: ## Clean up the generated code
|
||||
@echo "" >> ./pkg/apis/dashboard/v2/dashboard_spec.cue
|
||||
@cat ./kinds/v2/dashboard_spec.cue >> ./pkg/apis/dashboard/v2/dashboard_spec.cue
|
||||
|
||||
# Temporary workaround until grafana-app-sdk supports selectableFields through union parent paths.
|
||||
@bash ./cuehack/patch_variable_selectable_fields.sh ./pkg/apis/dashboard_manifest.go
|
||||
|
||||
@# Remove generated files for v1beta1 since it's a thin wrapper around v1
|
||||
@rm -f ./pkg/apis/dashboard/v1beta1/dashboard_codec_gen.go
|
||||
@rm -f ./pkg/apis/dashboard/v1beta1/dashboard_object_gen.go
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
manifest_path="${1:-./pkg/apis/dashboard_manifest.go}"
|
||||
|
||||
tmp_file="$(mktemp)"
|
||||
trap 'rm -f "$tmp_file"' EXIT
|
||||
|
||||
awk '
|
||||
BEGIN { patched = 0 }
|
||||
{
|
||||
print $0
|
||||
|
||||
if (!patched && $0 ~ /Schema: &versionSchemaVariablev2beta1,/) {
|
||||
if (getline nextline > 0) {
|
||||
if (nextline ~ /^[[:space:]]*SelectableFields: \[\]string\{/) {
|
||||
print nextline
|
||||
} else {
|
||||
print "\t\t\t\t\tSelectableFields: []string{"
|
||||
print "\t\t\t\t\t\t\"spec.spec.name\","
|
||||
print "\t\t\t\t\t},"
|
||||
print nextline
|
||||
}
|
||||
patched = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
' "$manifest_path" > "$tmp_file"
|
||||
|
||||
mv "$tmp_file" "$manifest_path"
|
||||
@@ -14,14 +14,9 @@ globalVariableV2beta1: {
|
||||
// - global: spec.spec.name
|
||||
// - folder: spec.spec.name + "--" + folderUID
|
||||
// - when metadata.name is provided, it must match the derived value.
|
||||
//TODO:
|
||||
// Adding selectableFields here causes the codegen to fail because it's a union parent path.
|
||||
// Until grafana-app-sdk supports selectableFields through union parent paths,
|
||||
// we're not adding it here and patching the manifest.go file instead with
|
||||
// apps/dashboard/cuehack/patch_variable_selectable_fields.sh
|
||||
// selectableFields: [
|
||||
// "spec.spec.name",
|
||||
// ]
|
||||
selectableFields: [
|
||||
"spec.spec.name",
|
||||
]
|
||||
validation: {
|
||||
operations: ["CREATE", "UPDATE"]
|
||||
}
|
||||
|
||||
@@ -5,13 +5,52 @@
|
||||
package v2beta1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/resource"
|
||||
)
|
||||
|
||||
// schema is unexported to prevent accidental overwrites
|
||||
var (
|
||||
schemaVariable = resource.NewSimpleSchema("dashboard.grafana.app", "v2beta1", NewVariable(), &VariableList{}, resource.WithKind("Variable"),
|
||||
resource.WithPlural("variables"), resource.WithScope(resource.NamespacedScope))
|
||||
resource.WithPlural("variables"), resource.WithScope(resource.NamespacedScope), resource.WithSelectableFields([]resource.SelectableField{{
|
||||
FieldSelector: "spec.spec.name",
|
||||
FieldValueFunc: func(o resource.Object) (string, error) {
|
||||
cast, ok := o.(*Variable)
|
||||
if !ok {
|
||||
return "", errors.New("provided object must be of type *Variable")
|
||||
}
|
||||
if cast.Spec.QueryVariableKind != nil {
|
||||
return string(cast.Spec.QueryVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.TextVariableKind != nil {
|
||||
return string(cast.Spec.TextVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.ConstantVariableKind != nil {
|
||||
return string(cast.Spec.ConstantVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.DatasourceVariableKind != nil {
|
||||
return string(cast.Spec.DatasourceVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.IntervalVariableKind != nil {
|
||||
return string(cast.Spec.IntervalVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.CustomVariableKind != nil {
|
||||
return string(cast.Spec.CustomVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.GroupByVariableKind != nil {
|
||||
return string(cast.Spec.GroupByVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.AdhocVariableKind != nil {
|
||||
return string(cast.Spec.AdhocVariableKind.Spec.Name), nil
|
||||
}
|
||||
if cast.Spec.SwitchVariableKind != nil {
|
||||
return string(cast.Spec.SwitchVariableKind.Spec.Name), nil
|
||||
}
|
||||
return "", nil
|
||||
},
|
||||
},
|
||||
}))
|
||||
kindVariable = resource.Kind{
|
||||
Schema: schemaVariable,
|
||||
Codecs: map[resource.KindEncoding]resource.Codec{
|
||||
|
||||
@@ -2184,12 +2184,15 @@ howett.net/plist v1.0.1 h1:37GdZ8tP09Q35o9ych3ehygcsL+HqKSwzctveSlarvM=
|
||||
howett.net/plist v1.0.1/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
|
||||
k8s.io/api v0.35.1/go.mod h1:28uR9xlXWml9eT0uaGo6y71xK86JBELShLy4wR1XtxM=
|
||||
k8s.io/api v0.35.3/go.mod h1:9Y9tkBcFwKNq2sxwZTQh1Njh9qHl81D0As56tu42GA4=
|
||||
k8s.io/api v0.36.0/go.mod h1:m1LVrGPNYax5NBHdO+QuAedXyuzTt4RryI/qnmNvs34=
|
||||
k8s.io/apiextensions-apiserver v0.35.1/go.mod h1:2CN4fe1GZ3HMe4wBr25qXyJnJyZaquy4nNlNmb3R7AQ=
|
||||
k8s.io/apimachinery v0.35.3/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns=
|
||||
k8s.io/apimachinery v0.35.4/go.mod h1:NNi1taPOpep0jOj+oRha3mBJPqvi0hGdaV8TCqGQ+cc=
|
||||
k8s.io/apimachinery v0.36.0/go.mod h1:FklypaRJt6n5wUIwWXIP6GJlIpUizTgfo1T/As+Tyxc=
|
||||
k8s.io/apiserver v0.35.1/go.mod h1:BiL6Dd3A2I/0lBnteXfWmCFobHM39vt5+hJQd7Lbpi4=
|
||||
k8s.io/client-go v0.35.1/go.mod h1:1p1KxDt3a0ruRfc/pG4qT/3oHmUj1AhSHEcxNSGg+OA=
|
||||
k8s.io/client-go v0.35.3/go.mod h1:RzoXkc0mzpWIDvBrRnD+VlfXP+lRzqQjCmKtiwZ8Q9c=
|
||||
k8s.io/client-go v0.36.0/go.mod h1:ZKKcpwF0aLYfkHFCjillCKaTK/yBkEDHTDXCFY6AS9Y=
|
||||
k8s.io/code-generator v0.36.0 h1:XWAkrhnArm0VWMmSFO7kyB+wE2LROwep7hEH0GPGkqA=
|
||||
k8s.io/code-generator v0.36.0/go.mod h1:Tr2UhfBRdlyRoadfob9aPCmmGe8PUs5XPK9MEJ2nx+w=
|
||||
k8s.io/component-base v0.35.1/go.mod h1:HI/6jXlwkiOL5zL9bqA3en1Ygv60F03oEpnuU1G56Bs=
|
||||
|
||||
@@ -347,8 +347,10 @@ import (
|
||||
_ "github.com/grafana/grafana/pkg/services/authz/rbac"
|
||||
_ "github.com/grafana/grafana/pkg/services/authz/zanzana"
|
||||
_ "github.com/grafana/grafana/pkg/services/authz/zanzana/common"
|
||||
_ "github.com/grafana/grafana/pkg/services/authz/zanzana/logger"
|
||||
_ "github.com/grafana/grafana/pkg/services/authz/zanzana/server/reconciler"
|
||||
_ "github.com/grafana/grafana/pkg/services/authz/zanzana/store"
|
||||
_ "github.com/grafana/grafana/pkg/services/authz/zanzana/store/migration"
|
||||
_ "github.com/grafana/grafana/pkg/services/caching"
|
||||
_ "github.com/grafana/grafana/pkg/services/cleanup"
|
||||
_ "github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||
@@ -578,6 +580,8 @@ import (
|
||||
_ "github.com/openfga/api/proto/openfga/v1"
|
||||
_ "github.com/openfga/openfga/pkg/storage"
|
||||
_ "github.com/openfga/openfga/pkg/storage/memory"
|
||||
_ "github.com/openfga/openfga/pkg/storage/postgres"
|
||||
_ "github.com/openfga/openfga/pkg/storage/sqlcommon"
|
||||
_ "github.com/patrickmn/go-cache"
|
||||
_ "github.com/prometheus/alertmanager/api/v2/models"
|
||||
_ "github.com/prometheus/alertmanager/pkg/labels"
|
||||
|
||||
Reference in New Issue
Block a user