From b214b076958bd29adcfb8011604f938ca9d37a9c Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Tue, 26 Mar 2024 15:52:12 +0100 Subject: [PATCH] Scopes: Name relationship objects *binding (#84955) Signed-off-by: bergquist Co-authored-by: Bogdan Matei --- .../v0alpha1/zz_generated.openapi.go | 2 +- .../query/v0alpha1/zz_generated.openapi.go | 2 +- pkg/apis/scope/v0alpha1/register.go | 8 ++-- pkg/apis/scope/v0alpha1/types.go | 44 +++++++++++------ .../scope/v0alpha1/zz_generated.deepcopy.go | 34 +++++++------- .../scope/v0alpha1/zz_generated.openapi.go | 47 +++++++++++-------- ...enerated.openapi_violation_exceptions.list | 5 +- .../scene/ScopesDashboardsScene.tsx | 7 +-- .../scene/ScopesScene.test.tsx | 4 +- 9 files changed, 84 insertions(+), 69 deletions(-) diff --git a/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go b/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go index 1450dc98477..5a0f971e3d6 100644 --- a/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go @@ -162,7 +162,7 @@ func schema_pkg_apis_datasource_v0alpha1_HealthCheckResult(ref common.ReferenceC }, "details": { SchemaProps: spec.SchemaProps{ - Description: "Spec depends on the the plugin", + Description: "Spec depends on the plugin", Ref: ref("github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"), }, }, diff --git a/pkg/apis/query/v0alpha1/zz_generated.openapi.go b/pkg/apis/query/v0alpha1/zz_generated.openapi.go index 3c8db96187b..94065764f1e 100644 --- a/pkg/apis/query/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/query/v0alpha1/zz_generated.openapi.go @@ -268,7 +268,7 @@ func schema_pkg_apis_query_v0alpha1_QueryTypeDefinition(ref common.ReferenceCall return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "Generic query request with shared time across all values", + Description: "Defines a query behavior in a datasource. This is a similar model to a CRD where the payload describes a valid query", Type: []string{"object"}, Properties: map[string]spec.Schema{ "kind": { diff --git a/pkg/apis/scope/v0alpha1/register.go b/pkg/apis/scope/v0alpha1/register.go index 5868562a84a..ee14f12e019 100644 --- a/pkg/apis/scope/v0alpha1/register.go +++ b/pkg/apis/scope/v0alpha1/register.go @@ -22,8 +22,8 @@ var ScopeResourceInfo = common.NewResourceInfo(GROUP, VERSION, var ScopeDashboardResourceInfo = common.NewResourceInfo(GROUP, VERSION, "scopedashboards", "scopedashboard", "ScopeDashboard", - func() runtime.Object { return &ScopeDashboard{} }, - func() runtime.Object { return &ScopeDashboardList{} }, + func() runtime.Object { return &ScopeDashboardBinding{} }, + func() runtime.Object { return &ScopeDashboardBindingList{} }, ) var ( @@ -45,8 +45,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Scope{}, &ScopeList{}, - &ScopeDashboard{}, - &ScopeDashboardList{}, + &ScopeDashboardBinding{}, + &ScopeDashboardBindingList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/scope/v0alpha1/types.go b/pkg/apis/scope/v0alpha1/types.go index 9ed2bb0742e..e9594cf30d4 100644 --- a/pkg/apis/scope/v0alpha1/types.go +++ b/pkg/apis/scope/v0alpha1/types.go @@ -13,19 +13,33 @@ type Scope struct { } type ScopeSpec struct { - Title string `json:"title"` - Type string `json:"type"` - Description string `json:"description"` - Category string `json:"category"` - Filters []ScopeFilter `json:"filters"` + Title string `json:"title"` + Type string `json:"type"` + Description string `json:"description"` + Category string `json:"category"` + + // +listType=atomic + Filters []ScopeFilter `json:"filters"` } type ScopeFilter struct { - Key string `json:"key"` - Value string `json:"value"` - Operator string `json:"operator"` + Key string `json:"key"` + Value string `json:"value"` + Operator FilterOperator `json:"operator"` } +// Type of the filter operator. +// +enum +type FilterOperator string + +// Defines values for FilterOperator. +const ( + FilterOperatorEquals FilterOperator = "equals" + FilterOperatorNotEquals FilterOperator = "not-equals" + FilterOperatorRegexMatch FilterOperator = "regex-match" + FilterOperatorRegexNotMatch FilterOperator = "regex-not-match" +) + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type ScopeList struct { metav1.TypeMeta `json:",inline"` @@ -35,22 +49,22 @@ type ScopeList struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type ScopeDashboard struct { +type ScopeDashboardBinding struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ScopeDashboardSpec `json:"spec,omitempty"` + Spec ScopeDashboardBindingSpec `json:"spec,omitempty"` } -type ScopeDashboardSpec struct { - DashboardUIDs []string `json:"dashboardUids"` - ScopeUID string `json:"scopeUid"` +type ScopeDashboardBindingSpec struct { + Dashboards []string `json:"dashboards"` + Scope string `json:"scope"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type ScopeDashboardList struct { +type ScopeDashboardBindingList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []ScopeDashboard `json:"items,omitempty"` + Items []ScopeDashboardBinding `json:"items,omitempty"` } diff --git a/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go b/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go index 77bc6b7498e..82a254ef224 100644 --- a/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go @@ -39,7 +39,7 @@ func (in *Scope) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ScopeDashboard) DeepCopyInto(out *ScopeDashboard) { +func (in *ScopeDashboardBinding) DeepCopyInto(out *ScopeDashboardBinding) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -47,18 +47,18 @@ func (in *ScopeDashboard) DeepCopyInto(out *ScopeDashboard) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeDashboard. -func (in *ScopeDashboard) DeepCopy() *ScopeDashboard { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeDashboardBinding. +func (in *ScopeDashboardBinding) DeepCopy() *ScopeDashboardBinding { if in == nil { return nil } - out := new(ScopeDashboard) + out := new(ScopeDashboardBinding) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ScopeDashboard) DeepCopyObject() runtime.Object { +func (in *ScopeDashboardBinding) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -66,13 +66,13 @@ func (in *ScopeDashboard) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ScopeDashboardList) DeepCopyInto(out *ScopeDashboardList) { +func (in *ScopeDashboardBindingList) DeepCopyInto(out *ScopeDashboardBindingList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]ScopeDashboard, len(*in)) + *out = make([]ScopeDashboardBinding, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -80,18 +80,18 @@ func (in *ScopeDashboardList) DeepCopyInto(out *ScopeDashboardList) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeDashboardList. -func (in *ScopeDashboardList) DeepCopy() *ScopeDashboardList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeDashboardBindingList. +func (in *ScopeDashboardBindingList) DeepCopy() *ScopeDashboardBindingList { if in == nil { return nil } - out := new(ScopeDashboardList) + out := new(ScopeDashboardBindingList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ScopeDashboardList) DeepCopyObject() runtime.Object { +func (in *ScopeDashboardBindingList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -99,22 +99,22 @@ func (in *ScopeDashboardList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ScopeDashboardSpec) DeepCopyInto(out *ScopeDashboardSpec) { +func (in *ScopeDashboardBindingSpec) DeepCopyInto(out *ScopeDashboardBindingSpec) { *out = *in - if in.DashboardUIDs != nil { - in, out := &in.DashboardUIDs, &out.DashboardUIDs + if in.Dashboards != nil { + in, out := &in.Dashboards, &out.Dashboards *out = make([]string, len(*in)) copy(*out, *in) } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeDashboardSpec. -func (in *ScopeDashboardSpec) DeepCopy() *ScopeDashboardSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeDashboardBindingSpec. +func (in *ScopeDashboardBindingSpec) DeepCopy() *ScopeDashboardBindingSpec { if in == nil { return nil } - out := new(ScopeDashboardSpec) + out := new(ScopeDashboardBindingSpec) in.DeepCopyInto(out) return out } diff --git a/pkg/apis/scope/v0alpha1/zz_generated.openapi.go b/pkg/apis/scope/v0alpha1/zz_generated.openapi.go index 65f7bfdb5c8..ff517d31422 100644 --- a/pkg/apis/scope/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/scope/v0alpha1/zz_generated.openapi.go @@ -16,13 +16,13 @@ import ( func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.Scope": schema_pkg_apis_scope_v0alpha1_Scope(ref), - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboard": schema_pkg_apis_scope_v0alpha1_ScopeDashboard(ref), - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardList": schema_pkg_apis_scope_v0alpha1_ScopeDashboardList(ref), - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardSpec": schema_pkg_apis_scope_v0alpha1_ScopeDashboardSpec(ref), - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeFilter": schema_pkg_apis_scope_v0alpha1_ScopeFilter(ref), - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeList": schema_pkg_apis_scope_v0alpha1_ScopeList(ref), - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeSpec": schema_pkg_apis_scope_v0alpha1_ScopeSpec(ref), + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.Scope": schema_pkg_apis_scope_v0alpha1_Scope(ref), + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardBinding": schema_pkg_apis_scope_v0alpha1_ScopeDashboardBinding(ref), + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardBindingList": schema_pkg_apis_scope_v0alpha1_ScopeDashboardBindingList(ref), + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardBindingSpec": schema_pkg_apis_scope_v0alpha1_ScopeDashboardBindingSpec(ref), + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeFilter": schema_pkg_apis_scope_v0alpha1_ScopeFilter(ref), + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeList": schema_pkg_apis_scope_v0alpha1_ScopeList(ref), + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeSpec": schema_pkg_apis_scope_v0alpha1_ScopeSpec(ref), } } @@ -66,7 +66,7 @@ func schema_pkg_apis_scope_v0alpha1_Scope(ref common.ReferenceCallback) common.O } } -func schema_pkg_apis_scope_v0alpha1_ScopeDashboard(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_scope_v0alpha1_ScopeDashboardBinding(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -95,18 +95,18 @@ func schema_pkg_apis_scope_v0alpha1_ScopeDashboard(ref common.ReferenceCallback) "spec": { SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardSpec"), + Ref: ref("github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardBindingSpec"), }, }, }, }, }, Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardBindingSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, } } -func schema_pkg_apis_scope_v0alpha1_ScopeDashboardList(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_scope_v0alpha1_ScopeDashboardBindingList(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -139,7 +139,7 @@ func schema_pkg_apis_scope_v0alpha1_ScopeDashboardList(ref common.ReferenceCallb Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboard"), + Ref: ref("github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardBinding"), }, }, }, @@ -149,17 +149,17 @@ func schema_pkg_apis_scope_v0alpha1_ScopeDashboardList(ref common.ReferenceCallb }, }, Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboard", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + "github.com/grafana/grafana/pkg/apis/scope/v0alpha1.ScopeDashboardBinding", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, } } -func schema_pkg_apis_scope_v0alpha1_ScopeDashboardSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_scope_v0alpha1_ScopeDashboardBindingSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ - "dashboardUids": { + "dashboards": { SchemaProps: spec.SchemaProps{ Type: []string{"array"}, Items: &spec.SchemaOrArray{ @@ -173,7 +173,7 @@ func schema_pkg_apis_scope_v0alpha1_ScopeDashboardSpec(ref common.ReferenceCallb }, }, }, - "scopeUid": { + "scope": { SchemaProps: spec.SchemaProps{ Default: "", Type: []string{"string"}, @@ -181,7 +181,7 @@ func schema_pkg_apis_scope_v0alpha1_ScopeDashboardSpec(ref common.ReferenceCallb }, }, }, - Required: []string{"dashboardUids", "scopeUid"}, + Required: []string{"dashboards", "scope"}, }, }, } @@ -209,9 +209,11 @@ func schema_pkg_apis_scope_v0alpha1_ScopeFilter(ref common.ReferenceCallback) co }, "operator": { SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", + Description: "Possible enum values:\n - `\"equals\"`\n - `\"not-equals\"`\n - `\"regex-match\"`\n - `\"regex-not-match\"`", + Default: "", + Type: []string{"string"}, + Format: "", + Enum: []interface{}{"equals", "not-equals", "regex-match", "regex-not-match"}, }, }, }, @@ -303,6 +305,11 @@ func schema_pkg_apis_scope_v0alpha1_ScopeSpec(ref common.ReferenceCallback) comm }, }, "filters": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-list-type": "atomic", + }, + }, SchemaProps: spec.SchemaProps{ Type: []string{"array"}, Items: &spec.SchemaOrArray{ diff --git a/pkg/apis/scope/v0alpha1/zz_generated.openapi_violation_exceptions.list b/pkg/apis/scope/v0alpha1/zz_generated.openapi_violation_exceptions.list index 55e0bf15fe6..c72408369bf 100644 --- a/pkg/apis/scope/v0alpha1/zz_generated.openapi_violation_exceptions.list +++ b/pkg/apis/scope/v0alpha1/zz_generated.openapi_violation_exceptions.list @@ -1,4 +1 @@ -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardSpec,DashboardUIDs -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeSpec,Filters -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardSpec,DashboardUIDs -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardSpec,ScopeUID +API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardBindingSpec,Dashboards diff --git a/public/app/features/dashboard-scene/scene/ScopesDashboardsScene.tsx b/public/app/features/dashboard-scene/scene/ScopesDashboardsScene.tsx index 3bdd10c7940..b9c60e6fd9b 100644 --- a/public/app/features/dashboard-scene/scene/ScopesDashboardsScene.tsx +++ b/public/app/features/dashboard-scene/scene/ScopesDashboardsScene.tsx @@ -58,13 +58,10 @@ export class ScopesDashboardsScene extends SceneObjectBase { try { const response = await getBackendSrv().get<{ - items: Array<{ spec: { dashboardUids: null | string[]; scopeUid: string } }>; + items: Array<{ spec: { dashboards: null | string[]; scope: string } }>; }>(this._url, { scope }); - return ( - response.items.find((item) => !!item.spec.dashboardUids && item.spec.scopeUid === scope)?.spec.dashboardUids ?? - [] - ); + return response.items.find((item) => !!item.spec.dashboards && item.spec.scope === scope)?.spec.dashboards ?? []; } catch (err) { return []; } diff --git a/public/app/features/dashboard-scene/scene/ScopesScene.test.tsx b/public/app/features/dashboard-scene/scene/ScopesScene.test.tsx index 8c13906f5bf..0508c762ddc 100644 --- a/public/app/features/dashboard-scene/scene/ScopesScene.test.tsx +++ b/public/app/features/dashboard-scene/scene/ScopesScene.test.tsx @@ -92,8 +92,8 @@ jest.mock('@grafana/runtime', () => ({ return { items: Object.values(scopesMocks).map((scope) => ({ spec: { - dashboardUids: scope.dashboards.map((dashboard) => dashboard.uid), - scopeUid: scope.uid, + dashboards: scope.dashboards.map((dashboard) => dashboard.uid), + scope: scope.uid, }, })), };