Scopes: Generate new field for default parent node (#108666)

* Generate new field for default parent node

* Update ScopeSpec with defaultPath and fix list types. Remove unused field

* Update frontend types

* Fix some errors

* ScopesSelector: Update zod types for spec schema

* Promlib: Update Scopes schema

---------

Co-authored-by: Matheus Macabu <macabu.matheus@gmail.com>
This commit is contained in:
Tobias Skarhed
2025-09-26 12:02:45 +02:00
committed by GitHub
co-authored by Matheus Macabu
parent 60fed679c4
commit eb16fa1642
14 changed files with 66 additions and 113 deletions
@@ -52,17 +52,22 @@ type Scope struct {
}
type ScopeSpec struct {
Title string `json:"title"`
Description string `json:"description"`
Title string `json:"title"`
// Provides a default path for the scope. This refers to a list of nodes in the selector. This is used to display the title next to the selected scope and expand the selector to the proper path.
// This will override whichever is selected from in the selector.
// The path is a list of node ids, starting at the direct parent of the selected node towards the root.
// +listType=atomic
DefaultPath []string `json:"defaultPath,omitempty"`
// +listType=atomic
Filters []ScopeFilter `json:"filters"`
Filters []ScopeFilter `json:"filters,omitempty"`
}
type ScopeFilter struct {
Key string `json:"key"`
Value string `json:"value"`
// Values is used for operators that require multiple values (e.g. one-of and not-one-of).
// +listType=atomic
Values []string `json:"values,omitempty"`
Operator FilterOperator `json:"operator"`
}
@@ -94,6 +94,11 @@ func (in *ScopeFilter) DeepCopy() *ScopeFilter {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ScopeSpec) DeepCopyInto(out *ScopeSpec) {
*out = *in
if in.DefaultPath != nil {
in, out := &in.DefaultPath, &out.DefaultPath
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Filters != nil {
in, out := &in.Filters, &out.Filters
*out = make([]ScopeFilter, len(*in))
@@ -200,6 +200,11 @@ func schema_apimachinery_apis_common_v0alpha1_ScopeFilter(ref common.ReferenceCa
},
},
"values": {
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-kubernetes-list-type": "atomic",
},
},
SchemaProps: spec.SchemaProps{
Description: "Values is used for operators that require multiple values (e.g. one-of and not-one-of).",
Type: []string{"array"},
@@ -243,11 +248,24 @@ func schema_apimachinery_apis_common_v0alpha1_ScopeSpec(ref common.ReferenceCall
Format: "",
},
},
"description": {
"defaultPath": {
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-kubernetes-list-type": "atomic",
},
},
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
Description: "Provides a default path for the scope. This refers to a list of nodes in the selector. This is used to display the title next to the selected scope and expand the selector to the proper path. This will override whichever is selected from in the selector. The path is a list of node ids, starting at the direct parent of the selected node towards the root.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
},
},
"filters": {
@@ -269,7 +287,7 @@ func schema_apimachinery_apis_common_v0alpha1_ScopeSpec(ref common.ReferenceCall
},
},
},
Required: []string{"title", "description", "filters"},
Required: []string{"title"},
},
},
Dependencies: []string{
@@ -1,4 +1,3 @@
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1,ScopeFilter,Values
API rule violation: names_match,github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1,Unstructured,Object
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,APIResourceList,APIResources
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Duration,Duration
+2 -4
View File
@@ -80,10 +80,8 @@ type PrometheusQueryProperties struct {
type ScopeSpec struct {
Name string `json:"name"` // This is the identifier from metadata.name of the scope model.
Title string `json:"title"`
Type string `json:"type"`
Description string `json:"description"`
Category string `json:"category"`
Filters []ScopeFilter `json:"filters"`
DefaultPath []string `json:"defaultPath,omitempty"`
Filters []ScopeFilter `json:"filters,omitempty"`
}
// ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go
+6 -13
View File
@@ -188,18 +188,14 @@
"type": "object",
"required": [
"name",
"title",
"type",
"description",
"category",
"filters"
"title"
],
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
"defaultPath": {
"type": "array",
"items": {
"type": "string"
}
},
"filters": {
"type": "array",
@@ -238,9 +234,6 @@
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"additionalProperties": false
+6 -13
View File
@@ -198,18 +198,14 @@
"type": "object",
"required": [
"name",
"title",
"type",
"description",
"category",
"filters"
"title"
],
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
"defaultPath": {
"type": "array",
"items": {
"type": "string"
}
},
"filters": {
"type": "array",
@@ -248,9 +244,6 @@
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"additionalProperties": false
+7 -14
View File
@@ -8,7 +8,7 @@
{
"metadata": {
"name": "default",
"resourceVersion": "1725885733879",
"resourceVersion": "1758739325095",
"creationTimestamp": "2024-03-25T13:19:04Z"
},
"spec": {
@@ -105,11 +105,11 @@
"additionalProperties": false,
"description": "ScopeSpec is a hand copy of the ScopeSpec struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix).",
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
"defaultPath": {
"items": {
"type": "string"
},
"type": "array"
},
"filters": {
"items": {
@@ -148,18 +148,11 @@
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
},
"required": [
"name",
"title",
"type",
"description",
"category",
"filters"
"title"
],
"type": "object"
},