Chore: Use Kind().GroupVersionResource() (#113133)
This commit is contained in:
+1
-6
@@ -144,13 +144,8 @@ type playlistK8sHandler struct {
|
||||
//-----------------------------------------------------------------------------------------
|
||||
|
||||
func newPlaylistK8sHandler(hs *HTTPServer) *playlistK8sHandler {
|
||||
gvr := schema.GroupVersionResource{
|
||||
Group: v0alpha1.PlaylistKind().Group(),
|
||||
Version: v0alpha1.PlaylistKind().Version(),
|
||||
Resource: v0alpha1.PlaylistKind().Plural(),
|
||||
}
|
||||
return &playlistK8sHandler{
|
||||
gvr: gvr,
|
||||
gvr: v0alpha1.PlaylistKind().GroupVersionResource(),
|
||||
namespacer: request.GetNamespaceMapper(hs.Cfg),
|
||||
clientConfigProvider: hs.clientConfigProvider,
|
||||
}
|
||||
|
||||
@@ -119,13 +119,8 @@ type shortURLK8sHandler struct {
|
||||
}
|
||||
|
||||
func newShortURLK8sHandler(hs *HTTPServer) *shortURLK8sHandler {
|
||||
gvr := schema.GroupVersionResource{
|
||||
Group: v1alpha1.ShortURLKind().Group(),
|
||||
Version: v1alpha1.ShortURLKind().Version(),
|
||||
Resource: v1alpha1.ShortURLKind().Plural(),
|
||||
}
|
||||
return &shortURLK8sHandler{
|
||||
gvr: gvr,
|
||||
gvr: v1alpha1.ShortURLKind().GroupVersionResource(),
|
||||
namespacer: request.GetNamespaceMapper(hs.Cfg),
|
||||
clientConfigProvider: hs.clientConfigProvider,
|
||||
cfg: hs.Cfg,
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
|
||||
playlist "github.com/grafana/grafana/apps/playlist/pkg/apis/playlist/v0alpha1"
|
||||
@@ -87,10 +86,7 @@ func (s *legacyStorage) Get(ctx context.Context, name string, options *metav1.Ge
|
||||
})
|
||||
if err != nil || dto == nil {
|
||||
if errors.Is(err, playlistsvc.ErrPlaylistNotFound) || err == nil {
|
||||
err = k8serrors.NewNotFound(schema.GroupResource{
|
||||
Group: playlist.PlaylistKind().Group(),
|
||||
Resource: playlist.PlaylistKind().Plural(),
|
||||
}, name)
|
||||
err = k8serrors.NewNotFound(playlist.PlaylistKind().GroupVersionResource().GroupResource(), name)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -65,11 +65,7 @@ func RegisterAppInstaller(
|
||||
|
||||
// GetLegacyStorage returns the legacy storage for the playlist app.
|
||||
func (p *PlaylistAppInstaller) GetLegacyStorage(requested schema.GroupVersionResource) grafanarest.Storage {
|
||||
gvr := schema.GroupVersionResource{
|
||||
Group: playlistv0alpha1.PlaylistKind().Group(),
|
||||
Version: playlistv0alpha1.PlaylistKind().Version(),
|
||||
Resource: playlistv0alpha1.PlaylistKind().Plural(),
|
||||
}
|
||||
gvr := playlistv0alpha1.PlaylistKind().GroupVersionResource()
|
||||
if requested.String() != gvr.String() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -55,11 +55,7 @@ func (p *PluginsAppInstaller) InstallAPIs(
|
||||
server appsdkapiserver.GenericAPIServer,
|
||||
restOptsGetter generic.RESTOptionsGetter,
|
||||
) error {
|
||||
pluginMetaGVR := schema.GroupVersionResource{
|
||||
Group: pluginsv0alpha1.GroupVersion.Group,
|
||||
Version: pluginsv0alpha1.GroupVersion.Version,
|
||||
Resource: pluginsv0alpha1.PluginMetaKind().Plural(),
|
||||
}
|
||||
pluginMetaGVR := pluginsv0alpha1.PluginMetaKind().GroupVersionResource()
|
||||
replacedStorage := map[schema.GroupVersionResource]rest.Storage{
|
||||
pluginMetaGVR: pluginsapp.NewPluginMetaStorage(request.GetNamespaceMapper(p.cfg)),
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
|
||||
shorturl "github.com/grafana/grafana/apps/shorturl/pkg/apis/shorturl/v1alpha1"
|
||||
@@ -97,10 +96,7 @@ func (s *legacyStorage) Get(ctx context.Context, name string, options *metav1.Ge
|
||||
dto, err := s.service.GetShortURLByUID(ctx, signedInUser, name)
|
||||
if err != nil || dto == nil {
|
||||
if errors.Is(err, shorturls.ErrShortURLNotFound) || err == nil {
|
||||
err = k8serrors.NewNotFound(schema.GroupResource{
|
||||
Group: shorturl.ShortURLKind().Group(),
|
||||
Resource: shorturl.ShortURLKind().Plural(),
|
||||
}, name)
|
||||
err = k8serrors.NewNotFound(shorturl.ShortURLKind().GroupVersionResource().GroupResource(), name)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -167,10 +163,7 @@ func (s *legacyStorage) Update(ctx context.Context,
|
||||
shortURL, err := s.service.GetShortURLByUID(ctx, signedInUser, name)
|
||||
if err != nil || shortURL == nil {
|
||||
if errors.Is(err, shorturls.ErrShortURLNotFound) || err == nil {
|
||||
err = k8serrors.NewNotFound(schema.GroupResource{
|
||||
Group: shorturl.ShortURLKind().Group(),
|
||||
Resource: shorturl.ShortURLKind().Plural(),
|
||||
}, name)
|
||||
err = k8serrors.NewNotFound(shorturl.ShortURLKind().GroupVersionResource().GroupResource(), name)
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
@@ -55,11 +55,7 @@ func RegisterAppInstaller(
|
||||
}
|
||||
|
||||
func (s *ShortURLAppInstaller) GetLegacyStorage(requested schema.GroupVersionResource) grafanarest.Storage {
|
||||
gvr := schema.GroupVersionResource{
|
||||
Group: shorturl.ShortURLKind().Group(),
|
||||
Version: shorturl.ShortURLKind().Version(),
|
||||
Resource: shorturl.ShortURLKind().Plural(),
|
||||
}
|
||||
gvr := shorturl.ShortURLKind().GroupVersionResource()
|
||||
if requested.String() != gvr.String() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/app"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/admission"
|
||||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/app"
|
||||
examplev1 "github.com/grafana/grafana/pkg/services/apiserver/builder/runner/testdata/app/pkg/apis/example/v1"
|
||||
)
|
||||
|
||||
@@ -20,12 +19,8 @@ func TestBuilderAdmission_Validate(t *testing.T) {
|
||||
A: "test",
|
||||
},
|
||||
}
|
||||
gvk := schema.GroupVersionKind{
|
||||
Group: examplev1.ExampleKind().Group(),
|
||||
Version: examplev1.ExampleKind().Version(),
|
||||
Kind: examplev1.ExampleKind().Kind(),
|
||||
}
|
||||
gvr := gvk.GroupVersion().WithResource(examplev1.ExampleKind().Plural())
|
||||
gvk := examplev1.ExampleKind().GroupVersionKind()
|
||||
gvr := examplev1.ExampleKind().GroupVersionResource()
|
||||
defaultAttributes := admission.NewAttributesRecord(exampleObj, nil, gvk, "default", "foo", gvr, "", admission.Create, nil, false, &user.DefaultInfo{})
|
||||
|
||||
tests := []struct {
|
||||
@@ -73,12 +68,8 @@ func TestBuilderAdmission_Validate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuilderAdmission_Mutate(t *testing.T) {
|
||||
gvk := schema.GroupVersionKind{
|
||||
Group: examplev1.ExampleKind().Group(),
|
||||
Version: examplev1.ExampleKind().Version(),
|
||||
Kind: examplev1.ExampleKind().Kind(),
|
||||
}
|
||||
gvr := gvk.GroupVersion().WithResource(examplev1.ExampleKind().Plural())
|
||||
gvk := examplev1.ExampleKind().GroupVersionKind()
|
||||
gvr := examplev1.ExampleKind().GroupVersionResource()
|
||||
getAttributes := func() admission.Attributes {
|
||||
exampleObj := &examplev1.Example{
|
||||
Spec: examplev1.ExampleSpec{
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/dynamic"
|
||||
|
||||
"github.com/grafana/grafana/apps/shorturl/pkg/apis/shorturl/v1alpha1"
|
||||
@@ -326,11 +325,7 @@ func (srv *CleanUpService) deleteStaleKubernetesShortURLs(ctx context.Context) {
|
||||
}
|
||||
|
||||
// Set up the GroupVersionResource for shortURLs
|
||||
gvr := schema.GroupVersionResource{
|
||||
Group: v1alpha1.ShortURLKind().Group(),
|
||||
Version: v1alpha1.ShortURLKind().Version(),
|
||||
Resource: v1alpha1.ShortURLKind().Plural(),
|
||||
}
|
||||
gvr := v1alpha1.ShortURLKind().GroupVersionResource()
|
||||
|
||||
// Calculate the expiration time
|
||||
expirationTime := time.Now().Add(-time.Duration(srv.Cfg.ShortLinkExpiration*24) * time.Hour)
|
||||
|
||||
@@ -3,12 +3,11 @@ package common
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/dynamic"
|
||||
|
||||
"github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
)
|
||||
|
||||
func NewReceiverClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1.Receiver, v0alpha1.ReceiverList] {
|
||||
@@ -19,11 +18,8 @@ func NewReceiverClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1.
|
||||
|
||||
return &apis.TypedClient[v0alpha1.Receiver, v0alpha1.ReceiverList]{
|
||||
Client: client.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: v0alpha1.ReceiverKind().Group(),
|
||||
Version: v0alpha1.ReceiverKind().Version(),
|
||||
Resource: v0alpha1.ReceiverKind().Plural(),
|
||||
}).Namespace("default"),
|
||||
v0alpha1.ReceiverKind().GroupVersionResource()).
|
||||
Namespace("default"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +31,7 @@ func NewRoutingTreeClient(t *testing.T, user apis.User) *apis.TypedClient[v0alph
|
||||
|
||||
return &apis.TypedClient[v0alpha1.RoutingTree, v0alpha1.RoutingTreeList]{
|
||||
Client: client.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: v0alpha1.RoutingTreeKind().Group(),
|
||||
Version: v0alpha1.RoutingTreeKind().Version(),
|
||||
Resource: v0alpha1.RoutingTreeKind().Plural(),
|
||||
}).Namespace("default"),
|
||||
v0alpha1.RoutingTreeKind().GroupVersionResource()).Namespace("default"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +43,7 @@ func NewTemplateGroupClient(t *testing.T, user apis.User) *apis.TypedClient[v0al
|
||||
|
||||
return &apis.TypedClient[v0alpha1.TemplateGroup, v0alpha1.TemplateGroupList]{
|
||||
Client: client.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: v0alpha1.TemplateGroupKind().Group(),
|
||||
Version: v0alpha1.TemplateGroupKind().Version(),
|
||||
Resource: v0alpha1.TemplateGroupKind().Plural(),
|
||||
}).Namespace("default"),
|
||||
v0alpha1.TemplateGroupKind().GroupVersionResource()).Namespace("default"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,10 +55,6 @@ func NewTimeIntervalClient(t *testing.T, user apis.User) *apis.TypedClient[v0alp
|
||||
|
||||
return &apis.TypedClient[v0alpha1.TimeInterval, v0alpha1.TimeIntervalList]{
|
||||
Client: client.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: v0alpha1.TimeIntervalKind().Group(),
|
||||
Version: v0alpha1.TimeIntervalKind().Version(),
|
||||
Resource: v0alpha1.TimeIntervalKind().Plural(),
|
||||
}).Namespace("default"),
|
||||
v0alpha1.TimeIntervalKind().GroupVersionResource()).Namespace("default"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/dynamic"
|
||||
|
||||
"github.com/grafana/grafana/apps/alerting/rules/pkg/apis/alerting/v0alpha1"
|
||||
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
"github.com/stretchr/testify/require"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/dynamic"
|
||||
)
|
||||
|
||||
func NewAlertRuleClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1.AlertRule, v0alpha1.AlertRuleList] {
|
||||
@@ -22,11 +22,7 @@ func NewAlertRuleClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1
|
||||
|
||||
return &apis.TypedClient[v0alpha1.AlertRule, v0alpha1.AlertRuleList]{
|
||||
Client: client.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: v0alpha1.AlertRuleKind().Group(),
|
||||
Version: v0alpha1.AlertRuleKind().Version(),
|
||||
Resource: v0alpha1.AlertRuleKind().Plural(),
|
||||
}).Namespace("default"),
|
||||
v0alpha1.AlertRuleKind().GroupVersionResource()).Namespace("default"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +34,7 @@ func NewRecordingRuleClient(t *testing.T, user apis.User) *apis.TypedClient[v0al
|
||||
|
||||
return &apis.TypedClient[v0alpha1.RecordingRule, v0alpha1.RecordingRuleList]{
|
||||
Client: client.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: v0alpha1.RecordingRuleKind().Group(),
|
||||
Version: v0alpha1.RecordingRuleKind().Version(),
|
||||
Resource: v0alpha1.RecordingRuleKind().Plural(),
|
||||
}).Namespace("default"),
|
||||
v0alpha1.RecordingRuleKind().GroupVersionResource()).Namespace("default"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,11 +46,7 @@ func NewFolderClient(t *testing.T, user apis.User) *apis.TypedClient[folders.Fol
|
||||
|
||||
return &apis.TypedClient[folders.Folder, folders.FolderList]{
|
||||
Client: client.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: folders.FolderKind().Group(),
|
||||
Version: folders.FolderKind().Version(),
|
||||
Resource: folders.FolderKind().Plural(),
|
||||
}).Namespace("default"),
|
||||
folders.FolderKind().GroupVersionResource()).Namespace("default"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user