Skip to content

Commit b214b07

Browse files
bergquistbfmatei
andauthored
Scopes: Name relationship objects *binding (#84955)
Signed-off-by: bergquist <carl.bergquist@gmail.com> Co-authored-by: Bogdan Matei <bogdan.matei@grafana.com>
1 parent c39b9b2 commit b214b07

File tree

9 files changed

+84
-69
lines changed

9 files changed

+84
-69
lines changed

pkg/apis/datasource/v0alpha1/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/query/v0alpha1/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/scope/v0alpha1/register.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ var ScopeResourceInfo = common.NewResourceInfo(GROUP, VERSION,
2222

2323
var ScopeDashboardResourceInfo = common.NewResourceInfo(GROUP, VERSION,
2424
"scopedashboards", "scopedashboard", "ScopeDashboard",
25-
func() runtime.Object { return &ScopeDashboard{} },
26-
func() runtime.Object { return &ScopeDashboardList{} },
25+
func() runtime.Object { return &ScopeDashboardBinding{} },
26+
func() runtime.Object { return &ScopeDashboardBindingList{} },
2727
)
2828

2929
var (
@@ -45,8 +45,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
4545
scheme.AddKnownTypes(SchemeGroupVersion,
4646
&Scope{},
4747
&ScopeList{},
48-
&ScopeDashboard{},
49-
&ScopeDashboardList{},
48+
&ScopeDashboardBinding{},
49+
&ScopeDashboardBindingList{},
5050
)
5151
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
5252
return nil

pkg/apis/scope/v0alpha1/types.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,33 @@ type Scope struct {
1313
}
1414

1515
type ScopeSpec struct {
16-
Title string `json:"title"`
17-
Type string `json:"type"`
18-
Description string `json:"description"`
19-
Category string `json:"category"`
20-
Filters []ScopeFilter `json:"filters"`
16+
Title string `json:"title"`
17+
Type string `json:"type"`
18+
Description string `json:"description"`
19+
Category string `json:"category"`
20+
21+
// +listType=atomic
22+
Filters []ScopeFilter `json:"filters"`
2123
}
2224

2325
type ScopeFilter struct {
24-
Key string `json:"key"`
25-
Value string `json:"value"`
26-
Operator string `json:"operator"`
26+
Key string `json:"key"`
27+
Value string `json:"value"`
28+
Operator FilterOperator `json:"operator"`
2729
}
2830

31+
// Type of the filter operator.
32+
// +enum
33+
type FilterOperator string
34+
35+
// Defines values for FilterOperator.
36+
const (
37+
FilterOperatorEquals FilterOperator = "equals"
38+
FilterOperatorNotEquals FilterOperator = "not-equals"
39+
FilterOperatorRegexMatch FilterOperator = "regex-match"
40+
FilterOperatorRegexNotMatch FilterOperator = "regex-not-match"
41+
)
42+
2943
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3044
type ScopeList struct {
3145
metav1.TypeMeta `json:",inline"`
@@ -35,22 +49,22 @@ type ScopeList struct {
3549
}
3650

3751
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
38-
type ScopeDashboard struct {
52+
type ScopeDashboardBinding struct {
3953
metav1.TypeMeta `json:",inline"`
4054
metav1.ObjectMeta `json:"metadata,omitempty"`
4155

42-
Spec ScopeDashboardSpec `json:"spec,omitempty"`
56+
Spec ScopeDashboardBindingSpec `json:"spec,omitempty"`
4357
}
4458

45-
type ScopeDashboardSpec struct {
46-
DashboardUIDs []string `json:"dashboardUids"`
47-
ScopeUID string `json:"scopeUid"`
59+
type ScopeDashboardBindingSpec struct {
60+
Dashboards []string `json:"dashboards"`
61+
Scope string `json:"scope"`
4862
}
4963

5064
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
51-
type ScopeDashboardList struct {
65+
type ScopeDashboardBindingList struct {
5266
metav1.TypeMeta `json:",inline"`
5367
metav1.ListMeta `json:"metadata,omitempty"`
5468

55-
Items []ScopeDashboard `json:"items,omitempty"`
69+
Items []ScopeDashboardBinding `json:"items,omitempty"`
5670
}

pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/scope/v0alpha1/zz_generated.openapi.go

Lines changed: 27 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardSpec,DashboardUIDs
2-
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeSpec,Filters
3-
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardSpec,DashboardUIDs
4-
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardSpec,ScopeUID
1+
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardBindingSpec,Dashboards

public/app/features/dashboard-scene/scene/ScopesDashboardsScene.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ export class ScopesDashboardsScene extends SceneObjectBase<ScopesDashboardsScene
5858
private async fetchDashboardsUids(scope: string): Promise<string[]> {
5959
try {
6060
const response = await getBackendSrv().get<{
61-
items: Array<{ spec: { dashboardUids: null | string[]; scopeUid: string } }>;
61+
items: Array<{ spec: { dashboards: null | string[]; scope: string } }>;
6262
}>(this._url, { scope });
6363

64-
return (
65-
response.items.find((item) => !!item.spec.dashboardUids && item.spec.scopeUid === scope)?.spec.dashboardUids ??
66-
[]
67-
);
64+
return response.items.find((item) => !!item.spec.dashboards && item.spec.scope === scope)?.spec.dashboards ?? [];
6865
} catch (err) {
6966
return [];
7067
}

public/app/features/dashboard-scene/scene/ScopesScene.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ jest.mock('@grafana/runtime', () => ({
9292
return {
9393
items: Object.values(scopesMocks).map((scope) => ({
9494
spec: {
95-
dashboardUids: scope.dashboards.map((dashboard) => dashboard.uid),
96-
scopeUid: scope.uid,
95+
dashboards: scope.dashboards.map((dashboard) => dashboard.uid),
96+
scope: scope.uid,
9797
},
9898
})),
9999
};

0 commit comments

Comments
 (0)