K8s/Dashboards: Generate Dashboards k8s APIs using Grafana App SDK (#99966)

* Generate Dashboard kinds with `grafana-app-sdk`

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Hack together a fix for invalid TS codegen for v0 & v1

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Address Go linter issues

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Address TS linter issues

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Add new app to CODEOWNERS

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Fix a couple of issues detected by tests

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Update OpenAPI definitions and test files

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Remove title from Dashboard v1alpha1 spec

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Remove unused CUE schemas

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* remove unrelated files

* allow any in the generated betterer

* Add a comment explaining why we don't use deepcopy-gen

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Default to v2alpha1 if dashboards v2 FF is enabled

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

---------

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Igor Suleymanov
2025-03-11 13:00:37 +02:00
committed by GitHub
co-authored by Ryan McKinley
parent 3fffb2872e
commit ea89a68028
81 changed files with 11452 additions and 679 deletions
@@ -47,79 +47,127 @@ func RegisterConversions(s *runtime.Scheme) error {
func Convert_V0_to_V1(in *dashboardV0.Dashboard, out *dashboardV1.Dashboard, scope conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Spec = in.Spec
out.Status = &dashboardV1.DashboardStatus{
ConversionStatus: &dashboardV1.ConversionStatus{
out.Spec.Object = in.Spec.Object
out.Status = dashboardV1.DashboardStatus{
Conversion: &dashboardV1.DashboardConversionStatus{
StoredVersion: dashboardV0.VERSION,
},
}
err := migration.Migrate(out.Spec.Object, schemaversion.LATEST_VERSION)
if err != nil {
out.Status.ConversionStatus.Failed = true
out.Status.ConversionStatus.Error = err.Error()
if err := migration.Migrate(out.Spec.Object, schemaversion.LATEST_VERSION); err != nil {
out.Status.Conversion.Failed = true
out.Status.Conversion.Error = err.Error()
}
return nil
}
func Convert_V0_to_V2(in *dashboardV0.Dashboard, out *dashboardV2.Dashboard, scope conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Spec = in.Spec
out.Status = &dashboardV2.DashboardStatus{
ConversionStatus: &dashboardV2.ConversionStatus{
// TODO (@radiohead): implement V0 to V2 conversion
// This is the bare minimum conversion that is needed to make the dashboard servable.
if v, ok := in.Spec.Object["title"]; ok {
if title, ok := v.(string); ok {
out.Spec.Title = title
}
}
// We need to make sure the layout is set to some value, otherwise the JSON marshaling will fail.
out.Spec.Layout = dashboardV2.DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind{
GridLayoutKind: &dashboardV2.DashboardGridLayoutKind{
Kind: "GridLayout",
Spec: dashboardV2.DashboardGridLayoutSpec{},
},
}
out.Status = dashboardV2.DashboardStatus{
Conversion: &dashboardV2.DashboardConversionStatus{
StoredVersion: dashboardV0.VERSION,
Failed: true,
Error: "backend conversion not yet implemented",
},
}
return nil
}
func Convert_V1_to_V0(in *dashboardV1.Dashboard, out *dashboardV0.Dashboard, scope conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Spec = in.Spec
out.Status = &dashboardV0.DashboardStatus{
ConversionStatus: &dashboardV0.ConversionStatus{
out.Spec.Object = in.Spec.Object
out.Status = dashboardV0.DashboardStatus{
Conversion: &dashboardV0.DashboardConversionStatus{
StoredVersion: dashboardV1.VERSION,
},
}
return nil
}
func Convert_V1_to_V2(in *dashboardV1.Dashboard, out *dashboardV2.Dashboard, scope conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Spec = in.Spec
out.Status = &dashboardV2.DashboardStatus{
ConversionStatus: &dashboardV2.ConversionStatus{
// TODO (@radiohead): implement V1 to V2 conversion
// This is the bare minimum conversion that is needed to make the dashboard servable.
if v, ok := in.Spec.Object["title"]; ok {
if title, ok := v.(string); ok {
out.Spec.Title = title
}
}
// We need to make sure the layout is set to some value, otherwise the JSON marshaling will fail.
out.Spec.Layout = dashboardV2.DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind{
GridLayoutKind: &dashboardV2.DashboardGridLayoutKind{
Kind: "GridLayout",
Spec: dashboardV2.DashboardGridLayoutSpec{},
},
}
out.Status = dashboardV2.DashboardStatus{
Conversion: &dashboardV2.DashboardConversionStatus{
StoredVersion: dashboardV1.VERSION,
Failed: true,
Error: "backend conversion not yet implemented",
},
}
return nil
}
func Convert_V2_to_V0(in *dashboardV2.Dashboard, out *dashboardV0.Dashboard, scope conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Spec = in.Spec
out.Status = &dashboardV0.DashboardStatus{
ConversionStatus: &dashboardV0.ConversionStatus{
// TODO: implement V2 to V0 conversion
out.Status = dashboardV0.DashboardStatus{
Conversion: &dashboardV0.DashboardConversionStatus{
StoredVersion: dashboardV2.VERSION,
Failed: true,
Error: "backend conversion not yet implemented",
},
}
return nil
}
func Convert_V2_to_V1(in *dashboardV2.Dashboard, out *dashboardV1.Dashboard, scope conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Spec = in.Spec
out.Status = &dashboardV1.DashboardStatus{
ConversionStatus: &dashboardV1.ConversionStatus{
// TODO: implement V2 to V1 conversion
out.Status = dashboardV1.DashboardStatus{
Conversion: &dashboardV1.DashboardConversionStatus{
StoredVersion: dashboardV2.VERSION,
Failed: true,
Error: "backend conversion not yet implemented",
},
}
return nil
}
+18
View File
@@ -0,0 +1,18 @@
package v0alpha1
import "k8s.io/apimachinery/pkg/runtime/schema"
const (
// Group is the API group used by all kinds in this package
Group = "dashboard.grafana.app"
// Version is the API version used by all kinds in this package
Version = "v0alpha1"
)
var (
// GroupVersion is a schema.GroupVersion consisting of the Group and Version constants for this package
GroupVersion = schema.GroupVersion{
Group: Group,
Version: Version,
}
)
@@ -0,0 +1,28 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v0alpha1
import (
"encoding/json"
"io"
"github.com/grafana/grafana-app-sdk/resource"
)
// DashboardJSONCodec is an implementation of resource.Codec for kubernetes JSON encoding
type DashboardJSONCodec struct{}
// Read reads JSON-encoded bytes from `reader` and unmarshals them into `into`
func (*DashboardJSONCodec) Read(reader io.Reader, into resource.Object) error {
return json.NewDecoder(reader).Decode(into)
}
// Write writes JSON-encoded bytes into `writer` marshaled from `from`
func (*DashboardJSONCodec) Write(writer io.Writer, from resource.Object) error {
return json.NewEncoder(writer).Encode(from)
}
// Interface compliance checks
var _ resource.Codec = &DashboardJSONCodec{}
@@ -0,0 +1,28 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v0alpha1
import (
time "time"
)
// metadata contains embedded CommonMetadata and can be extended with custom string fields
// TODO: use CommonMetadata instead of redefining here; currently needs to be defined here
// without external reference as using the CommonMetadata reference breaks thema codegen.
type DashboardMetadata struct {
UpdateTimestamp time.Time `json:"updateTimestamp"`
CreatedBy string `json:"createdBy"`
Uid string `json:"uid"`
CreationTimestamp time.Time `json:"creationTimestamp"`
DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"`
Finalizers []string `json:"finalizers"`
ResourceVersion string `json:"resourceVersion"`
Generation int64 `json:"generation"`
UpdatedBy string `json:"updatedBy"`
Labels map[string]string `json:"labels"`
}
// NewDashboardMetadata creates a new DashboardMetadata object.
func NewDashboardMetadata() *DashboardMetadata {
return &DashboardMetadata{}
}
@@ -0,0 +1,269 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v0alpha1
import (
"fmt"
"github.com/grafana/grafana-app-sdk/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"time"
)
// +k8s:openapi-gen=true
type Dashboard struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ObjectMeta `json:"metadata" yaml:"metadata"`
// Spec is the spec of the Dashboard
Spec DashboardSpec `json:"spec" yaml:"spec"`
Status DashboardStatus `json:"status" yaml:"status"`
}
func (o *Dashboard) GetSpec() any {
return o.Spec
}
func (o *Dashboard) SetSpec(spec any) error {
cast, ok := spec.(DashboardSpec)
if !ok {
return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec)
}
o.Spec = cast
return nil
}
func (o *Dashboard) GetSubresources() map[string]any {
return map[string]any{
"status": o.Status,
}
}
func (o *Dashboard) GetSubresource(name string) (any, bool) {
switch name {
case "status":
return o.Status, true
default:
return nil, false
}
}
func (o *Dashboard) SetSubresource(name string, value any) error {
switch name {
case "status":
cast, ok := value.(DashboardStatus)
if !ok {
return fmt.Errorf("cannot set status type %#v, not of type DashboardStatus", value)
}
o.Status = cast
return nil
default:
return fmt.Errorf("subresource '%s' does not exist", name)
}
}
func (o *Dashboard) GetStaticMetadata() resource.StaticMetadata {
gvk := o.GroupVersionKind()
return resource.StaticMetadata{
Name: o.ObjectMeta.Name,
Namespace: o.ObjectMeta.Namespace,
Group: gvk.Group,
Version: gvk.Version,
Kind: gvk.Kind,
}
}
func (o *Dashboard) SetStaticMetadata(metadata resource.StaticMetadata) {
o.Name = metadata.Name
o.Namespace = metadata.Namespace
o.SetGroupVersionKind(schema.GroupVersionKind{
Group: metadata.Group,
Version: metadata.Version,
Kind: metadata.Kind,
})
}
func (o *Dashboard) GetCommonMetadata() resource.CommonMetadata {
dt := o.DeletionTimestamp
var deletionTimestamp *time.Time
if dt != nil {
deletionTimestamp = &dt.Time
}
// Legacy ExtraFields support
extraFields := make(map[string]any)
if o.Annotations != nil {
extraFields["annotations"] = o.Annotations
}
if o.ManagedFields != nil {
extraFields["managedFields"] = o.ManagedFields
}
if o.OwnerReferences != nil {
extraFields["ownerReferences"] = o.OwnerReferences
}
return resource.CommonMetadata{
UID: string(o.UID),
ResourceVersion: o.ResourceVersion,
Generation: o.Generation,
Labels: o.Labels,
CreationTimestamp: o.CreationTimestamp.Time,
DeletionTimestamp: deletionTimestamp,
Finalizers: o.Finalizers,
UpdateTimestamp: o.GetUpdateTimestamp(),
CreatedBy: o.GetCreatedBy(),
UpdatedBy: o.GetUpdatedBy(),
ExtraFields: extraFields,
}
}
func (o *Dashboard) SetCommonMetadata(metadata resource.CommonMetadata) {
o.UID = types.UID(metadata.UID)
o.ResourceVersion = metadata.ResourceVersion
o.Generation = metadata.Generation
o.Labels = metadata.Labels
o.CreationTimestamp = metav1.NewTime(metadata.CreationTimestamp)
if metadata.DeletionTimestamp != nil {
dt := metav1.NewTime(*metadata.DeletionTimestamp)
o.DeletionTimestamp = &dt
} else {
o.DeletionTimestamp = nil
}
o.Finalizers = metadata.Finalizers
if o.Annotations == nil {
o.Annotations = make(map[string]string)
}
if !metadata.UpdateTimestamp.IsZero() {
o.SetUpdateTimestamp(metadata.UpdateTimestamp)
}
if metadata.CreatedBy != "" {
o.SetCreatedBy(metadata.CreatedBy)
}
if metadata.UpdatedBy != "" {
o.SetUpdatedBy(metadata.UpdatedBy)
}
// Legacy support for setting Annotations, ManagedFields, and OwnerReferences via ExtraFields
if metadata.ExtraFields != nil {
if annotations, ok := metadata.ExtraFields["annotations"]; ok {
if cast, ok := annotations.(map[string]string); ok {
o.Annotations = cast
}
}
if managedFields, ok := metadata.ExtraFields["managedFields"]; ok {
if cast, ok := managedFields.([]metav1.ManagedFieldsEntry); ok {
o.ManagedFields = cast
}
}
if ownerReferences, ok := metadata.ExtraFields["ownerReferences"]; ok {
if cast, ok := ownerReferences.([]metav1.OwnerReference); ok {
o.OwnerReferences = cast
}
}
}
}
func (o *Dashboard) GetCreatedBy() string {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
return o.ObjectMeta.Annotations["grafana.com/createdBy"]
}
func (o *Dashboard) SetCreatedBy(createdBy string) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy
}
func (o *Dashboard) GetUpdateTimestamp() time.Time {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"])
return parsed
}
func (o *Dashboard) SetUpdateTimestamp(updateTimestamp time.Time) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339)
}
func (o *Dashboard) GetUpdatedBy() string {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
return o.ObjectMeta.Annotations["grafana.com/updatedBy"]
}
func (o *Dashboard) SetUpdatedBy(updatedBy string) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy
}
func (o *Dashboard) Copy() resource.Object {
return resource.CopyObject(o)
}
func (o *Dashboard) DeepCopyObject() runtime.Object {
return o.Copy()
}
// Interface compliance compile-time check
var _ resource.Object = &Dashboard{}
// +k8s:openapi-gen=true
type DashboardList struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata" yaml:"metadata"`
Items []Dashboard `json:"items" yaml:"items"`
}
func (o *DashboardList) DeepCopyObject() runtime.Object {
return o.Copy()
}
func (o *DashboardList) Copy() resource.ListObject {
cpy := &DashboardList{
TypeMeta: o.TypeMeta,
Items: make([]Dashboard, len(o.Items)),
}
o.ListMeta.DeepCopyInto(&cpy.ListMeta)
for i := 0; i < len(o.Items); i++ {
if item, ok := o.Items[i].Copy().(*Dashboard); ok {
cpy.Items[i] = *item
}
}
return cpy
}
func (o *DashboardList) GetItems() []resource.Object {
items := make([]resource.Object, len(o.Items))
for i := 0; i < len(o.Items); i++ {
items[i] = &o.Items[i]
}
return items
}
func (o *DashboardList) SetItems(items []resource.Object) {
o.Items = make([]Dashboard, len(items))
for i := 0; i < len(items); i++ {
o.Items[i] = *items[i].(*Dashboard)
}
}
// Interface compliance compile-time check
var _ resource.ListObject = &DashboardList{}
@@ -0,0 +1,34 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v0alpha1
import (
"github.com/grafana/grafana-app-sdk/resource"
)
// schema is unexported to prevent accidental overwrites
var (
schemaDashboard = resource.NewSimpleSchema("dashboard.grafana.app", "v0alpha1", &Dashboard{}, &DashboardList{}, resource.WithKind("Dashboard"),
resource.WithPlural("dashboards"), resource.WithScope(resource.NamespacedScope))
kindDashboard = resource.Kind{
Schema: schemaDashboard,
Codecs: map[resource.KindEncoding]resource.Codec{
resource.KindEncodingJSON: &DashboardJSONCodec{},
},
}
)
// Kind returns a resource.Kind for this Schema with a JSON codec
func DashboardKind() resource.Kind {
return kindDashboard
}
// Schema returns a resource.SimpleSchema representation of Dashboard
func DashboardSchema() *resource.SimpleSchema {
return schemaDashboard
}
// Interface compliance checks
var _ resource.Schema = kindDashboard
@@ -0,0 +1,13 @@
package v0alpha1
import (
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
)
// +k8s:openapi-gen=true
type DashboardSpec = common.Unstructured
// NewDashboardSpec creates a new Spec object.
func NewDashboardSpec() *DashboardSpec {
return &DashboardSpec{}
}
@@ -0,0 +1,3 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v0alpha1
@@ -0,0 +1,34 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v0alpha1
// ConversionStatus is the status of the conversion of the dashboard.
// +k8s:openapi-gen=true
type DashboardConversionStatus struct {
// Whether from another version has failed.
// If true, means that the dashboard is not valid,
// and the caller should instead fetch the stored version.
Failed bool `json:"failed"`
// The version which was stored when the dashboard was created / updated.
// Fetching this version should always succeed.
StoredVersion string `json:"storedVersion"`
// The error message from the conversion.
// Empty if the conversion has not failed.
Error string `json:"error"`
}
// NewDashboardConversionStatus creates a new DashboardConversionStatus object.
func NewDashboardConversionStatus() *DashboardConversionStatus {
return &DashboardConversionStatus{}
}
// +k8s:openapi-gen=true
type DashboardStatus struct {
// Optional conversion status.
Conversion *DashboardConversionStatus `json:"conversion,omitempty"`
}
// NewDashboardStatus creates a new DashboardStatus object.
func NewDashboardStatus() *DashboardStatus {
return &DashboardStatus{}
}
+41
View File
@@ -0,0 +1,41 @@
package v0alpha1
// TODO: these should be automatically generated by the SDK.
func (in *Dashboard) DeepCopyInto(out *Dashboard) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
}
func (in *Dashboard) DeepCopy() *Dashboard {
if in == nil {
return nil
}
out := new(Dashboard)
in.DeepCopyInto(out)
return out
}
func (in *DashboardList) DeepCopyInto(out *DashboardList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Dashboard, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
func (in *DashboardList) DeepCopy() *DashboardList {
if in == nil {
return nil
}
out := new(DashboardList)
in.DeepCopyInto(out)
return out
}
+4 -1
View File
@@ -1,7 +1,10 @@
// +k8s:deepcopy-gen=package
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +k8s:conversion-gen=github.com/grafana/grafana/pkg/apis/dashboard
// +groupName=dashboard.grafana.app
// NOTE (@radiohead): we do not use package-wide deepcopy generation
// because grafana-app-sdk already provides deepcopy functions.
// Kinds which are not generated by the SDK are explicitly opted in to deepcopy generation.
package v0alpha1 // import "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
+7
View File
@@ -6,6 +6,7 @@ import (
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
)
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type SearchResults struct {
metav1.TypeMeta `json:",inline"`
@@ -32,11 +33,13 @@ type SearchResults struct {
Facets map[string]FacetResult `json:"facets,omitempty"`
}
// +k8s:deepcopy-gen=true
type SortBy struct {
Field string `json:"field"`
Descending bool `json:"desc,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type SortableFields struct {
metav1.TypeMeta `json:",inline"`
@@ -45,12 +48,14 @@ type SortableFields struct {
Fields []SortableField `json:"fields"`
}
// +k8s:deepcopy-gen=true
type SortableField struct {
Field string `json:"string,omitempty"`
Display string `json:"display,omitempty"`
Type string `json:"type,omitempty"` // string or number
}
// +k8s:deepcopy-gen=true
type DashboardHit struct {
// Dashboard or folder
Resource string `json:"resource"` // dashboards | folders
@@ -70,6 +75,7 @@ type DashboardHit struct {
Explain *common.Unstructured `json:"explain,omitempty"`
}
// +k8s:deepcopy-gen=true
type FacetResult struct {
Field string `json:"field,omitempty"`
// The distinct terms
@@ -80,6 +86,7 @@ type FacetResult struct {
Terms []TermFacet `json:"terms,omitempty"`
}
// +k8s:deepcopy-gen=true
type TermFacet struct {
Term string `json:"term,omitempty"`
Count int64 `json:"count,omitempty"`
+11 -35
View File
@@ -7,40 +7,7 @@ import (
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Dashboard struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// The dashboard body (unstructured for now)
Spec common.Unstructured `json:"spec"`
// Optional dashboard status
Status *DashboardStatus `json:"status,omitempty"`
}
type DashboardStatus struct {
ConversionStatus *ConversionStatus `json:"conversion,omitempty"`
}
type ConversionStatus struct {
Failed bool `json:"failed,omitempty"`
StoredVersion string `json:"storedVersion,omitempty"`
Error string `json:"error,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []Dashboard `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardVersionList struct {
metav1.TypeMeta `json:",inline"`
@@ -50,6 +17,7 @@ type DashboardVersionList struct {
Items []DashboardVersionInfo `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
type DashboardVersionInfo struct {
// The internal ID for this version (will be replaced with resourceVersion)
Version int `json:"version"`
@@ -67,6 +35,7 @@ type DashboardVersionInfo struct {
Message string `json:"message,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:conversion-gen:explicit-from=net/url.Values
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VersionsQueryOptions struct {
@@ -80,6 +49,7 @@ type VersionsQueryOptions struct {
Version int64 `json:"version,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type LibraryPanel struct {
metav1.TypeMeta `json:",inline"`
@@ -95,6 +65,7 @@ type LibraryPanel struct {
Status *LibraryPanelStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type LibraryPanelList struct {
metav1.TypeMeta `json:",inline"`
@@ -104,6 +75,7 @@ type LibraryPanelList struct {
Items []LibraryPanel `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
type LibraryPanelSpec struct {
// The panel type
Type string `json:"type"`
@@ -131,6 +103,7 @@ type LibraryPanelSpec struct {
Targets []data.DataQuery `json:"targets,omitempty"`
}
// +k8s:deepcopy-gen=true
type LibraryPanelStatus struct {
// Translation warnings (mostly things that were in SQL columns but not found in the saved body)
Warnings []string `json:"warnings,omitempty"`
@@ -140,6 +113,7 @@ type LibraryPanelStatus struct {
}
// This is like the legacy DTO where access and metadata are all returned in a single call
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardWithAccessInfo struct {
Dashboard `json:",inline"`
@@ -147,7 +121,7 @@ type DashboardWithAccessInfo struct {
Access DashboardAccess `json:"access"`
}
// Information about how the requesting user can use a given dashboard
// +k8s:deepcopy-gen=true
type DashboardAccess struct {
// Metadata fields
Slug string `json:"slug,omitempty"`
@@ -162,11 +136,13 @@ type DashboardAccess struct {
AnnotationsPermissions *AnnotationPermission `json:"annotationsPermissions"`
}
// +k8s:deepcopy-gen=true
type AnnotationPermission struct {
Dashboard AnnotationActions `json:"dashboard"`
Organization AnnotationActions `json:"organization"`
}
// +k8s:deepcopy-gen=true
type AnnotationActions struct {
CanAdd bool `json:"canAdd"`
CanEdit bool `json:"canEdit"`
@@ -46,54 +46,6 @@ func (in *AnnotationPermission) DeepCopy() *AnnotationPermission {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ConversionStatus) DeepCopyInto(out *ConversionStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConversionStatus.
func (in *ConversionStatus) DeepCopy() *ConversionStatus {
if in == nil {
return nil
}
out := new(ConversionStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Dashboard) DeepCopyInto(out *Dashboard) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
if in.Status != nil {
in, out := &in.Status, &out.Status
*out = new(DashboardStatus)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Dashboard.
func (in *Dashboard) DeepCopy() *Dashboard {
if in == nil {
return nil
}
out := new(Dashboard)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Dashboard) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardAccess) DeepCopyInto(out *DashboardAccess) {
*out = *in
@@ -144,60 +96,6 @@ func (in *DashboardHit) DeepCopy() *DashboardHit {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardList) DeepCopyInto(out *DashboardList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Dashboard, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardList.
func (in *DashboardList) DeepCopy() *DashboardList {
if in == nil {
return nil
}
out := new(DashboardList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *DashboardList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardStatus) DeepCopyInto(out *DashboardStatus) {
*out = *in
if in.ConversionStatus != nil {
in, out := &in.ConversionStatus, &out.ConversionStatus
*out = new(ConversionStatus)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardStatus.
func (in *DashboardStatus) DeepCopy() *DashboardStatus {
if in == nil {
return nil
}
out := new(DashboardStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardVersionInfo) DeepCopyInto(out *DashboardVersionInfo) {
*out = *in
@@ -8,34 +8,38 @@
package v0alpha1
import (
commonv0alpha1 "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
common "k8s.io/kube-openapi/pkg/common"
spec "k8s.io/kube-openapi/pkg/validation/spec"
)
func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationActions": schema_pkg_apis_dashboard_v0alpha1_AnnotationActions(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationPermission": schema_pkg_apis_dashboard_v0alpha1_AnnotationPermission(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.ConversionStatus": schema_pkg_apis_dashboard_v0alpha1_ConversionStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Dashboard": schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardAccess": schema_pkg_apis_dashboard_v0alpha1_DashboardAccess(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardHit": schema_pkg_apis_dashboard_v0alpha1_DashboardHit(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardList": schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardStatus": schema_pkg_apis_dashboard_v0alpha1_DashboardStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionList": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardWithAccessInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardWithAccessInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.FacetResult": schema_pkg_apis_dashboard_v0alpha1_FacetResult(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanel": schema_pkg_apis_dashboard_v0alpha1_LibraryPanel(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanelList": schema_pkg_apis_dashboard_v0alpha1_LibraryPanelList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanelSpec": schema_pkg_apis_dashboard_v0alpha1_LibraryPanelSpec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanelStatus": schema_pkg_apis_dashboard_v0alpha1_LibraryPanelStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SearchResults": schema_pkg_apis_dashboard_v0alpha1_SearchResults(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SortBy": schema_pkg_apis_dashboard_v0alpha1_SortBy(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SortableField": schema_pkg_apis_dashboard_v0alpha1_SortableField(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SortableFields": schema_pkg_apis_dashboard_v0alpha1_SortableFields(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.TermFacet": schema_pkg_apis_dashboard_v0alpha1_TermFacet(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.VersionsQueryOptions": schema_pkg_apis_dashboard_v0alpha1_VersionsQueryOptions(ref),
"github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured": commonv0alpha1.Unstructured{}.OpenAPIDefinition(),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationActions": schema_pkg_apis_dashboard_v0alpha1_AnnotationActions(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationPermission": schema_pkg_apis_dashboard_v0alpha1_AnnotationPermission(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Dashboard": schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardAccess": schema_pkg_apis_dashboard_v0alpha1_DashboardAccess(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardConversionStatus": schema_pkg_apis_dashboard_v0alpha1_DashboardConversionStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardHit": schema_pkg_apis_dashboard_v0alpha1_DashboardHit(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardJSONCodec": schema_pkg_apis_dashboard_v0alpha1_DashboardJSONCodec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardList": schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardMetadata": schema_pkg_apis_dashboard_v0alpha1_DashboardMetadata(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardStatus": schema_pkg_apis_dashboard_v0alpha1_DashboardStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionList": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardWithAccessInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardWithAccessInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.FacetResult": schema_pkg_apis_dashboard_v0alpha1_FacetResult(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanel": schema_pkg_apis_dashboard_v0alpha1_LibraryPanel(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanelList": schema_pkg_apis_dashboard_v0alpha1_LibraryPanelList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanelSpec": schema_pkg_apis_dashboard_v0alpha1_LibraryPanelSpec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.LibraryPanelStatus": schema_pkg_apis_dashboard_v0alpha1_LibraryPanelStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SearchResults": schema_pkg_apis_dashboard_v0alpha1_SearchResults(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SortBy": schema_pkg_apis_dashboard_v0alpha1_SortBy(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SortableField": schema_pkg_apis_dashboard_v0alpha1_SortableField(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.SortableFields": schema_pkg_apis_dashboard_v0alpha1_SortableFields(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.TermFacet": schema_pkg_apis_dashboard_v0alpha1_TermFacet(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.VersionsQueryOptions": schema_pkg_apis_dashboard_v0alpha1_VersionsQueryOptions(ref),
}
}
@@ -100,36 +104,6 @@ func schema_pkg_apis_dashboard_v0alpha1_AnnotationPermission(ref common.Referenc
}
}
func schema_pkg_apis_dashboard_v0alpha1_ConversionStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"failed": {
SchemaProps: spec.SchemaProps{
Type: []string{"boolean"},
Format: "",
},
},
"storedVersion": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
"error": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
},
},
},
}
}
func schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -152,25 +126,24 @@ func schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref common.ReferenceCallback)
},
"metadata": {
SchemaProps: spec.SchemaProps{
Description: "Standard object's metadata More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
},
},
"spec": {
SchemaProps: spec.SchemaProps{
Description: "The dashboard body (unstructured for now)",
Description: "Spec is the spec of the Dashboard",
Ref: ref("github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"),
},
},
"status": {
SchemaProps: spec.SchemaProps{
Description: "Optional dashboard status",
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardStatus"),
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardStatus"),
},
},
},
Required: []string{"spec"},
Required: []string{"metadata", "spec", "status"},
},
},
Dependencies: []string{
@@ -182,8 +155,7 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardAccess(ref common.ReferenceCall
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "Information about how the requesting user can use a given dashboard",
Type: []string{"object"},
Type: []string{"object"},
Properties: map[string]spec.Schema{
"slug": {
SchemaProps: spec.SchemaProps{
@@ -248,6 +220,44 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardAccess(ref common.ReferenceCall
}
}
func schema_pkg_apis_dashboard_v0alpha1_DashboardConversionStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "ConversionStatus is the status of the conversion of the dashboard.",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"failed": {
SchemaProps: spec.SchemaProps{
Description: "Whether from another version has failed. If true, means that the dashboard is not valid, and the caller should instead fetch the stored version.",
Default: false,
Type: []string{"boolean"},
Format: "",
},
},
"storedVersion": {
SchemaProps: spec.SchemaProps{
Description: "The version which was stored when the dashboard was created / updated. Fetching this version should always succeed.",
Default: "",
Type: []string{"string"},
Format: "",
},
},
"error": {
SchemaProps: spec.SchemaProps{
Description: "The error message from the conversion. Empty if the conversion has not failed.",
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
Required: []string{"failed", "storedVersion", "error"},
},
},
}
}
func schema_pkg_apis_dashboard_v0alpha1_DashboardHit(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -328,6 +338,17 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardHit(ref common.ReferenceCallbac
}
}
func schema_pkg_apis_dashboard_v0alpha1_DashboardJSONCodec(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "DashboardJSONCodec is an implementation of resource.Codec for kubernetes JSON encoding",
Type: []string{"object"},
},
},
}
}
func schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -368,6 +389,7 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref common.ReferenceCallba
},
},
},
Required: []string{"metadata", "items"},
},
},
Dependencies: []string{
@@ -375,6 +397,102 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref common.ReferenceCallba
}
}
func schema_pkg_apis_dashboard_v0alpha1_DashboardMetadata(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "metadata contains embedded CommonMetadata and can be extended with custom string fields without external reference as using the CommonMetadata reference breaks thema codegen.",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"updateTimestamp": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
"createdBy": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"uid": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"creationTimestamp": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
"deletionTimestamp": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
"finalizers": {
SchemaProps: spec.SchemaProps{
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
},
},
"resourceVersion": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"generation": {
SchemaProps: spec.SchemaProps{
Default: 0,
Type: []string{"integer"},
Format: "int64",
},
},
"updatedBy": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"labels": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Allows: true,
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
},
},
},
Required: []string{"updateTimestamp", "createdBy", "uid", "creationTimestamp", "finalizers", "resourceVersion", "generation", "updatedBy", "labels"},
},
},
}
}
func schema_pkg_apis_dashboard_v0alpha1_DashboardStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -383,14 +501,15 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardStatus(ref common.ReferenceCall
Properties: map[string]spec.Schema{
"conversion": {
SchemaProps: spec.SchemaProps{
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.ConversionStatus"),
Description: "Optional conversion status.",
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardConversionStatus"),
},
},
},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.ConversionStatus"},
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardConversionStatus"},
}
}
@@ -514,21 +633,20 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardWithAccessInfo(ref common.Refer
},
"metadata": {
SchemaProps: spec.SchemaProps{
Description: "Standard object's metadata More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
},
},
"spec": {
SchemaProps: spec.SchemaProps{
Description: "The dashboard body (unstructured for now)",
Description: "Spec is the spec of the Dashboard",
Ref: ref("github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"),
},
},
"status": {
SchemaProps: spec.SchemaProps{
Description: "Optional dashboard status",
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardStatus"),
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardStatus"),
},
},
"access": {
@@ -538,7 +656,7 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardWithAccessInfo(ref common.Refer
},
},
},
Required: []string{"spec", "access"},
Required: []string{"metadata", "spec", "status", "access"},
},
},
Dependencies: []string{
@@ -1,8 +1,9 @@
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,DashboardHit,Tags
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,DashboardMetadata,Finalizers
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,FacetResult,Terms
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,LibraryPanelStatus,Warnings
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,SearchResults,Hits
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,SortableFields,Fields
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,DashboardStatus,ConversionStatus
API rule violation: names_match,github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1,Unstructured,Object
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,SortBy,Descending
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,SortableField,Field
+18
View File
@@ -0,0 +1,18 @@
package v1alpha1
import "k8s.io/apimachinery/pkg/runtime/schema"
const (
// Group is the API group used by all kinds in this package
Group = "dashboard.grafana.app"
// Version is the API version used by all kinds in this package
Version = "v1alpha1"
)
var (
// GroupVersion is a schema.GroupVersion consisting of the Group and Version constants for this package
GroupVersion = schema.GroupVersion{
Group: Group,
Version: Version,
}
)
@@ -0,0 +1,28 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v1alpha1
import (
"encoding/json"
"io"
"github.com/grafana/grafana-app-sdk/resource"
)
// DashboardJSONCodec is an implementation of resource.Codec for kubernetes JSON encoding
type DashboardJSONCodec struct{}
// Read reads JSON-encoded bytes from `reader` and unmarshals them into `into`
func (*DashboardJSONCodec) Read(reader io.Reader, into resource.Object) error {
return json.NewDecoder(reader).Decode(into)
}
// Write writes JSON-encoded bytes into `writer` marshaled from `from`
func (*DashboardJSONCodec) Write(writer io.Writer, from resource.Object) error {
return json.NewEncoder(writer).Encode(from)
}
// Interface compliance checks
var _ resource.Codec = &DashboardJSONCodec{}
@@ -0,0 +1,28 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v1alpha1
import (
time "time"
)
// metadata contains embedded CommonMetadata and can be extended with custom string fields
// TODO: use CommonMetadata instead of redefining here; currently needs to be defined here
// without external reference as using the CommonMetadata reference breaks thema codegen.
type DashboardMetadata struct {
UpdateTimestamp time.Time `json:"updateTimestamp"`
CreatedBy string `json:"createdBy"`
Uid string `json:"uid"`
CreationTimestamp time.Time `json:"creationTimestamp"`
DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"`
Finalizers []string `json:"finalizers"`
ResourceVersion string `json:"resourceVersion"`
Generation int64 `json:"generation"`
UpdatedBy string `json:"updatedBy"`
Labels map[string]string `json:"labels"`
}
// NewDashboardMetadata creates a new DashboardMetadata object.
func NewDashboardMetadata() *DashboardMetadata {
return &DashboardMetadata{}
}
@@ -0,0 +1,269 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v1alpha1
import (
"fmt"
"github.com/grafana/grafana-app-sdk/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"time"
)
// +k8s:openapi-gen=true
type Dashboard struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ObjectMeta `json:"metadata" yaml:"metadata"`
// Spec is the spec of the Dashboard
Spec DashboardSpec `json:"spec" yaml:"spec"`
Status DashboardStatus `json:"status" yaml:"status"`
}
func (o *Dashboard) GetSpec() any {
return o.Spec
}
func (o *Dashboard) SetSpec(spec any) error {
cast, ok := spec.(DashboardSpec)
if !ok {
return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec)
}
o.Spec = cast
return nil
}
func (o *Dashboard) GetSubresources() map[string]any {
return map[string]any{
"status": o.Status,
}
}
func (o *Dashboard) GetSubresource(name string) (any, bool) {
switch name {
case "status":
return o.Status, true
default:
return nil, false
}
}
func (o *Dashboard) SetSubresource(name string, value any) error {
switch name {
case "status":
cast, ok := value.(DashboardStatus)
if !ok {
return fmt.Errorf("cannot set status type %#v, not of type DashboardStatus", value)
}
o.Status = cast
return nil
default:
return fmt.Errorf("subresource '%s' does not exist", name)
}
}
func (o *Dashboard) GetStaticMetadata() resource.StaticMetadata {
gvk := o.GroupVersionKind()
return resource.StaticMetadata{
Name: o.ObjectMeta.Name,
Namespace: o.ObjectMeta.Namespace,
Group: gvk.Group,
Version: gvk.Version,
Kind: gvk.Kind,
}
}
func (o *Dashboard) SetStaticMetadata(metadata resource.StaticMetadata) {
o.Name = metadata.Name
o.Namespace = metadata.Namespace
o.SetGroupVersionKind(schema.GroupVersionKind{
Group: metadata.Group,
Version: metadata.Version,
Kind: metadata.Kind,
})
}
func (o *Dashboard) GetCommonMetadata() resource.CommonMetadata {
dt := o.DeletionTimestamp
var deletionTimestamp *time.Time
if dt != nil {
deletionTimestamp = &dt.Time
}
// Legacy ExtraFields support
extraFields := make(map[string]any)
if o.Annotations != nil {
extraFields["annotations"] = o.Annotations
}
if o.ManagedFields != nil {
extraFields["managedFields"] = o.ManagedFields
}
if o.OwnerReferences != nil {
extraFields["ownerReferences"] = o.OwnerReferences
}
return resource.CommonMetadata{
UID: string(o.UID),
ResourceVersion: o.ResourceVersion,
Generation: o.Generation,
Labels: o.Labels,
CreationTimestamp: o.CreationTimestamp.Time,
DeletionTimestamp: deletionTimestamp,
Finalizers: o.Finalizers,
UpdateTimestamp: o.GetUpdateTimestamp(),
CreatedBy: o.GetCreatedBy(),
UpdatedBy: o.GetUpdatedBy(),
ExtraFields: extraFields,
}
}
func (o *Dashboard) SetCommonMetadata(metadata resource.CommonMetadata) {
o.UID = types.UID(metadata.UID)
o.ResourceVersion = metadata.ResourceVersion
o.Generation = metadata.Generation
o.Labels = metadata.Labels
o.CreationTimestamp = metav1.NewTime(metadata.CreationTimestamp)
if metadata.DeletionTimestamp != nil {
dt := metav1.NewTime(*metadata.DeletionTimestamp)
o.DeletionTimestamp = &dt
} else {
o.DeletionTimestamp = nil
}
o.Finalizers = metadata.Finalizers
if o.Annotations == nil {
o.Annotations = make(map[string]string)
}
if !metadata.UpdateTimestamp.IsZero() {
o.SetUpdateTimestamp(metadata.UpdateTimestamp)
}
if metadata.CreatedBy != "" {
o.SetCreatedBy(metadata.CreatedBy)
}
if metadata.UpdatedBy != "" {
o.SetUpdatedBy(metadata.UpdatedBy)
}
// Legacy support for setting Annotations, ManagedFields, and OwnerReferences via ExtraFields
if metadata.ExtraFields != nil {
if annotations, ok := metadata.ExtraFields["annotations"]; ok {
if cast, ok := annotations.(map[string]string); ok {
o.Annotations = cast
}
}
if managedFields, ok := metadata.ExtraFields["managedFields"]; ok {
if cast, ok := managedFields.([]metav1.ManagedFieldsEntry); ok {
o.ManagedFields = cast
}
}
if ownerReferences, ok := metadata.ExtraFields["ownerReferences"]; ok {
if cast, ok := ownerReferences.([]metav1.OwnerReference); ok {
o.OwnerReferences = cast
}
}
}
}
func (o *Dashboard) GetCreatedBy() string {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
return o.ObjectMeta.Annotations["grafana.com/createdBy"]
}
func (o *Dashboard) SetCreatedBy(createdBy string) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy
}
func (o *Dashboard) GetUpdateTimestamp() time.Time {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"])
return parsed
}
func (o *Dashboard) SetUpdateTimestamp(updateTimestamp time.Time) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339)
}
func (o *Dashboard) GetUpdatedBy() string {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
return o.ObjectMeta.Annotations["grafana.com/updatedBy"]
}
func (o *Dashboard) SetUpdatedBy(updatedBy string) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy
}
func (o *Dashboard) Copy() resource.Object {
return resource.CopyObject(o)
}
func (o *Dashboard) DeepCopyObject() runtime.Object {
return o.Copy()
}
// Interface compliance compile-time check
var _ resource.Object = &Dashboard{}
// +k8s:openapi-gen=true
type DashboardList struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata" yaml:"metadata"`
Items []Dashboard `json:"items" yaml:"items"`
}
func (o *DashboardList) DeepCopyObject() runtime.Object {
return o.Copy()
}
func (o *DashboardList) Copy() resource.ListObject {
cpy := &DashboardList{
TypeMeta: o.TypeMeta,
Items: make([]Dashboard, len(o.Items)),
}
o.ListMeta.DeepCopyInto(&cpy.ListMeta)
for i := 0; i < len(o.Items); i++ {
if item, ok := o.Items[i].Copy().(*Dashboard); ok {
cpy.Items[i] = *item
}
}
return cpy
}
func (o *DashboardList) GetItems() []resource.Object {
items := make([]resource.Object, len(o.Items))
for i := 0; i < len(o.Items); i++ {
items[i] = &o.Items[i]
}
return items
}
func (o *DashboardList) SetItems(items []resource.Object) {
o.Items = make([]Dashboard, len(items))
for i := 0; i < len(items); i++ {
o.Items[i] = *items[i].(*Dashboard)
}
}
// Interface compliance compile-time check
var _ resource.ListObject = &DashboardList{}
@@ -0,0 +1,34 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v1alpha1
import (
"github.com/grafana/grafana-app-sdk/resource"
)
// schema is unexported to prevent accidental overwrites
var (
schemaDashboard = resource.NewSimpleSchema("dashboard.grafana.app", "v1alpha1", &Dashboard{}, &DashboardList{}, resource.WithKind("Dashboard"),
resource.WithPlural("dashboards"), resource.WithScope(resource.NamespacedScope))
kindDashboard = resource.Kind{
Schema: schemaDashboard,
Codecs: map[resource.KindEncoding]resource.Codec{
resource.KindEncodingJSON: &DashboardJSONCodec{},
},
}
)
// Kind returns a resource.Kind for this Schema with a JSON codec
func DashboardKind() resource.Kind {
return kindDashboard
}
// Schema returns a resource.SimpleSchema representation of Dashboard
func DashboardSchema() *resource.SimpleSchema {
return schemaDashboard
}
// Interface compliance checks
var _ resource.Schema = kindDashboard
@@ -0,0 +1,11 @@
package v1alpha1
import common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
// +k8s:openapi-gen=true
type DashboardSpec = common.Unstructured
// NewDashboardSpec creates a new Spec object.
func NewDashboardSpec() *DashboardSpec {
return &DashboardSpec{}
}
@@ -0,0 +1,3 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v1alpha1
@@ -0,0 +1,34 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v1alpha1
// ConversionStatus is the status of the conversion of the dashboard.
// +k8s:openapi-gen=true
type DashboardConversionStatus struct {
// Whether from another version has failed.
// If true, means that the dashboard is not valid,
// and the caller should instead fetch the stored version.
Failed bool `json:"failed"`
// The version which was stored when the dashboard was created / updated.
// Fetching this version should always succeed.
StoredVersion string `json:"storedVersion"`
// The error message from the conversion.
// Empty if the conversion has not failed.
Error string `json:"error"`
}
// NewDashboardConversionStatus creates a new DashboardConversionStatus object.
func NewDashboardConversionStatus() *DashboardConversionStatus {
return &DashboardConversionStatus{}
}
// +k8s:openapi-gen=true
type DashboardStatus struct {
// Optional conversion status.
Conversion *DashboardConversionStatus `json:"conversion,omitempty"`
}
// NewDashboardStatus creates a new DashboardStatus object.
func NewDashboardStatus() *DashboardStatus {
return &DashboardStatus{}
}
+41
View File
@@ -0,0 +1,41 @@
package v1alpha1
// TODO: these should be automatically generated by the SDK.
func (in *Dashboard) DeepCopyInto(out *Dashboard) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
}
func (in *Dashboard) DeepCopy() *Dashboard {
if in == nil {
return nil
}
out := new(Dashboard)
in.DeepCopyInto(out)
return out
}
func (in *DashboardList) DeepCopyInto(out *DashboardList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Dashboard, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
func (in *DashboardList) DeepCopy() *DashboardList {
if in == nil {
return nil
}
out := new(DashboardList)
in.DeepCopyInto(out)
return out
}
+4 -1
View File
@@ -1,7 +1,10 @@
// +k8s:deepcopy-gen=package
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +k8s:conversion-gen=github.com/grafana/grafana/pkg/apis/dashboard
// +groupName=dashboard.grafana.app
// NOTE (@radiohead): we do not use package-wide deepcopy generation
// because grafana-app-sdk already provides deepcopy functions.
// Kinds which are not generated by the SDK are explicitly opted in to deepcopy generation.
package v1alpha1 // import "github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1"
+11 -34
View File
@@ -7,40 +7,7 @@ import (
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Dashboard struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// The dashboard body (unstructured for now)
Spec common.Unstructured `json:"spec"`
// Optional dashboard status
Status *DashboardStatus `json:"status,omitempty"`
}
type DashboardStatus struct {
ConversionStatus *ConversionStatus `json:"conversion,omitempty"`
}
type ConversionStatus struct {
Failed bool `json:"failed,omitempty"`
StoredVersion string `json:"storedVersion,omitempty"`
Error string `json:"error,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []Dashboard `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardVersionList struct {
metav1.TypeMeta `json:",inline"`
@@ -50,6 +17,7 @@ type DashboardVersionList struct {
Items []DashboardVersionInfo `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
type DashboardVersionInfo struct {
// The internal ID for this version (will be replaced with resourceVersion)
Version int `json:"version"`
@@ -67,6 +35,7 @@ type DashboardVersionInfo struct {
Message string `json:"message,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:conversion-gen:explicit-from=net/url.Values
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VersionsQueryOptions struct {
@@ -80,6 +49,7 @@ type VersionsQueryOptions struct {
Version int64 `json:"version,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type LibraryPanel struct {
metav1.TypeMeta `json:",inline"`
@@ -95,6 +65,7 @@ type LibraryPanel struct {
Status *LibraryPanelStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type LibraryPanelList struct {
metav1.TypeMeta `json:",inline"`
@@ -104,6 +75,7 @@ type LibraryPanelList struct {
Items []LibraryPanel `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
type LibraryPanelSpec struct {
// The panel type
Type string `json:"type"`
@@ -131,6 +103,7 @@ type LibraryPanelSpec struct {
Targets []data.DataQuery `json:"targets,omitempty"`
}
// +k8s:deepcopy-gen=true
type LibraryPanelStatus struct {
// Translation warnings (mostly things that were in SQL columns but not found in the saved body)
Warnings []string `json:"warnings,omitempty"`
@@ -140,6 +113,7 @@ type LibraryPanelStatus struct {
}
// This is like the legacy DTO where access and metadata are all returned in a single call
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardWithAccessInfo struct {
Dashboard `json:",inline"`
@@ -148,6 +122,7 @@ type DashboardWithAccessInfo struct {
}
// Information about how the requesting user can use a given dashboard
// +k8s:deepcopy-gen=true
type DashboardAccess struct {
// Metadata fields
Slug string `json:"slug,omitempty"`
@@ -162,11 +137,13 @@ type DashboardAccess struct {
AnnotationsPermissions *AnnotationPermission `json:"annotationsPermissions"`
}
// +k8s:deepcopy-gen=true
type AnnotationPermission struct {
Dashboard AnnotationActions `json:"dashboard"`
Organization AnnotationActions `json:"organization"`
}
// +k8s:deepcopy-gen=true
type AnnotationActions struct {
CanAdd bool `json:"canAdd"`
CanEdit bool `json:"canEdit"`
@@ -46,54 +46,6 @@ func (in *AnnotationPermission) DeepCopy() *AnnotationPermission {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ConversionStatus) DeepCopyInto(out *ConversionStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConversionStatus.
func (in *ConversionStatus) DeepCopy() *ConversionStatus {
if in == nil {
return nil
}
out := new(ConversionStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Dashboard) DeepCopyInto(out *Dashboard) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
if in.Status != nil {
in, out := &in.Status, &out.Status
*out = new(DashboardStatus)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Dashboard.
func (in *Dashboard) DeepCopy() *Dashboard {
if in == nil {
return nil
}
out := new(Dashboard)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Dashboard) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardAccess) DeepCopyInto(out *DashboardAccess) {
*out = *in
@@ -115,60 +67,6 @@ func (in *DashboardAccess) DeepCopy() *DashboardAccess {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardList) DeepCopyInto(out *DashboardList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Dashboard, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardList.
func (in *DashboardList) DeepCopy() *DashboardList {
if in == nil {
return nil
}
out := new(DashboardList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *DashboardList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardStatus) DeepCopyInto(out *DashboardStatus) {
*out = *in
if in.ConversionStatus != nil {
in, out := &in.ConversionStatus, &out.ConversionStatus
*out = new(ConversionStatus)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardStatus.
func (in *DashboardStatus) DeepCopy() *DashboardStatus {
if in == nil {
return nil
}
out := new(DashboardStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardVersionInfo) DeepCopyInto(out *DashboardVersionInfo) {
*out = *in
@@ -8,27 +8,31 @@
package v1alpha1
import (
v0alpha1 "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
common "k8s.io/kube-openapi/pkg/common"
spec "k8s.io/kube-openapi/pkg/validation/spec"
)
func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.AnnotationActions": schema_pkg_apis_dashboard_v1alpha1_AnnotationActions(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.AnnotationPermission": schema_pkg_apis_dashboard_v1alpha1_AnnotationPermission(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.ConversionStatus": schema_pkg_apis_dashboard_v1alpha1_ConversionStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.Dashboard": schema_pkg_apis_dashboard_v1alpha1_Dashboard(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardAccess": schema_pkg_apis_dashboard_v1alpha1_DashboardAccess(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardList": schema_pkg_apis_dashboard_v1alpha1_DashboardList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardStatus": schema_pkg_apis_dashboard_v1alpha1_DashboardStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardVersionInfo": schema_pkg_apis_dashboard_v1alpha1_DashboardVersionInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardVersionList": schema_pkg_apis_dashboard_v1alpha1_DashboardVersionList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardWithAccessInfo": schema_pkg_apis_dashboard_v1alpha1_DashboardWithAccessInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanel": schema_pkg_apis_dashboard_v1alpha1_LibraryPanel(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanelList": schema_pkg_apis_dashboard_v1alpha1_LibraryPanelList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanelSpec": schema_pkg_apis_dashboard_v1alpha1_LibraryPanelSpec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanelStatus": schema_pkg_apis_dashboard_v1alpha1_LibraryPanelStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.VersionsQueryOptions": schema_pkg_apis_dashboard_v1alpha1_VersionsQueryOptions(ref),
"github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured": v0alpha1.Unstructured{}.OpenAPIDefinition(),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.AnnotationActions": schema_pkg_apis_dashboard_v1alpha1_AnnotationActions(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.AnnotationPermission": schema_pkg_apis_dashboard_v1alpha1_AnnotationPermission(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.Dashboard": schema_pkg_apis_dashboard_v1alpha1_Dashboard(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardAccess": schema_pkg_apis_dashboard_v1alpha1_DashboardAccess(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardConversionStatus": schema_pkg_apis_dashboard_v1alpha1_DashboardConversionStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardJSONCodec": schema_pkg_apis_dashboard_v1alpha1_DashboardJSONCodec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardList": schema_pkg_apis_dashboard_v1alpha1_DashboardList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardMetadata": schema_pkg_apis_dashboard_v1alpha1_DashboardMetadata(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardStatus": schema_pkg_apis_dashboard_v1alpha1_DashboardStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardVersionInfo": schema_pkg_apis_dashboard_v1alpha1_DashboardVersionInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardVersionList": schema_pkg_apis_dashboard_v1alpha1_DashboardVersionList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardWithAccessInfo": schema_pkg_apis_dashboard_v1alpha1_DashboardWithAccessInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanel": schema_pkg_apis_dashboard_v1alpha1_LibraryPanel(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanelList": schema_pkg_apis_dashboard_v1alpha1_LibraryPanelList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanelSpec": schema_pkg_apis_dashboard_v1alpha1_LibraryPanelSpec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.LibraryPanelStatus": schema_pkg_apis_dashboard_v1alpha1_LibraryPanelStatus(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.VersionsQueryOptions": schema_pkg_apis_dashboard_v1alpha1_VersionsQueryOptions(ref),
}
}
@@ -93,36 +97,6 @@ func schema_pkg_apis_dashboard_v1alpha1_AnnotationPermission(ref common.Referenc
}
}
func schema_pkg_apis_dashboard_v1alpha1_ConversionStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"failed": {
SchemaProps: spec.SchemaProps{
Type: []string{"boolean"},
Format: "",
},
},
"storedVersion": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
"error": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
},
},
},
}
}
func schema_pkg_apis_dashboard_v1alpha1_Dashboard(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -145,25 +119,24 @@ func schema_pkg_apis_dashboard_v1alpha1_Dashboard(ref common.ReferenceCallback)
},
"metadata": {
SchemaProps: spec.SchemaProps{
Description: "Standard object's metadata More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
},
},
"spec": {
SchemaProps: spec.SchemaProps{
Description: "The dashboard body (unstructured for now)",
Description: "Spec is the spec of the Dashboard",
Ref: ref("github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"),
},
},
"status": {
SchemaProps: spec.SchemaProps{
Description: "Optional dashboard status",
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardStatus"),
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardStatus"),
},
},
},
Required: []string{"spec"},
Required: []string{"metadata", "spec", "status"},
},
},
Dependencies: []string{
@@ -241,6 +214,55 @@ func schema_pkg_apis_dashboard_v1alpha1_DashboardAccess(ref common.ReferenceCall
}
}
func schema_pkg_apis_dashboard_v1alpha1_DashboardConversionStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "ConversionStatus is the status of the conversion of the dashboard.",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"failed": {
SchemaProps: spec.SchemaProps{
Description: "Whether from another version has failed. If true, means that the dashboard is not valid, and the caller should instead fetch the stored version.",
Default: false,
Type: []string{"boolean"},
Format: "",
},
},
"storedVersion": {
SchemaProps: spec.SchemaProps{
Description: "The version which was stored when the dashboard was created / updated. Fetching this version should always succeed.",
Default: "",
Type: []string{"string"},
Format: "",
},
},
"error": {
SchemaProps: spec.SchemaProps{
Description: "The error message from the conversion. Empty if the conversion has not failed.",
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
Required: []string{"failed", "storedVersion", "error"},
},
},
}
}
func schema_pkg_apis_dashboard_v1alpha1_DashboardJSONCodec(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "DashboardJSONCodec is an implementation of resource.Codec for kubernetes JSON encoding",
Type: []string{"object"},
},
},
}
}
func schema_pkg_apis_dashboard_v1alpha1_DashboardList(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -281,6 +303,7 @@ func schema_pkg_apis_dashboard_v1alpha1_DashboardList(ref common.ReferenceCallba
},
},
},
Required: []string{"metadata", "items"},
},
},
Dependencies: []string{
@@ -288,6 +311,102 @@ func schema_pkg_apis_dashboard_v1alpha1_DashboardList(ref common.ReferenceCallba
}
}
func schema_pkg_apis_dashboard_v1alpha1_DashboardMetadata(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "metadata contains embedded CommonMetadata and can be extended with custom string fields without external reference as using the CommonMetadata reference breaks thema codegen.",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"updateTimestamp": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
"createdBy": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"uid": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"creationTimestamp": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
"deletionTimestamp": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
"finalizers": {
SchemaProps: spec.SchemaProps{
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
},
},
"resourceVersion": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"generation": {
SchemaProps: spec.SchemaProps{
Default: 0,
Type: []string{"integer"},
Format: "int64",
},
},
"updatedBy": {
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
"labels": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Allows: true,
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
},
},
},
Required: []string{"updateTimestamp", "createdBy", "uid", "creationTimestamp", "finalizers", "resourceVersion", "generation", "updatedBy", "labels"},
},
},
}
}
func schema_pkg_apis_dashboard_v1alpha1_DashboardStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -296,14 +415,15 @@ func schema_pkg_apis_dashboard_v1alpha1_DashboardStatus(ref common.ReferenceCall
Properties: map[string]spec.Schema{
"conversion": {
SchemaProps: spec.SchemaProps{
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.ConversionStatus"),
Description: "Optional conversion status.",
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardConversionStatus"),
},
},
},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.ConversionStatus"},
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardConversionStatus"},
}
}
@@ -427,21 +547,20 @@ func schema_pkg_apis_dashboard_v1alpha1_DashboardWithAccessInfo(ref common.Refer
},
"metadata": {
SchemaProps: spec.SchemaProps{
Description: "Standard object's metadata More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
},
},
"spec": {
SchemaProps: spec.SchemaProps{
Description: "The dashboard body (unstructured for now)",
Description: "Spec is the spec of the Dashboard",
Ref: ref("github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"),
},
},
"status": {
SchemaProps: spec.SchemaProps{
Description: "Optional dashboard status",
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardStatus"),
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1.DashboardStatus"),
},
},
"access": {
@@ -451,7 +570,7 @@ func schema_pkg_apis_dashboard_v1alpha1_DashboardWithAccessInfo(ref common.Refer
},
},
},
Required: []string{"spec", "access"},
Required: []string{"metadata", "spec", "status", "access"},
},
},
Dependencies: []string{
@@ -1,2 +1,3 @@
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1,DashboardMetadata,Finalizers
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1,LibraryPanelStatus,Warnings
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1,DashboardStatus,ConversionStatus
API rule violation: names_match,github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1,Unstructured,Object
+18
View File
@@ -0,0 +1,18 @@
package v2alpha1
import "k8s.io/apimachinery/pkg/runtime/schema"
const (
// Group is the API group used by all kinds in this package
Group = "dashboard.grafana.app"
// Version is the API version used by all kinds in this package
Version = "v2alpha1"
)
var (
// GroupVersion is a schema.GroupVersion consisting of the Group and Version constants for this package
GroupVersion = schema.GroupVersion{
Group: Group,
Version: Version,
}
)
@@ -0,0 +1,28 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v2alpha1
import (
"encoding/json"
"io"
"github.com/grafana/grafana-app-sdk/resource"
)
// DashboardJSONCodec is an implementation of resource.Codec for kubernetes JSON encoding
type DashboardJSONCodec struct{}
// Read reads JSON-encoded bytes from `reader` and unmarshals them into `into`
func (*DashboardJSONCodec) Read(reader io.Reader, into resource.Object) error {
return json.NewDecoder(reader).Decode(into)
}
// Write writes JSON-encoded bytes into `writer` marshaled from `from`
func (*DashboardJSONCodec) Write(writer io.Writer, from resource.Object) error {
return json.NewEncoder(writer).Encode(from)
}
// Interface compliance checks
var _ resource.Codec = &DashboardJSONCodec{}
@@ -0,0 +1,28 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v2alpha1
import (
time "time"
)
// metadata contains embedded CommonMetadata and can be extended with custom string fields
// TODO: use CommonMetadata instead of redefining here; currently needs to be defined here
// without external reference as using the CommonMetadata reference breaks thema codegen.
type DashboardMetadata struct {
UpdateTimestamp time.Time `json:"updateTimestamp"`
CreatedBy string `json:"createdBy"`
Uid string `json:"uid"`
CreationTimestamp time.Time `json:"creationTimestamp"`
DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"`
Finalizers []string `json:"finalizers"`
ResourceVersion string `json:"resourceVersion"`
Generation int64 `json:"generation"`
UpdatedBy string `json:"updatedBy"`
Labels map[string]string `json:"labels"`
}
// NewDashboardMetadata creates a new DashboardMetadata object.
func NewDashboardMetadata() *DashboardMetadata {
return &DashboardMetadata{}
}
@@ -0,0 +1,269 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v2alpha1
import (
"fmt"
"github.com/grafana/grafana-app-sdk/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"time"
)
// +k8s:openapi-gen=true
type Dashboard struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ObjectMeta `json:"metadata" yaml:"metadata"`
// Spec is the spec of the Dashboard
Spec DashboardSpec `json:"spec" yaml:"spec"`
Status DashboardStatus `json:"status" yaml:"status"`
}
func (o *Dashboard) GetSpec() any {
return o.Spec
}
func (o *Dashboard) SetSpec(spec any) error {
cast, ok := spec.(DashboardSpec)
if !ok {
return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec)
}
o.Spec = cast
return nil
}
func (o *Dashboard) GetSubresources() map[string]any {
return map[string]any{
"status": o.Status,
}
}
func (o *Dashboard) GetSubresource(name string) (any, bool) {
switch name {
case "status":
return o.Status, true
default:
return nil, false
}
}
func (o *Dashboard) SetSubresource(name string, value any) error {
switch name {
case "status":
cast, ok := value.(DashboardStatus)
if !ok {
return fmt.Errorf("cannot set status type %#v, not of type DashboardStatus", value)
}
o.Status = cast
return nil
default:
return fmt.Errorf("subresource '%s' does not exist", name)
}
}
func (o *Dashboard) GetStaticMetadata() resource.StaticMetadata {
gvk := o.GroupVersionKind()
return resource.StaticMetadata{
Name: o.ObjectMeta.Name,
Namespace: o.ObjectMeta.Namespace,
Group: gvk.Group,
Version: gvk.Version,
Kind: gvk.Kind,
}
}
func (o *Dashboard) SetStaticMetadata(metadata resource.StaticMetadata) {
o.Name = metadata.Name
o.Namespace = metadata.Namespace
o.SetGroupVersionKind(schema.GroupVersionKind{
Group: metadata.Group,
Version: metadata.Version,
Kind: metadata.Kind,
})
}
func (o *Dashboard) GetCommonMetadata() resource.CommonMetadata {
dt := o.DeletionTimestamp
var deletionTimestamp *time.Time
if dt != nil {
deletionTimestamp = &dt.Time
}
// Legacy ExtraFields support
extraFields := make(map[string]any)
if o.Annotations != nil {
extraFields["annotations"] = o.Annotations
}
if o.ManagedFields != nil {
extraFields["managedFields"] = o.ManagedFields
}
if o.OwnerReferences != nil {
extraFields["ownerReferences"] = o.OwnerReferences
}
return resource.CommonMetadata{
UID: string(o.UID),
ResourceVersion: o.ResourceVersion,
Generation: o.Generation,
Labels: o.Labels,
CreationTimestamp: o.CreationTimestamp.Time,
DeletionTimestamp: deletionTimestamp,
Finalizers: o.Finalizers,
UpdateTimestamp: o.GetUpdateTimestamp(),
CreatedBy: o.GetCreatedBy(),
UpdatedBy: o.GetUpdatedBy(),
ExtraFields: extraFields,
}
}
func (o *Dashboard) SetCommonMetadata(metadata resource.CommonMetadata) {
o.UID = types.UID(metadata.UID)
o.ResourceVersion = metadata.ResourceVersion
o.Generation = metadata.Generation
o.Labels = metadata.Labels
o.CreationTimestamp = metav1.NewTime(metadata.CreationTimestamp)
if metadata.DeletionTimestamp != nil {
dt := metav1.NewTime(*metadata.DeletionTimestamp)
o.DeletionTimestamp = &dt
} else {
o.DeletionTimestamp = nil
}
o.Finalizers = metadata.Finalizers
if o.Annotations == nil {
o.Annotations = make(map[string]string)
}
if !metadata.UpdateTimestamp.IsZero() {
o.SetUpdateTimestamp(metadata.UpdateTimestamp)
}
if metadata.CreatedBy != "" {
o.SetCreatedBy(metadata.CreatedBy)
}
if metadata.UpdatedBy != "" {
o.SetUpdatedBy(metadata.UpdatedBy)
}
// Legacy support for setting Annotations, ManagedFields, and OwnerReferences via ExtraFields
if metadata.ExtraFields != nil {
if annotations, ok := metadata.ExtraFields["annotations"]; ok {
if cast, ok := annotations.(map[string]string); ok {
o.Annotations = cast
}
}
if managedFields, ok := metadata.ExtraFields["managedFields"]; ok {
if cast, ok := managedFields.([]metav1.ManagedFieldsEntry); ok {
o.ManagedFields = cast
}
}
if ownerReferences, ok := metadata.ExtraFields["ownerReferences"]; ok {
if cast, ok := ownerReferences.([]metav1.OwnerReference); ok {
o.OwnerReferences = cast
}
}
}
}
func (o *Dashboard) GetCreatedBy() string {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
return o.ObjectMeta.Annotations["grafana.com/createdBy"]
}
func (o *Dashboard) SetCreatedBy(createdBy string) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy
}
func (o *Dashboard) GetUpdateTimestamp() time.Time {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"])
return parsed
}
func (o *Dashboard) SetUpdateTimestamp(updateTimestamp time.Time) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339)
}
func (o *Dashboard) GetUpdatedBy() string {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
return o.ObjectMeta.Annotations["grafana.com/updatedBy"]
}
func (o *Dashboard) SetUpdatedBy(updatedBy string) {
if o.ObjectMeta.Annotations == nil {
o.ObjectMeta.Annotations = make(map[string]string)
}
o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy
}
func (o *Dashboard) Copy() resource.Object {
return resource.CopyObject(o)
}
func (o *Dashboard) DeepCopyObject() runtime.Object {
return o.Copy()
}
// Interface compliance compile-time check
var _ resource.Object = &Dashboard{}
// +k8s:openapi-gen=true
type DashboardList struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata" yaml:"metadata"`
Items []Dashboard `json:"items" yaml:"items"`
}
func (o *DashboardList) DeepCopyObject() runtime.Object {
return o.Copy()
}
func (o *DashboardList) Copy() resource.ListObject {
cpy := &DashboardList{
TypeMeta: o.TypeMeta,
Items: make([]Dashboard, len(o.Items)),
}
o.ListMeta.DeepCopyInto(&cpy.ListMeta)
for i := 0; i < len(o.Items); i++ {
if item, ok := o.Items[i].Copy().(*Dashboard); ok {
cpy.Items[i] = *item
}
}
return cpy
}
func (o *DashboardList) GetItems() []resource.Object {
items := make([]resource.Object, len(o.Items))
for i := 0; i < len(o.Items); i++ {
items[i] = &o.Items[i]
}
return items
}
func (o *DashboardList) SetItems(items []resource.Object) {
o.Items = make([]Dashboard, len(items))
for i := 0; i < len(items); i++ {
o.Items[i] = *items[i].(*Dashboard)
}
}
// Interface compliance compile-time check
var _ resource.ListObject = &DashboardList{}
@@ -0,0 +1,34 @@
//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v2alpha1
import (
"github.com/grafana/grafana-app-sdk/resource"
)
// schema is unexported to prevent accidental overwrites
var (
schemaDashboard = resource.NewSimpleSchema("dashboard.grafana.app", "v2alpha1", &Dashboard{}, &DashboardList{}, resource.WithKind("Dashboard"),
resource.WithPlural("dashboards"), resource.WithScope(resource.NamespacedScope))
kindDashboard = resource.Kind{
Schema: schemaDashboard,
Codecs: map[resource.KindEncoding]resource.Codec{
resource.KindEncodingJSON: &DashboardJSONCodec{},
},
}
)
// Kind returns a resource.Kind for this Schema with a JSON codec
func DashboardKind() resource.Kind {
return kindDashboard
}
// Schema returns a resource.SimpleSchema representation of Dashboard
func DashboardSchema() *resource.SimpleSchema {
return schemaDashboard
}
// Interface compliance checks
var _ resource.Schema = kindDashboard
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,34 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v2alpha1
// ConversionStatus is the status of the conversion of the dashboard.
// +k8s:openapi-gen=true
type DashboardConversionStatus struct {
// Whether from another version has failed.
// If true, means that the dashboard is not valid,
// and the caller should instead fetch the stored version.
Failed bool `json:"failed"`
// The version which was stored when the dashboard was created / updated.
// Fetching this version should always succeed.
StoredVersion string `json:"storedVersion"`
// The error message from the conversion.
// Empty if the conversion has not failed.
Error string `json:"error"`
}
// NewDashboardConversionStatus creates a new DashboardConversionStatus object.
func NewDashboardConversionStatus() *DashboardConversionStatus {
return &DashboardConversionStatus{}
}
// +k8s:openapi-gen=true
type DashboardStatus struct {
// Optional conversion status.
Conversion *DashboardConversionStatus `json:"conversion,omitempty"`
}
// NewDashboardStatus creates a new DashboardStatus object.
func NewDashboardStatus() *DashboardStatus {
return &DashboardStatus{}
}
+63
View File
@@ -0,0 +1,63 @@
package v2alpha1
import "reflect"
// TODO: these should be automatically generated by the SDK.
func (in *Dashboard) DeepCopyInto(out *Dashboard) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
}
func (in *Dashboard) DeepCopy() *Dashboard {
if in == nil {
return nil
}
out := new(Dashboard)
in.DeepCopyInto(out)
return out
}
func (in *DashboardList) DeepCopyInto(out *DashboardList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Dashboard, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
func (in *DashboardList) DeepCopy() *DashboardList {
if in == nil {
return nil
}
out := new(DashboardList)
in.DeepCopyInto(out)
return out
}
// TODO: we currently don't generate these methods for spec / status types.
// We probably should do that in the SDK.
func (in *DashboardSpec) DeepCopyInto(out *DashboardSpec) {
// TODO (@radiohead): since we don't generate this,
// I've added a manual reflection-based implementation for now.
val := reflect.ValueOf(in).Elem()
cpy := reflect.New(val.Type())
cpy.Elem().Set(val)
}
func (in *DashboardSpec) DeepCopy() *DashboardSpec {
if in == nil {
return nil
}
out := new(DashboardSpec)
in.DeepCopyInto(out)
return out
}
+4 -1
View File
@@ -1,7 +1,10 @@
// +k8s:deepcopy-gen=package
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +k8s:conversion-gen=github.com/grafana/grafana/pkg/apis/dashboard
// +groupName=dashboard.grafana.app
// NOTE (@radiohead): we do not use package-wide deepcopy generation
// because grafana-app-sdk already provides deepcopy functions.
// Kinds which are not generated by the SDK are explicitly opted in to deepcopy generation.
package v2alpha1 // import "github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1"
+7 -7
View File
@@ -32,7 +32,7 @@ var DashboardResourceInfo = utils.NewResourceInfo(GROUP, VERSION,
if dash != nil {
return []interface{}{
dash.Name,
dash.Spec.GetNestedString("title"),
dash.Spec.Title,
dash.CreationTimestamp.UTC().Format(time.RFC3339),
}, nil
}
@@ -54,14 +54,14 @@ var LibraryPanelResourceInfo = utils.NewResourceInfo(GROUP, VERSION,
{Name: "Created At", Type: "date"},
},
Reader: func(obj any) ([]interface{}, error) {
dash, ok := obj.(*LibraryPanel)
panel, ok := obj.(*LibraryPanel)
if ok {
if dash != nil {
if panel != nil {
return []interface{}{
dash.Name,
dash.Spec.Title,
dash.Spec.Type,
dash.CreationTimestamp.UTC().Format(time.RFC3339),
panel.Name,
panel.Spec.Title,
panel.Spec.Type,
panel.CreationTimestamp.UTC().Format(time.RFC3339),
}, nil
}
}
+11 -34
View File
@@ -7,40 +7,7 @@ import (
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Dashboard struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// The dashboard body (unstructured for now)
Spec common.Unstructured `json:"spec"`
// Optional dashboard status
Status *DashboardStatus `json:"status,omitempty"`
}
type DashboardStatus struct {
ConversionStatus *ConversionStatus `json:"conversion,omitempty"`
}
type ConversionStatus struct {
Failed bool `json:"failed,omitempty"`
StoredVersion string `json:"storedVersion,omitempty"`
Error string `json:"error,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []Dashboard `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardVersionList struct {
metav1.TypeMeta `json:",inline"`
@@ -50,6 +17,7 @@ type DashboardVersionList struct {
Items []DashboardVersionInfo `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
type DashboardVersionInfo struct {
// The internal ID for this version (will be replaced with resourceVersion)
Version int `json:"version"`
@@ -67,6 +35,7 @@ type DashboardVersionInfo struct {
Message string `json:"message,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:conversion-gen:explicit-from=net/url.Values
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VersionsQueryOptions struct {
@@ -80,6 +49,7 @@ type VersionsQueryOptions struct {
Version int64 `json:"version,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type LibraryPanel struct {
metav1.TypeMeta `json:",inline"`
@@ -95,6 +65,7 @@ type LibraryPanel struct {
Status *LibraryPanelStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type LibraryPanelList struct {
metav1.TypeMeta `json:",inline"`
@@ -104,6 +75,7 @@ type LibraryPanelList struct {
Items []LibraryPanel `json:"items,omitempty"`
}
// +k8s:deepcopy-gen=true
type LibraryPanelSpec struct {
// The panel type
Type string `json:"type"`
@@ -131,6 +103,7 @@ type LibraryPanelSpec struct {
Targets []data.DataQuery `json:"targets,omitempty"`
}
// +k8s:deepcopy-gen=true
type LibraryPanelStatus struct {
// Translation warnings (mostly things that were in SQL columns but not found in the saved body)
Warnings []string `json:"warnings,omitempty"`
@@ -140,6 +113,7 @@ type LibraryPanelStatus struct {
}
// This is like the legacy DTO where access and metadata are all returned in a single call
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardWithAccessInfo struct {
Dashboard `json:",inline"`
@@ -148,6 +122,7 @@ type DashboardWithAccessInfo struct {
}
// Information about how the requesting user can use a given dashboard
// +k8s:deepcopy-gen=true
type DashboardAccess struct {
// Metadata fields
Slug string `json:"slug,omitempty"`
@@ -162,11 +137,13 @@ type DashboardAccess struct {
AnnotationsPermissions *AnnotationPermission `json:"annotationsPermissions"`
}
// +k8s:deepcopy-gen=true
type AnnotationPermission struct {
Dashboard AnnotationActions `json:"dashboard"`
Organization AnnotationActions `json:"organization"`
}
// +k8s:deepcopy-gen=true
type AnnotationActions struct {
CanAdd bool `json:"canAdd"`
CanEdit bool `json:"canEdit"`
@@ -46,54 +46,6 @@ func (in *AnnotationPermission) DeepCopy() *AnnotationPermission {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ConversionStatus) DeepCopyInto(out *ConversionStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConversionStatus.
func (in *ConversionStatus) DeepCopy() *ConversionStatus {
if in == nil {
return nil
}
out := new(ConversionStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Dashboard) DeepCopyInto(out *Dashboard) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
if in.Status != nil {
in, out := &in.Status, &out.Status
*out = new(DashboardStatus)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Dashboard.
func (in *Dashboard) DeepCopy() *Dashboard {
if in == nil {
return nil
}
out := new(Dashboard)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Dashboard) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardAccess) DeepCopyInto(out *DashboardAccess) {
*out = *in
@@ -115,60 +67,6 @@ func (in *DashboardAccess) DeepCopy() *DashboardAccess {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardList) DeepCopyInto(out *DashboardList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Dashboard, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardList.
func (in *DashboardList) DeepCopy() *DashboardList {
if in == nil {
return nil
}
out := new(DashboardList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *DashboardList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardStatus) DeepCopyInto(out *DashboardStatus) {
*out = *in
if in.ConversionStatus != nil {
in, out := &in.ConversionStatus, &out.ConversionStatus
*out = new(ConversionStatus)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardStatus.
func (in *DashboardStatus) DeepCopy() *DashboardStatus {
if in == nil {
return nil
}
out := new(DashboardStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardVersionInfo) DeepCopyInto(out *DashboardVersionInfo) {
*out = *in
File diff suppressed because it is too large Load Diff
@@ -1,2 +1,65 @@
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardAdHocFilterWithLabels,ValueLabels
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardAdHocFilterWithLabels,Values
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardAdhocVariableSpec,BaseFilters
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardAdhocVariableSpec,DefaultKeys
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardAdhocVariableSpec,Filters
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardCustomVariableSpec,Options
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardDashboardLink,Tags
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardDatasourceVariableSpec,Options
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardFieldConfig,Links
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardFieldConfig,Mappings
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardFieldConfigSource,Overrides
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutRowSpec,Elements
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutSpec,Items
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGroupByVariableSpec,Options
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardIntervalVariableSpec,Options
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardMetadata,Finalizers
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardPanelSpec,Links
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryGroupSpec,Queries
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryGroupSpec,Transformations
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableSpec,Options
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardResponsiveGridLayoutSpec,Items
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardRowsLayoutSpec,Rows
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardSpec,Annotations
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardSpec,Links
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardSpec,Tags
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardSpec,Variables
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardStringOrArrayOfString,ArrayOfString
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardTabsLayoutSpec,Tabs
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardThresholdsConfig,Steps
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardTimeSettingsSpec,AutoRefreshIntervals
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardTimeSettingsSpec,QuickRanges
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardV2alpha1FieldConfigSourceOverrides,Properties
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,LibraryPanelStatus,Warnings
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardStatus,ConversionStatus
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutItemKindOrGridLayoutRowKind,GridLayoutItemKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutItemKindOrGridLayoutRowKind,GridLayoutRowKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind,GridLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind,ResponsiveGridLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind,TabsLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKind,GridLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKind,ResponsiveGridLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKind,RowsLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind,GridLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind,ResponsiveGridLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind,RowsLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardGridLayoutKindOrRowsLayoutKindOrResponsiveGridLayoutKindOrTabsLayoutKind,TabsLayoutKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardIntervalVariableSpec,AutoCount
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardIntervalVariableSpec,AutoMin
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardPanelKindOrLibraryPanelKind,LibraryPanelKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardPanelKindOrLibraryPanelKind,PanelKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,AdhocVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,ConstantVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,CustomVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,DatasourceVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,GroupByVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,IntervalVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,QueryVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardQueryVariableKindOrTextVariableKindOrConstantVariableKindOrDatasourceVariableKindOrIntervalVariableKindOrCustomVariableKindOrGroupByVariableKindOrAdhocVariableKind,TextVariableKind
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardStringOrArrayOfString,ArrayOfString
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardStringOrArrayOfString,String
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardStringOrFloat64,Float64
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardStringOrFloat64,String
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardValueMapOrRangeMapOrRegexMapOrSpecialValueMap,RangeMap
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardValueMapOrRangeMapOrRegexMapOrSpecialValueMap,RegexMap
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardValueMapOrRangeMapOrRegexMapOrSpecialValueMap,SpecialValueMap
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1,DashboardValueMapOrRangeMapOrRegexMapOrSpecialValueMap,ValueMap
+53
View File
@@ -0,0 +1,53 @@
//
// This file is generated by grafana-app-sdk
// DO NOT EDIT
//
package apis
import (
"encoding/json"
"github.com/grafana/grafana-app-sdk/app"
)
var ()
var appManifestData = app.ManifestData{
AppName: "dashboard",
Group: "dashboard.grafana.app",
Kinds: []app.ManifestKind{
{
Kind: "Dashboard",
Scope: "Namespaced",
Conversion: false,
Versions: []app.ManifestKindVersion{
{
Name: "v0alpha1",
},
{
Name: "v1alpha1",
},
{
Name: "v2alpha1",
},
},
},
},
}
func jsonToMap(j string) map[string]any {
m := make(map[string]any)
json.Unmarshal([]byte(j), &j)
return m
}
func LocalManifest() app.Manifest {
return app.NewEmbeddedManifest(appManifestData)
}
func RemoteManifest() app.Manifest {
return app.NewAPIServerManifest("dashboard")
}
+9 -11
View File
@@ -1,6 +1,7 @@
package dashboard
import (
"encoding/json"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
@@ -35,7 +36,11 @@ func NewDashboardLargeObjectSupport(scheme *runtime.Scheme) *apistore.BasicLarge
case *dashboardV1.Dashboard:
reduceUnstructredSpec(&dash.Spec)
case *dashboardV2.Dashboard:
reduceUnstructredSpec(&dash.Spec)
dash.Spec = dashboardV2.DashboardSpec{
Title: dash.Spec.Title,
Description: dash.Spec.Description,
Tags: dash.Spec.Tags,
}
default:
return fmt.Errorf("unsupported dashboard type %T", obj)
}
@@ -45,23 +50,16 @@ func NewDashboardLargeObjectSupport(scheme *runtime.Scheme) *apistore.BasicLarge
},
RebuildSpec: func(obj runtime.Object, blob []byte) error {
body := commonV0.Unstructured{}
err := body.UnmarshalJSON(blob)
if err != nil {
return err
}
switch dash := obj.(type) {
case *dashboardV0.Dashboard:
dash.Spec = body
return dash.Spec.UnmarshalJSON(blob)
case *dashboardV1.Dashboard:
dash.Spec = body
return dash.Spec.UnmarshalJSON(blob)
case *dashboardV2.Dashboard:
dash.Spec = body
return json.Unmarshal(blob, &dash.Spec)
default:
return fmt.Errorf("unsupported dashboard type %T", obj)
}
return nil
},
}
}
+1 -4
View File
@@ -38,10 +38,7 @@ func (b *DashboardsAPIBuilder) Mutate(ctx context.Context, a admission.Attribute
internalID = int64(id)
}
case *dashboardV2.Dashboard:
if id, ok := v.Spec.Object["id"].(float64); ok {
delete(v.Spec.Object, "id")
internalID = int64(id)
}
// Noop for V2
default:
return fmt.Errorf("mutation error: expected to dashboard, got %T", obj)
}
+10
View File
@@ -109,6 +109,16 @@ func RegisterAPIService(
}
func (b *DashboardsAPIBuilder) GetGroupVersions() []schema.GroupVersion {
if featuremgmt.AnyEnabled(b.features, featuremgmt.FlagUseV2DashboardsAPI) {
// If dashboards v2 is enabled, we want to use v2alpha1 as the default API version.
return []schema.GroupVersion{
dashboardv2alpha1.DashboardResourceInfo.GroupVersion(),
dashboardv0alpha1.DashboardResourceInfo.GroupVersion(),
dashboardv1alpha1.DashboardResourceInfo.GroupVersion(),
}
}
// TODO (@radiohead): should we switch to v1alpha1 by default?
return []schema.GroupVersion{
dashboardv0alpha1.DashboardResourceInfo.GroupVersion(),
dashboardv1alpha1.DashboardResourceInfo.GroupVersion(),
@@ -7,11 +7,15 @@ import (
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
"github.com/grafana/grafana/pkg/apis/dashboard/v1alpha1"
"github.com/grafana/grafana/pkg/apis/dashboard/v2alpha1"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/user"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/admission"
)
@@ -158,3 +162,93 @@ func TestDashboardAPIBuilder_Validate(t *testing.T) {
})
}
}
func TestDashboardAPIBuilder_GetGroupVersions(t *testing.T) {
tests := []struct {
name string
enabledFeatures []string
expected []schema.GroupVersion
}{
{
name: "should return v0alpha1 by default",
enabledFeatures: []string{},
expected: []schema.GroupVersion{
v0alpha1.DashboardResourceInfo.GroupVersion(),
v1alpha1.DashboardResourceInfo.GroupVersion(),
v2alpha1.DashboardResourceInfo.GroupVersion(),
},
},
{
name: "should return v0alpha1 as the default if some other feature is enabled",
enabledFeatures: []string{
featuremgmt.FlagKubernetesDashboards,
},
expected: []schema.GroupVersion{
v0alpha1.DashboardResourceInfo.GroupVersion(),
v1alpha1.DashboardResourceInfo.GroupVersion(),
v2alpha1.DashboardResourceInfo.GroupVersion(),
},
},
{
name: "should return v2alpha1 as the default if dashboards v2 is enabled",
enabledFeatures: []string{
featuremgmt.FlagUseV2DashboardsAPI,
},
expected: []schema.GroupVersion{
v2alpha1.DashboardResourceInfo.GroupVersion(),
v0alpha1.DashboardResourceInfo.GroupVersion(),
v1alpha1.DashboardResourceInfo.GroupVersion(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
builder := &DashboardsAPIBuilder{
features: newMockFeatureToggles(t, tt.enabledFeatures...),
}
require.Equal(t, tt.expected, builder.GetGroupVersions())
})
}
}
type mockFeatureToggles struct {
// We need to make a copy in `GetEnabled` anyway,
// so no need to store the original map as map[string]bool.
enabledFeatures map[string]struct{}
}
func newMockFeatureToggles(t *testing.T, enabledFeatures ...string) featuremgmt.FeatureToggles {
t.Helper()
res := &mockFeatureToggles{
enabledFeatures: make(map[string]struct{}, len(enabledFeatures)),
}
for _, f := range enabledFeatures {
res.enabledFeatures[f] = struct{}{}
}
return res
}
func (m *mockFeatureToggles) IsEnabledGlobally(feature string) bool {
_, ok := m.enabledFeatures[feature]
return ok
}
func (m *mockFeatureToggles) IsEnabled(ctx context.Context, feature string) bool {
_, ok := m.enabledFeatures[feature]
return ok
}
func (m *mockFeatureToggles) GetEnabled(ctx context.Context) map[string]bool {
res := make(map[string]bool, len(m.enabledFeatures))
for f := range m.enabledFeatures {
res[f] = true
}
return res
}
+1
View File
@@ -207,6 +207,7 @@ require (
github.com/grafana/authlib v0.0.0-20250305132846-37f49eb947fa // indirect
github.com/grafana/dataplane/sdata v0.0.9 // indirect
github.com/grafana/dskit v0.0.0-20241105154643-a6b453a88040 // indirect
github.com/grafana/grafana-app-sdk v0.31.0 // indirect
github.com/grafana/grafana-app-sdk/logging v0.30.0 // indirect
github.com/grafana/grafana-aws-sdk v0.31.5 // indirect
github.com/grafana/grafana-azure-sdk-go/v2 v2.1.6 // indirect
+2
View File
@@ -1265,6 +1265,8 @@ github.com/grafana/dataplane/sdata v0.0.9 h1:AGL1LZnCUG4MnQtnWpBPbQ8ZpptaZs14w6k
github.com/grafana/dataplane/sdata v0.0.9/go.mod h1:Jvs5ddpGmn6vcxT7tCTWAZ1mgi4sbcdFt9utQx5uMAU=
github.com/grafana/dskit v0.0.0-20241105154643-a6b453a88040 h1:IR+UNYHqaU31t8/TArJk8K/GlDwOyxMpGNkWCXeZ28g=
github.com/grafana/dskit v0.0.0-20241105154643-a6b453a88040/go.mod h1:SPLNCARd4xdjCkue0O6hvuoveuS1dGJjDnfxYe405YQ=
github.com/grafana/grafana-app-sdk v0.31.0 h1:/mFCcx+YqG8cWAi9hePDJQxIdtXDClDIDRgZwHkksFk=
github.com/grafana/grafana-app-sdk v0.31.0/go.mod h1:Xw00NL7qpRLo5r3Gn48Bl1Xn2n4eUDI5pYf/wMufKWs=
github.com/grafana/grafana-app-sdk/logging v0.30.0 h1:K/P/bm7Cp7Di4tqIJ3EQz2+842JozQGRaz62r95ApME=
github.com/grafana/grafana-app-sdk/logging v0.30.0/go.mod h1:xy6ZyVXl50Z3DBDLybvBPphbykPhuVNed/VNmen9DQM=
github.com/grafana/grafana-aws-sdk v0.31.5 h1:4HpMQx7n4Qqoi7Bgu8KHQ2QKT9fYYdHilX/Gh3FZKBE=
+1 -1
View File
@@ -133,6 +133,7 @@ require (
github.com/gorilla/mux v1.8.1 // indirect
github.com/grafana/alerting v0.0.0-20250310104713-16b885f1c79e // indirect
github.com/grafana/dataplane/sdata v0.0.9 // indirect
github.com/grafana/grafana-app-sdk v0.31.0 // indirect
github.com/grafana/grafana-app-sdk/logging v0.30.0 // indirect
github.com/grafana/grafana-aws-sdk v0.31.5 // indirect
github.com/grafana/grafana-azure-sdk-go/v2 v2.1.6 // indirect
@@ -214,7 +215,6 @@ require (
github.com/tjhop/slog-gokit v0.1.3 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/unknwon/bra v0.0.0-20200517080246-1e3013ecaff8 // indirect
github.com/unknwon/com v1.0.1 // indirect
github.com/unknwon/log v0.0.0-20200308114134-929b1006e34a // indirect
+2
View File
@@ -1160,6 +1160,8 @@ github.com/grafana/dataplane/sdata v0.0.9 h1:AGL1LZnCUG4MnQtnWpBPbQ8ZpptaZs14w6k
github.com/grafana/dataplane/sdata v0.0.9/go.mod h1:Jvs5ddpGmn6vcxT7tCTWAZ1mgi4sbcdFt9utQx5uMAU=
github.com/grafana/dskit v0.0.0-20241105154643-a6b453a88040 h1:IR+UNYHqaU31t8/TArJk8K/GlDwOyxMpGNkWCXeZ28g=
github.com/grafana/dskit v0.0.0-20241105154643-a6b453a88040/go.mod h1:SPLNCARd4xdjCkue0O6hvuoveuS1dGJjDnfxYe405YQ=
github.com/grafana/grafana-app-sdk v0.31.0 h1:/mFCcx+YqG8cWAi9hePDJQxIdtXDClDIDRgZwHkksFk=
github.com/grafana/grafana-app-sdk v0.31.0/go.mod h1:Xw00NL7qpRLo5r3Gn48Bl1Xn2n4eUDI5pYf/wMufKWs=
github.com/grafana/grafana-app-sdk/logging v0.30.0 h1:K/P/bm7Cp7Di4tqIJ3EQz2+842JozQGRaz62r95ApME=
github.com/grafana/grafana-app-sdk/logging v0.30.0/go.mod h1:xy6ZyVXl50Z3DBDLybvBPphbykPhuVNed/VNmen9DQM=
github.com/grafana/grafana-aws-sdk v0.31.5 h1:4HpMQx7n4Qqoi7Bgu8KHQ2QKT9fYYdHilX/Gh3FZKBE=
@@ -4,3 +4,7 @@ metadata:
name: test-v2
spec:
title: Test dashboard. Created at v2
layout:
kind: GridLayout
spec:
items: []
@@ -1490,24 +1490,12 @@
}
}
},
"com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.ConversionStatus": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"failed": {
"type": "boolean"
},
"storedVersion": {
"type": "string"
}
}
},
"com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.Dashboard": {
"type": "object",
"required": [
"spec"
"metadata",
"spec",
"status"
],
"properties": {
"apiVersion": {
@@ -1519,7 +1507,6 @@
"type": "string"
},
"metadata": {
"description": "Standard object's metadata More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
"default": {},
"allOf": [
{
@@ -1528,7 +1515,7 @@
]
},
"spec": {
"description": "The dashboard body (unstructured for now)",
"description": "Spec is the spec of the Dashboard",
"allOf": [
{
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apimachinery.apis.common.v0alpha1.Unstructured"
@@ -1536,7 +1523,7 @@
]
},
"status": {
"description": "Optional dashboard status",
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.DashboardStatus"
@@ -1553,7 +1540,6 @@
]
},
"com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.DashboardAccess": {
"description": "Information about how the requesting user can use a given dashboard",
"type": "object",
"required": [
"canSave",
@@ -1597,8 +1583,38 @@
}
}
},
"com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.DashboardConversionStatus": {
"description": "ConversionStatus is the status of the conversion of the dashboard.",
"type": "object",
"required": [
"failed",
"storedVersion",
"error"
],
"properties": {
"error": {
"description": "The error message from the conversion. Empty if the conversion has not failed.",
"type": "string",
"default": ""
},
"failed": {
"description": "Whether from another version has failed. If true, means that the dashboard is not valid, and the caller should instead fetch the stored version.",
"type": "boolean",
"default": false
},
"storedVersion": {
"description": "The version which was stored when the dashboard was created / updated. Fetching this version should always succeed.",
"type": "string",
"default": ""
}
}
},
"com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.DashboardList": {
"type": "object",
"required": [
"metadata",
"items"
],
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
@@ -1640,7 +1656,12 @@
"type": "object",
"properties": {
"conversion": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.ConversionStatus"
"description": "Optional conversion status.",
"allOf": [
{
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.DashboardConversionStatus"
}
]
}
}
},
@@ -1648,7 +1669,9 @@
"description": "This is like the legacy DTO where access and metadata are all returned in a single call",
"type": "object",
"required": [
"metadata",
"spec",
"status",
"access"
],
"properties": {
@@ -1669,7 +1692,6 @@
"type": "string"
},
"metadata": {
"description": "Standard object's metadata More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
"default": {},
"allOf": [
{
@@ -1678,7 +1700,7 @@
]
},
"spec": {
"description": "The dashboard body (unstructured for now)",
"description": "Spec is the spec of the Dashboard",
"allOf": [
{
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apimachinery.apis.common.v0alpha1.Unstructured"
@@ -1686,7 +1708,7 @@
]
},
"status": {
"description": "Optional dashboard status",
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.dashboard.v0alpha1.DashboardStatus"