mirror of https://github.com/grafana/grafana
K8s/Playlist: Refactor apis packages so the types and registry are in different packages (#77586)
parent
72ed6434ca
commit
dd654fdc87
@ -1,4 +0,0 @@ |
||||
// +k8s:deepcopy-gen=package
|
||||
// +groupName=playlist.grafana.app
|
||||
|
||||
package playlist // import "github.com/grafana/grafana/pkg/apis/playlist"
|
@ -1,65 +0,0 @@ |
||||
package playlist |
||||
|
||||
import ( |
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
||||
) |
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
type Playlist 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"` |
||||
|
||||
Spec Spec `json:"spec,omitempty"` |
||||
} |
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
type PlaylistList struct { |
||||
metav1.TypeMeta `json:",inline"` |
||||
// +optional
|
||||
metav1.ListMeta `json:"metadata,omitempty"` |
||||
|
||||
Items []Playlist `json:"items,omitempty"` |
||||
} |
||||
|
||||
// Spec defines model for Spec.
|
||||
type Spec struct { |
||||
// Name of the playlist.
|
||||
Title string `json:"title"` |
||||
|
||||
// Interval sets the time between switching views in a playlist.
|
||||
Interval string `json:"interval"` |
||||
|
||||
// The ordered list of items that the playlist will iterate over.
|
||||
Items []Item `json:"items,omitempty"` |
||||
} |
||||
|
||||
// Defines values for ItemType.
|
||||
const ( |
||||
ItemTypeDashboardByTag ItemType = "dashboard_by_tag" |
||||
ItemTypeDashboardByUid ItemType = "dashboard_by_uid" |
||||
|
||||
// deprecated -- should use UID
|
||||
ItemTypeDashboardById ItemType = "dashboard_by_id" |
||||
) |
||||
|
||||
// Item defines model for Item.
|
||||
type Item struct { |
||||
// Type of the item.
|
||||
Type ItemType `json:"type"` |
||||
|
||||
// Value depends on type and describes the playlist item.
|
||||
//
|
||||
// - dashboard_by_id: The value is an internal numerical identifier set by Grafana. This
|
||||
// is not portable as the numerical identifier is non-deterministic between different instances.
|
||||
// Will be replaced by dashboard_by_uid in the future. (deprecated)
|
||||
// - dashboard_by_tag: The value is a tag which is set on any number of dashboards. All
|
||||
// dashboards behind the tag will be added to the playlist.
|
||||
// - dashboard_by_uid: The value is the dashboard UID
|
||||
Value string `json:"value"` |
||||
} |
||||
|
||||
// Type of the item.
|
||||
type ItemType string |
@ -1,74 +0,0 @@ |
||||
package v0alpha1 |
||||
|
||||
import ( |
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
||||
"k8s.io/apimachinery/pkg/runtime" |
||||
"k8s.io/apimachinery/pkg/runtime/schema" |
||||
"k8s.io/apimachinery/pkg/runtime/serializer" |
||||
"k8s.io/apiserver/pkg/registry/generic" |
||||
genericapiserver "k8s.io/apiserver/pkg/server" |
||||
common "k8s.io/kube-openapi/pkg/common" |
||||
|
||||
grafanaapiserver "github.com/grafana/grafana/pkg/services/grafana-apiserver" |
||||
"github.com/grafana/grafana/pkg/services/grafana-apiserver/endpoints/request" |
||||
"github.com/grafana/grafana/pkg/services/playlist" |
||||
"github.com/grafana/grafana/pkg/setting" |
||||
) |
||||
|
||||
// GroupName is the group name for this API.
|
||||
const GroupName = "playlist.grafana.app" |
||||
const VersionID = "v0alpha1" |
||||
|
||||
var _ grafanaapiserver.APIGroupBuilder = (*PlaylistAPIBuilder)(nil) |
||||
|
||||
// This is used just so wire has something unique to return
|
||||
type PlaylistAPIBuilder struct { |
||||
service playlist.Service |
||||
namespacer request.NamespaceMapper |
||||
gv schema.GroupVersion |
||||
} |
||||
|
||||
func RegisterAPIService(p playlist.Service, |
||||
apiregistration grafanaapiserver.APIRegistrar, |
||||
cfg *setting.Cfg, |
||||
) *PlaylistAPIBuilder { |
||||
builder := &PlaylistAPIBuilder{ |
||||
service: p, |
||||
namespacer: request.GetNamespaceMapper(cfg), |
||||
gv: schema.GroupVersion{Group: GroupName, Version: VersionID}, |
||||
} |
||||
apiregistration.RegisterAPI(builder) |
||||
return builder |
||||
} |
||||
|
||||
func (b *PlaylistAPIBuilder) GetGroupVersion() schema.GroupVersion { |
||||
return b.gv |
||||
} |
||||
|
||||
func (b *PlaylistAPIBuilder) InstallSchema(scheme *runtime.Scheme) error { |
||||
scheme.AddKnownTypes(b.gv, |
||||
&Playlist{}, |
||||
&PlaylistList{}, |
||||
) |
||||
if err := RegisterConversions(scheme); err != nil { |
||||
return err |
||||
} |
||||
metav1.AddToGroupVersion(scheme, b.gv) |
||||
return scheme.SetVersionPriority(b.gv) |
||||
} |
||||
|
||||
func (b *PlaylistAPIBuilder) GetAPIGroupInfo( |
||||
scheme *runtime.Scheme, |
||||
codecs serializer.CodecFactory, // pointer?
|
||||
optsGetter generic.RESTOptionsGetter, |
||||
) (*genericapiserver.APIGroupInfo, error) { |
||||
return nil, nil |
||||
} |
||||
|
||||
func (b *PlaylistAPIBuilder) GetOpenAPIDefinitions() common.GetOpenAPIDefinitions { |
||||
return getOpenAPIDefinitions |
||||
} |
||||
|
||||
func (b *PlaylistAPIBuilder) GetAPIRoutes() *grafanaapiserver.APIRoutes { |
||||
return nil // no custom API routes
|
||||
} |
@ -1,170 +0,0 @@ |
||||
//go:build !ignore_autogenerated
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/* |
||||
Copyright The Kubernetes Authors. |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
*/ |
||||
|
||||
// Code generated by conversion-gen. DO NOT EDIT.
|
||||
|
||||
package v0alpha1 |
||||
|
||||
import ( |
||||
unsafe "unsafe" |
||||
|
||||
playlist "github.com/grafana/grafana/pkg/apis/playlist" |
||||
conversion "k8s.io/apimachinery/pkg/conversion" |
||||
runtime "k8s.io/apimachinery/pkg/runtime" |
||||
) |
||||
|
||||
// RegisterConversions adds conversion functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
func RegisterConversions(s *runtime.Scheme) error { |
||||
if err := s.AddGeneratedConversionFunc((*Item)(nil), (*playlist.Item)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_v0alpha1_Item_To_playlist_Item(a.(*Item), b.(*playlist.Item), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
if err := s.AddGeneratedConversionFunc((*playlist.Item)(nil), (*Item)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_playlist_Item_To_v0alpha1_Item(a.(*playlist.Item), b.(*Item), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
if err := s.AddGeneratedConversionFunc((*Playlist)(nil), (*playlist.Playlist)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_v0alpha1_Playlist_To_playlist_Playlist(a.(*Playlist), b.(*playlist.Playlist), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
if err := s.AddGeneratedConversionFunc((*playlist.Playlist)(nil), (*Playlist)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_playlist_Playlist_To_v0alpha1_Playlist(a.(*playlist.Playlist), b.(*Playlist), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
if err := s.AddGeneratedConversionFunc((*PlaylistList)(nil), (*playlist.PlaylistList)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_v0alpha1_PlaylistList_To_playlist_PlaylistList(a.(*PlaylistList), b.(*playlist.PlaylistList), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
if err := s.AddGeneratedConversionFunc((*playlist.PlaylistList)(nil), (*PlaylistList)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_playlist_PlaylistList_To_v0alpha1_PlaylistList(a.(*playlist.PlaylistList), b.(*PlaylistList), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
if err := s.AddGeneratedConversionFunc((*Spec)(nil), (*playlist.Spec)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_v0alpha1_Spec_To_playlist_Spec(a.(*Spec), b.(*playlist.Spec), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
if err := s.AddGeneratedConversionFunc((*playlist.Spec)(nil), (*Spec)(nil), func(a, b interface{}, scope conversion.Scope) error { |
||||
return Convert_playlist_Spec_To_v0alpha1_Spec(a.(*playlist.Spec), b.(*Spec), scope) |
||||
}); err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func autoConvert_v0alpha1_Item_To_playlist_Item(in *Item, out *playlist.Item, s conversion.Scope) error { |
||||
out.Type = playlist.ItemType(in.Type) |
||||
out.Value = in.Value |
||||
return nil |
||||
} |
||||
|
||||
// Convert_v0alpha1_Item_To_playlist_Item is an autogenerated conversion function.
|
||||
func Convert_v0alpha1_Item_To_playlist_Item(in *Item, out *playlist.Item, s conversion.Scope) error { |
||||
return autoConvert_v0alpha1_Item_To_playlist_Item(in, out, s) |
||||
} |
||||
|
||||
func autoConvert_playlist_Item_To_v0alpha1_Item(in *playlist.Item, out *Item, s conversion.Scope) error { |
||||
out.Type = ItemType(in.Type) |
||||
out.Value = in.Value |
||||
return nil |
||||
} |
||||
|
||||
// Convert_playlist_Item_To_v0alpha1_Item is an autogenerated conversion function.
|
||||
func Convert_playlist_Item_To_v0alpha1_Item(in *playlist.Item, out *Item, s conversion.Scope) error { |
||||
return autoConvert_playlist_Item_To_v0alpha1_Item(in, out, s) |
||||
} |
||||
|
||||
func autoConvert_v0alpha1_Playlist_To_playlist_Playlist(in *Playlist, out *playlist.Playlist, s conversion.Scope) error { |
||||
out.ObjectMeta = in.ObjectMeta |
||||
if err := Convert_v0alpha1_Spec_To_playlist_Spec(&in.Spec, &out.Spec, s); err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// Convert_v0alpha1_Playlist_To_playlist_Playlist is an autogenerated conversion function.
|
||||
func Convert_v0alpha1_Playlist_To_playlist_Playlist(in *Playlist, out *playlist.Playlist, s conversion.Scope) error { |
||||
return autoConvert_v0alpha1_Playlist_To_playlist_Playlist(in, out, s) |
||||
} |
||||
|
||||
func autoConvert_playlist_Playlist_To_v0alpha1_Playlist(in *playlist.Playlist, out *Playlist, s conversion.Scope) error { |
||||
out.ObjectMeta = in.ObjectMeta |
||||
if err := Convert_playlist_Spec_To_v0alpha1_Spec(&in.Spec, &out.Spec, s); err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// Convert_playlist_Playlist_To_v0alpha1_Playlist is an autogenerated conversion function.
|
||||
func Convert_playlist_Playlist_To_v0alpha1_Playlist(in *playlist.Playlist, out *Playlist, s conversion.Scope) error { |
||||
return autoConvert_playlist_Playlist_To_v0alpha1_Playlist(in, out, s) |
||||
} |
||||
|
||||
func autoConvert_v0alpha1_PlaylistList_To_playlist_PlaylistList(in *PlaylistList, out *playlist.PlaylistList, s conversion.Scope) error { |
||||
out.ListMeta = in.ListMeta |
||||
out.Items = *(*[]playlist.Playlist)(unsafe.Pointer(&in.Items)) |
||||
return nil |
||||
} |
||||
|
||||
// Convert_v0alpha1_PlaylistList_To_playlist_PlaylistList is an autogenerated conversion function.
|
||||
func Convert_v0alpha1_PlaylistList_To_playlist_PlaylistList(in *PlaylistList, out *playlist.PlaylistList, s conversion.Scope) error { |
||||
return autoConvert_v0alpha1_PlaylistList_To_playlist_PlaylistList(in, out, s) |
||||
} |
||||
|
||||
func autoConvert_playlist_PlaylistList_To_v0alpha1_PlaylistList(in *playlist.PlaylistList, out *PlaylistList, s conversion.Scope) error { |
||||
out.ListMeta = in.ListMeta |
||||
out.Items = *(*[]Playlist)(unsafe.Pointer(&in.Items)) |
||||
return nil |
||||
} |
||||
|
||||
// Convert_playlist_PlaylistList_To_v0alpha1_PlaylistList is an autogenerated conversion function.
|
||||
func Convert_playlist_PlaylistList_To_v0alpha1_PlaylistList(in *playlist.PlaylistList, out *PlaylistList, s conversion.Scope) error { |
||||
return autoConvert_playlist_PlaylistList_To_v0alpha1_PlaylistList(in, out, s) |
||||
} |
||||
|
||||
func autoConvert_v0alpha1_Spec_To_playlist_Spec(in *Spec, out *playlist.Spec, s conversion.Scope) error { |
||||
out.Title = in.Title |
||||
out.Interval = in.Interval |
||||
out.Items = *(*[]playlist.Item)(unsafe.Pointer(&in.Items)) |
||||
return nil |
||||
} |
||||
|
||||
// Convert_v0alpha1_Spec_To_playlist_Spec is an autogenerated conversion function.
|
||||
func Convert_v0alpha1_Spec_To_playlist_Spec(in *Spec, out *playlist.Spec, s conversion.Scope) error { |
||||
return autoConvert_v0alpha1_Spec_To_playlist_Spec(in, out, s) |
||||
} |
||||
|
||||
func autoConvert_playlist_Spec_To_v0alpha1_Spec(in *playlist.Spec, out *Spec, s conversion.Scope) error { |
||||
out.Title = in.Title |
||||
out.Interval = in.Interval |
||||
out.Items = *(*[]Item)(unsafe.Pointer(&in.Items)) |
||||
return nil |
||||
} |
||||
|
||||
// Convert_playlist_Spec_To_v0alpha1_Spec is an autogenerated conversion function.
|
||||
func Convert_playlist_Spec_To_v0alpha1_Spec(in *playlist.Spec, out *Spec, s conversion.Scope) error { |
||||
return autoConvert_playlist_Spec_To_v0alpha1_Spec(in, out, s) |
||||
} |
@ -1,123 +0,0 @@ |
||||
//go:build !ignore_autogenerated
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/* |
||||
Copyright The Kubernetes Authors. |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
*/ |
||||
|
||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
||||
|
||||
package playlist |
||||
|
||||
import ( |
||||
runtime "k8s.io/apimachinery/pkg/runtime" |
||||
) |
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Item) DeepCopyInto(out *Item) { |
||||
*out = *in |
||||
return |
||||
} |
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Item.
|
||||
func (in *Item) DeepCopy() *Item { |
||||
if in == nil { |
||||
return nil |
||||
} |
||||
out := new(Item) |
||||
in.DeepCopyInto(out) |
||||
return out |
||||
} |
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Playlist) DeepCopyInto(out *Playlist) { |
||||
*out = *in |
||||
out.TypeMeta = in.TypeMeta |
||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) |
||||
in.Spec.DeepCopyInto(&out.Spec) |
||||
return |
||||
} |
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Playlist.
|
||||
func (in *Playlist) DeepCopy() *Playlist { |
||||
if in == nil { |
||||
return nil |
||||
} |
||||
out := new(Playlist) |
||||
in.DeepCopyInto(out) |
||||
return out |
||||
} |
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *Playlist) 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 *PlaylistList) DeepCopyInto(out *PlaylistList) { |
||||
*out = *in |
||||
out.TypeMeta = in.TypeMeta |
||||
in.ListMeta.DeepCopyInto(&out.ListMeta) |
||||
if in.Items != nil { |
||||
in, out := &in.Items, &out.Items |
||||
*out = make([]Playlist, len(*in)) |
||||
for i := range *in { |
||||
(*in)[i].DeepCopyInto(&(*out)[i]) |
||||
} |
||||
} |
||||
return |
||||
} |
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PlaylistList.
|
||||
func (in *PlaylistList) DeepCopy() *PlaylistList { |
||||
if in == nil { |
||||
return nil |
||||
} |
||||
out := new(PlaylistList) |
||||
in.DeepCopyInto(out) |
||||
return out |
||||
} |
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *PlaylistList) 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 *Spec) DeepCopyInto(out *Spec) { |
||||
*out = *in |
||||
if in.Items != nil { |
||||
in, out := &in.Items, &out.Items |
||||
*out = make([]Item, len(*in)) |
||||
copy(*out, *in) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Spec.
|
||||
func (in *Spec) DeepCopy() *Spec { |
||||
if in == nil { |
||||
return nil |
||||
} |
||||
out := new(Spec) |
||||
in.DeepCopyInto(out) |
||||
return out |
||||
} |
@ -1,17 +0,0 @@ |
||||
package apis |
||||
|
||||
import ( |
||||
"github.com/google/wire" |
||||
|
||||
examplev0alpha1 "github.com/grafana/grafana/pkg/apis/example/v0alpha1" |
||||
"github.com/grafana/grafana/pkg/apis/playlist" |
||||
playlistsv0alpha1 "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1" |
||||
) |
||||
|
||||
// WireSet is the list of all services
|
||||
// NOTE: you must also register the service in: pkg/registry/apis/apis.go
|
||||
var WireSet = wire.NewSet( |
||||
playlist.RegisterAPIService, |
||||
playlistsv0alpha1.RegisterAPIService, |
||||
examplev0alpha1.RegisterAPIService, |
||||
) |
Loading…
Reference in new issue