K8s: Move shared apis to a common folder with shared openapi spec (#80484)

This commit is contained in:
Ryan McKinley
2024-01-12 12:05:30 -08:00
committed by GitHub
parent 81c45bfe44
commit bb05a6f58f
25 changed files with 2700 additions and 269 deletions
+4
View File
@@ -0,0 +1,4 @@
// +k8s:openapi-gen=true
// +groupName=common.grafana.app
package v0alpha1 // import "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
@@ -1,4 +1,4 @@
package apis
package v0alpha1
import (
"k8s.io/apimachinery/pkg/api/errors"
@@ -8,6 +8,7 @@ import (
)
// ResourceInfo helps define a k8s resource
// +k8s:openapi-gen=false
type ResourceInfo struct {
group string
version string
@@ -5,15 +5,33 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
runtime "k8s.io/apimachinery/pkg/runtime"
openapi "k8s.io/kube-openapi/pkg/common"
spec "k8s.io/kube-openapi/pkg/validation/spec"
)
// Unstructured allows objects that do not have Golang structs registered to be manipulated
// generically.
type Unstructured struct {
// Object is a JSON compatible map with string, float, int, bool, []interface{}, or
// map[string]interface{}
// children.
Object map[string]interface{}
// Object is a JSON compatible map with string, float, int, bool, []interface{},
// or map[string]interface{} children.
Object map[string]any
}
// Produce an API definition that represents map[string]any
func (u Unstructured) OpenAPIDefinition() openapi.OpenAPIDefinition {
return openapi.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{Allows: true},
},
VendorExtensible: spec.VendorExtensible{
Extensions: map[string]interface{}{
"x-kubernetes-preserve-unknown-fields": true,
},
},
},
}
}
func (u *Unstructured) UnstructuredContent() map[string]interface{} {
@@ -0,0 +1,19 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by defaulter-gen. DO NOT EDIT.
package v0alpha1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// RegisterDefaults adds defaulters functions to the given scheme.
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
return nil
}
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
package v0alpha1
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
const (
GROUP = "dashboard.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
)
var DashboardResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"dashboards", "dashboard", "Dashboard",
func() runtime.Object { return &Dashboard{} },
func() runtime.Object { return &DashboardList{} },
)
var DashboardSummaryResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"summary", "summary", "DashboardSummary",
func() runtime.Object { return &DashboardSummary{} },
func() runtime.Object { return &DashboardSummaryList{} },
)
var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: GROUP, Version: VERSION}
)
+2 -21
View File
@@ -2,27 +2,8 @@ package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"github.com/grafana/grafana/pkg/apis"
)
const (
GROUP = "dashboard.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
)
var DashboardResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
"dashboards", "dashboard", "Dashboard",
func() runtime.Object { return &Dashboard{} },
func() runtime.Object { return &DashboardList{} },
)
var DashboardSummaryResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
"summary", "summary", "DashboardSummary",
func() runtime.Object { return &DashboardSummary{} },
func() runtime.Object { return &DashboardSummaryList{} },
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -34,7 +15,7 @@ type Dashboard struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
// The dashboard body (unstructured for now)
Spec Unstructured `json:"spec"`
Spec common.Unstructured `json:"spec"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -27,7 +27,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummarySpec": schema_pkg_apis_dashboard_v0alpha1_DashboardSummarySpec(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.DashboardVersionsInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionsInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Unstructured": schema_pkg_apis_dashboard_v0alpha1_Unstructured(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.VersionsQueryOptions": schema_pkg_apis_dashboard_v0alpha1_VersionsQueryOptions(ref),
"k8s.io/apimachinery/pkg/apis/meta/v1.APIGroup": schema_pkg_apis_meta_v1_APIGroup(ref),
"k8s.io/apimachinery/pkg/apis/meta/v1.APIGroupList": schema_pkg_apis_meta_v1_APIGroupList(ref),
@@ -176,7 +175,7 @@ func schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref common.ReferenceCallback)
SchemaProps: spec.SchemaProps{
Description: "The dashboard body (unstructured for now)",
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Unstructured"),
Ref: ref("github.com/grafana/grafana/pkg/apis/common/v0alpha1.Unstructured"),
},
},
},
@@ -184,7 +183,7 @@ func schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref common.ReferenceCallback)
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Unstructured", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
"github.com/grafana/grafana/pkg/apis/common/v0alpha1.Unstructured", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
}
}
@@ -519,35 +518,6 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardVersionsInfo(ref common.Referen
}
}
func schema_pkg_apis_dashboard_v0alpha1_Unstructured(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "Unstructured allows objects that do not have Golang structs registered to be manipulated generically.",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"Object": {
SchemaProps: spec.SchemaProps{
Description: "Object is a JSON compatible map with string, float, int, bool, []interface{}, or map[string]interface{} children.",
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Allows: true,
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Format: "",
},
},
},
},
},
},
Required: []string{"Object"},
},
},
}
}
func schema_pkg_apis_dashboard_v0alpha1_VersionsQueryOptions(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
+18
View File
@@ -0,0 +1,18 @@
package v0alpha1
import (
"k8s.io/apimachinery/pkg/runtime"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
const (
GROUP = "*.datasource.grafana.app"
VERSION = "v0alpha1"
)
var GenericConnectionResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"connections", "connection", "DataSourceConnection",
func() runtime.Object { return &DataSourceConnection{} },
func() runtime.Object { return &DataSourceConnectionList{} },
)
+2 -14
View File
@@ -2,20 +2,8 @@ package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"github.com/grafana/grafana/pkg/apis"
)
const (
GROUP = "*.datasource.grafana.app"
VERSION = "v0alpha1"
)
var GenericConnectionResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
"connections", "connection", "DataSourceConnection",
func() runtime.Object { return &DataSourceConnection{} },
func() runtime.Object { return &DataSourceConnectionList{} },
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -53,5 +41,5 @@ type HealthCheckResult struct {
Message string `json:"message,omitempty"`
// Spec depends on the the plugin
Details *Unstructured `json:"details,omitempty"`
Details *common.Unstructured `json:"details,omitempty"`
}
@@ -1,100 +0,0 @@
package v0alpha1
import (
"encoding/json"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
runtime "k8s.io/apimachinery/pkg/runtime"
)
// Unstructured allows objects that do not have Golang structs registered to be manipulated
// generically.
type Unstructured struct {
// Object is a JSON compatible map with string, float, int, bool, []interface{}, or
// map[string]interface{}
// children.
Object map[string]interface{}
}
func (u *Unstructured) UnstructuredContent() map[string]interface{} {
if u.Object == nil {
return make(map[string]interface{})
}
return u.Object
}
func (u *Unstructured) SetUnstructuredContent(content map[string]interface{}) {
u.Object = content
}
// MarshalJSON ensures that the unstructured object produces proper
// JSON when passed to Go's standard JSON library.
func (u *Unstructured) MarshalJSON() ([]byte, error) {
return json.Marshal(u.Object)
}
// UnmarshalJSON ensures that the unstructured object properly decodes
// JSON when passed to Go's standard JSON library.
func (u *Unstructured) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &u.Object)
}
func (u *Unstructured) DeepCopy() *Unstructured {
if u == nil {
return nil
}
out := new(Unstructured)
*out = *u
out.Object = runtime.DeepCopyJSON(u.Object)
return out
}
func (u *Unstructured) DeepCopyInto(out *Unstructured) {
clone := u.DeepCopy()
*out = *clone
}
func (u *Unstructured) Set(field string, value interface{}) {
if u.Object == nil {
u.Object = make(map[string]interface{})
}
_ = unstructured.SetNestedField(u.Object, value, field)
}
func (u *Unstructured) Remove(fields ...string) {
if u.Object == nil {
u.Object = make(map[string]interface{})
}
unstructured.RemoveNestedField(u.Object, fields...)
}
func (u *Unstructured) SetNestedField(value interface{}, fields ...string) {
if u.Object == nil {
u.Object = make(map[string]interface{})
}
_ = unstructured.SetNestedField(u.Object, value, fields...)
}
func (u *Unstructured) GetNestedString(fields ...string) string {
val, found, err := unstructured.NestedString(u.Object, fields...)
if !found || err != nil {
return ""
}
return val
}
func (u *Unstructured) GetNestedStringSlice(fields ...string) []string {
val, found, err := unstructured.NestedStringSlice(u.Object, fields...)
if !found || err != nil {
return nil
}
return val
}
func (u *Unstructured) GetNestedInt64(fields ...string) int64 {
val, found, err := unstructured.NestedInt64(u.Object, fields...)
if !found || err != nil {
return 0
}
return val
}
@@ -20,7 +20,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1.DataSourceConnection": schema_pkg_apis_datasource_v0alpha1_DataSourceConnection(ref),
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1.DataSourceConnectionList": schema_pkg_apis_datasource_v0alpha1_DataSourceConnectionList(ref),
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1.HealthCheckResult": schema_pkg_apis_datasource_v0alpha1_HealthCheckResult(ref),
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1.Unstructured": schema_pkg_apis_datasource_v0alpha1_Unstructured(ref),
"k8s.io/apimachinery/pkg/apis/meta/v1.APIGroup": schema_pkg_apis_meta_v1_APIGroup(ref),
"k8s.io/apimachinery/pkg/apis/meta/v1.APIGroupList": schema_pkg_apis_meta_v1_APIGroupList(ref),
"k8s.io/apimachinery/pkg/apis/meta/v1.APIResource": schema_pkg_apis_meta_v1_APIResource(ref),
@@ -217,44 +216,14 @@ func schema_pkg_apis_datasource_v0alpha1_HealthCheckResult(ref common.ReferenceC
"details": {
SchemaProps: spec.SchemaProps{
Description: "Spec depends on the the plugin",
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/datasource/v0alpha1.Unstructured"),
Ref: ref("github.com/grafana/grafana/pkg/apis/common/v0alpha1.Unstructured"),
},
},
},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1.Unstructured"},
}
}
func schema_pkg_apis_datasource_v0alpha1_Unstructured(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "Unstructured allows objects that do not have Golang structs registered to be manipulated generically.",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"Object": {
SchemaProps: spec.SchemaProps{
Description: "Object is a JSON compatible map with string, float, int, bool, []interface{}, or map[string]interface{} children.",
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Allows: true,
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Format: "",
},
},
},
},
},
},
Required: []string{"Object"},
},
},
"github.com/grafana/grafana/pkg/apis/common/v0alpha1.Unstructured"},
}
}
+30
View File
@@ -0,0 +1,30 @@
package v0alpha1
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
const (
GROUP = "example.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
)
var RuntimeResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"runtime", "runtime", "RuntimeInfo",
func() runtime.Object { return &RuntimeInfo{} },
func() runtime.Object { return &RuntimeInfo{} },
)
var DummyResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"dummy", "dummy", "DummyResource",
func() runtime.Object { return &DummyResource{} },
func() runtime.Object { return &DummyResourceList{} },
)
var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: GROUP, Version: VERSION}
)
-20
View File
@@ -2,26 +2,6 @@ package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"github.com/grafana/grafana/pkg/apis"
)
const (
GROUP = "example.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
)
var RuntimeResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
"runtime", "runtime", "RuntimeInfo",
func() runtime.Object { return &RuntimeInfo{} },
func() runtime.Object { return &RuntimeInfo{} },
)
var DummyResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
"dummy", "dummy", "DummyResource",
func() runtime.Object { return &DummyResource{} },
func() runtime.Object { return &DummyResourceList{} },
)
// Mirrors the info exposed in "github.com/grafana/grafana/pkg/setting"
+26
View File
@@ -0,0 +1,26 @@
package v0alpha1
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
const (
GROUP = "folders.grafana.app"
VERSION = "v0alpha1"
RESOURCE = "folders"
APIVERSION = GROUP + "/" + VERSION
)
var FolderResourceInfo = common.NewResourceInfo(GROUP, VERSION,
RESOURCE, "folder", "Folder",
func() runtime.Object { return &Folder{} },
func() runtime.Object { return &FolderList{} },
)
var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: GROUP, Version: VERSION}
)
-16
View File
@@ -2,22 +2,6 @@ package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"github.com/grafana/grafana/pkg/apis"
)
const (
GROUP = "folders.grafana.app"
VERSION = "v0alpha1"
RESOURCE = "folders"
APIVERSION = GROUP + "/" + VERSION
)
var FolderResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
RESOURCE, "folder", "Folder",
func() runtime.Object { return &Folder{} },
func() runtime.Object { return &FolderList{} },
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+25
View File
@@ -0,0 +1,25 @@
package v0alpha1
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
const (
GROUP = "playlist.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
)
var PlaylistResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"playlists", "playlist", "Playlist",
func() runtime.Object { return &Playlist{} },
func() runtime.Object { return &PlaylistList{} },
)
var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: GROUP, Version: VERSION}
)
-15
View File
@@ -2,21 +2,6 @@ package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"github.com/grafana/grafana/pkg/apis"
)
const (
GROUP = "playlist.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
)
var PlaylistResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
"playlists", "playlist", "Playlist",
func() runtime.Object { return &Playlist{} },
func() runtime.Object { return &PlaylistList{} },
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/grafana/grafana/pkg/apis"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
const (
@@ -14,7 +14,7 @@ const (
APIVERSION = GROUP + "/" + VERSION
)
var ExternalNameResourceInfo = apis.NewResourceInfo(GROUP, VERSION,
var ExternalNameResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"externalnames", "externalname", "ExternalName",
func() runtime.Object { return &ExternalName{} },
func() runtime.Object { return &ExternalNameList{} },
@@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
"github.com/grafana/grafana/pkg/apis"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
"github.com/grafana/grafana/pkg/registry/apis/dashboard/access"
"github.com/grafana/grafana/pkg/services/grafana-apiserver/endpoints/request"
@@ -29,7 +29,7 @@ var (
)
type dashboardStorage struct {
resource apis.ResourceInfo
resource common.ResourceInfo
access access.DashboardAccess
tableConverter rest.TableConvertor
}
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
"github.com/grafana/grafana/pkg/services/grafana-apiserver/endpoints/request"
@@ -72,7 +73,7 @@ func (r *VersionsREST) Connect(ctx context.Context, uid string, opts runtime.Obj
Name: uid,
CreationTimestamp: metav1.NewTime(dto.Created),
},
Spec: v0alpha1.Unstructured{Object: data},
Spec: common.Unstructured{Object: data},
}
responder.Object(100, dash)
return
@@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
"github.com/grafana/grafana/pkg/apis"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/registry/apis/dashboard/access"
"github.com/grafana/grafana/pkg/services/grafana-apiserver/endpoints/request"
)
@@ -22,7 +22,7 @@ var (
)
type summaryStorage struct {
resource apis.ResourceInfo
resource common.ResourceInfo
access access.DashboardAccess
tableConverter rest.TableConvertor
}
+2 -2
View File
@@ -10,7 +10,7 @@ import (
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"github.com/grafana/grafana/pkg/apis"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
"github.com/grafana/grafana/pkg/kinds"
"github.com/grafana/grafana/pkg/services/datasources"
@@ -26,7 +26,7 @@ var (
)
type connectionAccess struct {
resourceInfo apis.ResourceInfo
resourceInfo common.ResourceInfo
tableConverter rest.TableConvertor
builder *DataSourceAPIBuilder
}
+4 -4
View File
@@ -14,10 +14,10 @@ import (
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
common "k8s.io/kube-openapi/pkg/common"
openapi "k8s.io/kube-openapi/pkg/common"
"k8s.io/utils/strings/slices"
"github.com/grafana/grafana/pkg/apis"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/plugins"
@@ -35,7 +35,7 @@ var _ grafanaapiserver.APIGroupBuilder = (*DataSourceAPIBuilder)(nil)
// This is used just so wire has something unique to return
type DataSourceAPIBuilder struct {
connectionResourceInfo apis.ResourceInfo
connectionResourceInfo common.ResourceInfo
plugin plugins.JSONData
client plugins.Client
@@ -187,7 +187,7 @@ func (b *DataSourceAPIBuilder) GetAPIGroupInfo(
return &apiGroupInfo, nil
}
func (b *DataSourceAPIBuilder) GetOpenAPIDefinitions() common.GetOpenAPIDefinitions {
func (b *DataSourceAPIBuilder) GetOpenAPIDefinitions() openapi.GetOpenAPIDefinitions {
return v0alpha1.GetOpenAPIDefinitions
}
@@ -6,12 +6,15 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
common "k8s.io/kube-openapi/pkg/common"
spec "k8s.io/kube-openapi/pkg/validation/spec"
"github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
// This should eventually live in grafana-app-sdk
func GetOpenAPIDefinitions(builders []APIGroupBuilder) common.GetOpenAPIDefinitions {
return func(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
defs := getStandardOpenAPIDefinitions(ref)
maps.Copy(defs, v0alpha1.GetOpenAPIDefinitions(ref)) // common grafana apis
for _, builder := range builders {
g := builder.GetOpenAPIDefinitions()
if g != nil {