From cab5818bc74840818803f9779ae7e6887b56ca42 Mon Sep 17 00:00:00 2001 From: Kyle Brandt Date: Tue, 20 Aug 2024 12:32:16 -0400 Subject: [PATCH] Scopes: Add groups property to ScopeDashboardBinding (#92077) - Note: The `dashboardTitle` property and this property (`groups`) are likely to move from the `spec` container to the `status` container within the `scopeDashboardBinding` object in the future. --- pkg/apis/scope/v0alpha1/register.go | 2 ++ pkg/apis/scope/v0alpha1/types.go | 9 +++++++- .../scope/v0alpha1/zz_generated.deepcopy.go | 7 +++++- .../scope/v0alpha1/zz_generated.openapi.go | 22 ++++++++++++++++--- ...enerated.openapi_violation_exceptions.list | 1 + .../example-scope-dashboard-binding-abc.yaml | 4 +++- .../example-scope-dashboard-binding-xyz.yaml | 4 +++- 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/pkg/apis/scope/v0alpha1/register.go b/pkg/apis/scope/v0alpha1/register.go index 7d301cba8a9..660af02ec4a 100644 --- a/pkg/apis/scope/v0alpha1/register.go +++ b/pkg/apis/scope/v0alpha1/register.go @@ -53,6 +53,7 @@ var ScopeDashboardBindingResourceInfo = common.NewResourceInfo(GROUP, VERSION, {Name: "Created At", Type: "date"}, {Name: "Dashboard", Type: "string"}, {Name: "Scope", Type: "string"}, + {Name: "Groups", Type: "array"}, }, Reader: func(obj any) ([]interface{}, error) { m, ok := obj.(*ScopeDashboardBinding) @@ -64,6 +65,7 @@ var ScopeDashboardBindingResourceInfo = common.NewResourceInfo(GROUP, VERSION, m.CreationTimestamp.UTC().Format(time.RFC3339), m.Spec.Dashboard, m.Spec.Scope, + m.Spec.Groups, }, nil }, }, diff --git a/pkg/apis/scope/v0alpha1/types.go b/pkg/apis/scope/v0alpha1/types.go index 2683368d148..9064687ece0 100644 --- a/pkg/apis/scope/v0alpha1/types.go +++ b/pkg/apis/scope/v0alpha1/types.go @@ -60,9 +60,16 @@ type ScopeDashboardBinding struct { } type ScopeDashboardBindingSpec struct { - Dashboard string `json:"dashboard"` + Dashboard string `json:"dashboard"` + + // DashboardTitle should be populated and update from the dashboard DashboardTitle string `json:"dashboardTitle"` + // Groups is used for the grouping of dashboards that are suggested based + // on a scope. The source of truth for this information has not been + // determined yet. + Groups []string `json:"groups,omitempty"` + Scope string `json:"scope"` } diff --git a/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go b/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go index dcf457e6cef..a529a79ab15 100644 --- a/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/scope/v0alpha1/zz_generated.deepcopy.go @@ -108,7 +108,7 @@ func (in *ScopeDashboardBinding) DeepCopyInto(out *ScopeDashboardBinding) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) return } @@ -166,6 +166,11 @@ func (in *ScopeDashboardBindingList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ScopeDashboardBindingSpec) DeepCopyInto(out *ScopeDashboardBindingSpec) { *out = *in + if in.Groups != nil { + in, out := &in.Groups, &out.Groups + *out = make([]string, len(*in)) + copy(*out, *in) + } return } diff --git a/pkg/apis/scope/v0alpha1/zz_generated.openapi.go b/pkg/apis/scope/v0alpha1/zz_generated.openapi.go index 1bcc51f93a4..af5079a01a8 100644 --- a/pkg/apis/scope/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/scope/v0alpha1/zz_generated.openapi.go @@ -265,9 +265,25 @@ func schema_pkg_apis_scope_v0alpha1_ScopeDashboardBindingSpec(ref common.Referen }, "dashboardTitle": { SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", + Description: "DashboardTitle should be populated and update from the dashboard", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "groups": { + SchemaProps: spec.SchemaProps{ + Description: "Groups is used for the grouping of dashboards that are suggested based on a scope. The source of truth for this information has not been determined yet.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, }, }, "scope": { 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 e0fabd106cb..a50285a2a54 100644 --- a/pkg/apis/scope/v0alpha1/zz_generated.openapi_violation_exceptions.list +++ b/pkg/apis/scope/v0alpha1/zz_generated.openapi_violation_exceptions.list @@ -1,2 +1,3 @@ API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,FindScopeDashboardBindingsResults,Items +API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeDashboardBindingSpec,Groups API rule violation: names_match,github.com/grafana/grafana/pkg/apis/scope/v0alpha1,ScopeNodeSpec,LinkID diff --git a/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-abc.yaml b/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-abc.yaml index be175b5613b..d60eac1da96 100644 --- a/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-abc.yaml +++ b/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-abc.yaml @@ -4,4 +4,6 @@ metadata: name: example_abc spec: scope: example - dashboard: abc \ No newline at end of file + dashboard: abc + dashboardTitle: "Example Dashboard ABC" + groups: ["group1", "group2"] \ No newline at end of file diff --git a/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-xyz.yaml b/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-xyz.yaml index 98cfa8ed93f..1fd6306aa1b 100644 --- a/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-xyz.yaml +++ b/pkg/tests/apis/scopes/testdata/example-scope-dashboard-binding-xyz.yaml @@ -4,4 +4,6 @@ metadata: name: example_xyz spec: scope: example - dashboard: xyz \ No newline at end of file + dashboard: xyz + dashboardTitle: "Example Dashboard XYZ" + groups: ["group2", "group3"] \ No newline at end of file