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
+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"},
}
}