Commit bbb94e42 authored by Chao Xu's avatar Chao Xu

remove registry from testing/fixture.go; update client-gen to not use

registry in the generated clients
parent ca520e34
...@@ -123,12 +123,11 @@ func PackageForClientset(customArgs clientgenargs.Args, fakeClientsetPackage str ...@@ -123,12 +123,11 @@ func PackageForClientset(customArgs clientgenargs.Args, fakeClientsetPackage str
DefaultGen: generator.DefaultGen{ DefaultGen: generator.DefaultGen{
OptionalName: "register", OptionalName: "register",
}, },
InputPackages: customArgs.GroupVersionToInputPath, InputPackages: customArgs.GroupVersionToInputPath,
OutputPackage: fakeClientsetPackage, OutputPackage: fakeClientsetPackage,
Groups: customArgs.Groups, Groups: customArgs.Groups,
ImportTracker: generator.NewImportTracker(), ImportTracker: generator.NewImportTracker(),
PrivateScheme: true, PrivateScheme: true,
CreateRegistry: true, // needed to know about root resources and for RESTMapper
}, },
} }
return generators return generators
......
...@@ -108,7 +108,7 @@ var common = ` ...@@ -108,7 +108,7 @@ var common = `
// without applying any validations and/or defaults. It shouldn't be considered a replacement // without applying any validations and/or defaults. It shouldn't be considered a replacement
// for a real clientset and is mostly useful in simple unit tests. // for a real clientset and is mostly useful in simple unit tests.
func NewSimpleClientset(objects ...runtime.Object) *Clientset { func NewSimpleClientset(objects ...runtime.Object) *Clientset {
o := testing.NewObjectTracker(registry, scheme, codecs.UniversalDecoder()) o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
for _, obj := range objects { for _, obj := range objects {
if err := o.Add(obj); err != nil { if err := o.Add(obj); err != nil {
panic(err) panic(err)
...@@ -116,7 +116,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { ...@@ -116,7 +116,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
} }
fakePtr := testing.Fake{} fakePtr := testing.Fake{}
fakePtr.AddReactor("*", "*", testing.ObjectReaction(o, registry.RESTMapper())) fakePtr.AddReactor("*", "*", testing.ObjectReaction(o))
fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil))
......
...@@ -120,6 +120,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io. ...@@ -120,6 +120,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
"GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}), "GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}),
"Everything": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/labels", Name: "Everything"}), "Everything": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/labels", Name: "Everything"}),
"GroupVersionResource": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionResource"}), "GroupVersionResource": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionResource"}),
"GroupVersionKind": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionKind"}),
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}), "PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}),
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}), "watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}),
...@@ -156,6 +157,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io. ...@@ -156,6 +157,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
if !noMethods { if !noMethods {
sw.Do(resource, m) sw.Do(resource, m)
sw.Do(kind, m)
sw.Do(createTemplate, m) sw.Do(createTemplate, m)
sw.Do(updateTemplate, m) sw.Do(updateTemplate, m)
// Generate the UpdateStatus method if the type has a status // Generate the UpdateStatus method if the type has a status
...@@ -198,11 +200,15 @@ var resource = ` ...@@ -198,11 +200,15 @@ var resource = `
var $.type|allLowercasePlural$Resource = $.GroupVersionResource|raw${Group: "$.groupName$", Version: "$.version$", Resource: "$.type|allLowercasePlural$"} var $.type|allLowercasePlural$Resource = $.GroupVersionResource|raw${Group: "$.groupName$", Version: "$.version$", Resource: "$.type|allLowercasePlural$"}
` `
var kind = `
var $.type|allLowercasePlural$Kind = $.GroupVersionKind|raw${Group: "$.groupName$", Version: "$.version$", Kind: "$.type|public$"}
`
var listTemplate = ` var listTemplate = `
func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type|raw$List, err error) { func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type|raw$List, err error) {
obj, err := c.Fake. obj, err := c.Fake.
$if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, c.ns, opts), &$.type|raw$List{}) $if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), &$.type|raw$List{})
$else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, opts), &$.type|raw$List{})$end$ $else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), &$.type|raw$List{})$end$
if obj == nil { if obj == nil {
return nil, err return nil, err
} }
...@@ -213,8 +219,8 @@ func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type ...@@ -213,8 +219,8 @@ func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type
var listUsingOptionsTemplate = ` var listUsingOptionsTemplate = `
func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type|raw$List, err error) { func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type|raw$List, err error) {
obj, err := c.Fake. obj, err := c.Fake.
$if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, c.ns, opts), &$.type|raw$List{}) $if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), &$.type|raw$List{})
$else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, opts), &$.type|raw$List{})$end$ $else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), &$.type|raw$List{})$end$
if obj == nil { if obj == nil {
return nil, err return nil, err
} }
......
...@@ -67,9 +67,9 @@ func (c *FakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1. ...@@ -67,9 +67,9 @@ func (c *FakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1.
// Search returns a list of events matching the specified object. // Search returns a list of events matching the specified object.
func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*v1.EventList, error) { func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*v1.EventList, error) {
action := core.NewRootListAction(eventsResource, metav1.ListOptions{}) action := core.NewRootListAction(eventsResource, eventsKind, metav1.ListOptions{})
if c.ns != "" { if c.ns != "" {
action = core.NewListAction(eventsResource, c.ns, metav1.ListOptions{}) action = core.NewListAction(eventsResource, eventsKind, c.ns, metav1.ListOptions{})
} }
obj, err := c.Fake.Invokes(action, &v1.EventList{}) obj, err := c.Fake.Invokes(action, &v1.EventList{})
if obj == nil { if obj == nil {
......
...@@ -67,9 +67,9 @@ func (c *FakeEvents) PatchWithEventNamespace(event *api.Event, data []byte) (*ap ...@@ -67,9 +67,9 @@ func (c *FakeEvents) PatchWithEventNamespace(event *api.Event, data []byte) (*ap
// Search returns a list of events matching the specified object. // Search returns a list of events matching the specified object.
func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*api.EventList, error) { func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*api.EventList, error) {
action := core.NewRootListAction(eventsResource, metav1.ListOptions{}) action := core.NewRootListAction(eventsResource, eventsKind, metav1.ListOptions{})
if c.ns != "" { if c.ns != "" {
action = core.NewListAction(eventsResource, c.ns, metav1.ListOptions{}) action = core.NewListAction(eventsResource, eventsKind, c.ns, metav1.ListOptions{})
} }
obj, err := c.Fake.Invokes(action, &api.EventList{}) obj, err := c.Fake.Invokes(action, &api.EventList{})
if obj == nil { if obj == nil {
......
...@@ -19,6 +19,7 @@ package util ...@@ -19,6 +19,7 @@ package util
import ( import (
"reflect" "reflect"
"testing" "testing"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
...@@ -31,7 +32,6 @@ import ( ...@@ -31,7 +32,6 @@ import (
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"time"
) )
type fakeClientAccessFactory struct { type fakeClientAccessFactory struct {
...@@ -52,6 +52,7 @@ func newFakeClientAccessFactory(objs []runtime.Object) *fakeClientAccessFactory ...@@ -52,6 +52,7 @@ func newFakeClientAccessFactory(objs []runtime.Object) *fakeClientAccessFactory
var ( var (
podsResource = schema.GroupVersionResource{Resource: "pods"} podsResource = schema.GroupVersionResource{Resource: "pods"}
podsKind = schema.GroupVersionKind{Kind: "Pod"}
) )
func TestLogsForObject(t *testing.T) { func TestLogsForObject(t *testing.T) {
...@@ -82,7 +83,7 @@ func TestLogsForObject(t *testing.T) { ...@@ -82,7 +83,7 @@ func TestLogsForObject(t *testing.T) {
}, },
pods: []runtime.Object{testPod()}, pods: []runtime.Object{testPod()},
actions: []testclient.Action{ actions: []testclient.Action{
testclient.NewListAction(podsResource, "test", metav1.ListOptions{LabelSelector: "foo=bar"}), testclient.NewListAction(podsResource, podsKind, "test", metav1.ListOptions{LabelSelector: "foo=bar"}),
getLogsAction("test", nil), getLogsAction("test", nil),
}, },
}, },
...@@ -96,7 +97,7 @@ func TestLogsForObject(t *testing.T) { ...@@ -96,7 +97,7 @@ func TestLogsForObject(t *testing.T) {
}, },
pods: []runtime.Object{testPod()}, pods: []runtime.Object{testPod()},
actions: []testclient.Action{ actions: []testclient.Action{
testclient.NewListAction(podsResource, "test", metav1.ListOptions{LabelSelector: "foo=bar"}), testclient.NewListAction(podsResource, podsKind, "test", metav1.ListOptions{LabelSelector: "foo=bar"}),
getLogsAction("test", nil), getLogsAction("test", nil),
}, },
}, },
...@@ -110,7 +111,7 @@ func TestLogsForObject(t *testing.T) { ...@@ -110,7 +111,7 @@ func TestLogsForObject(t *testing.T) {
}, },
pods: []runtime.Object{testPod()}, pods: []runtime.Object{testPod()},
actions: []testclient.Action{ actions: []testclient.Action{
testclient.NewListAction(podsResource, "test", metav1.ListOptions{LabelSelector: "foo=bar"}), testclient.NewListAction(podsResource, podsKind, "test", metav1.ListOptions{LabelSelector: "foo=bar"}),
getLogsAction("test", nil), getLogsAction("test", nil),
}, },
}, },
...@@ -124,7 +125,7 @@ func TestLogsForObject(t *testing.T) { ...@@ -124,7 +125,7 @@ func TestLogsForObject(t *testing.T) {
}, },
pods: []runtime.Object{testPod()}, pods: []runtime.Object{testPod()},
actions: []testclient.Action{ actions: []testclient.Action{
testclient.NewListAction(podsResource, "test", metav1.ListOptions{LabelSelector: "foo=bar"}), testclient.NewListAction(podsResource, podsKind, "test", metav1.ListOptions{LabelSelector: "foo=bar"}),
getLogsAction("test", nil), getLogsAction("test", nil),
}, },
}, },
...@@ -138,7 +139,7 @@ func TestLogsForObject(t *testing.T) { ...@@ -138,7 +139,7 @@ func TestLogsForObject(t *testing.T) {
}, },
pods: []runtime.Object{testPod()}, pods: []runtime.Object{testPod()},
actions: []testclient.Action{ actions: []testclient.Action{
testclient.NewListAction(podsResource, "test", metav1.ListOptions{LabelSelector: "foo=bar"}), testclient.NewListAction(podsResource, podsKind, "test", metav1.ListOptions{LabelSelector: "foo=bar"}),
getLogsAction("test", nil), getLogsAction("test", nil),
}, },
}, },
......
...@@ -47,20 +47,22 @@ func NewGetAction(resource schema.GroupVersionResource, namespace, name string) ...@@ -47,20 +47,22 @@ func NewGetAction(resource schema.GroupVersionResource, namespace, name string)
return action return action
} }
func NewRootListAction(resource schema.GroupVersionResource, opts interface{}) ListActionImpl { func NewRootListAction(resource schema.GroupVersionResource, kind schema.GroupVersionKind, opts interface{}) ListActionImpl {
action := ListActionImpl{} action := ListActionImpl{}
action.Verb = "list" action.Verb = "list"
action.Resource = resource action.Resource = resource
action.Kind = kind
labelSelector, fieldSelector, _ := ExtractFromListOptions(opts) labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector} action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
return action return action
} }
func NewListAction(resource schema.GroupVersionResource, namespace string, opts interface{}) ListActionImpl { func NewListAction(resource schema.GroupVersionResource, kind schema.GroupVersionKind, namespace string, opts interface{}) ListActionImpl {
action := ListActionImpl{} action := ListActionImpl{}
action.Verb = "list" action.Verb = "list"
action.Resource = resource action.Resource = resource
action.Kind = kind
action.Namespace = namespace action.Namespace = namespace
labelSelector, fieldSelector, _ := ExtractFromListOptions(opts) labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector} action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
...@@ -375,9 +377,14 @@ func (a GetActionImpl) GetName() string { ...@@ -375,9 +377,14 @@ func (a GetActionImpl) GetName() string {
type ListActionImpl struct { type ListActionImpl struct {
ActionImpl ActionImpl
Kind schema.GroupVersionKind
ListRestrictions ListRestrictions ListRestrictions ListRestrictions
} }
func (a ListActionImpl) GetKind() schema.GroupVersionKind {
return a.Kind
}
func (a ListActionImpl) GetListRestrictions() ListRestrictions { func (a ListActionImpl) GetListRestrictions() ListRestrictions {
return a.ListRestrictions return a.ListRestrictions
} }
......
...@@ -33,7 +33,7 @@ import ( ...@@ -33,7 +33,7 @@ import (
// without applying any validations and/or defaults. It shouldn't be considered a replacement // without applying any validations and/or defaults. It shouldn't be considered a replacement
// for a real clientset and is mostly useful in simple unit tests. // for a real clientset and is mostly useful in simple unit tests.
func NewSimpleClientset(objects ...runtime.Object) *Clientset { func NewSimpleClientset(objects ...runtime.Object) *Clientset {
o := testing.NewObjectTracker(api.Registry, api.Scheme, api.Codecs.UniversalDecoder()) o := testing.NewObjectTracker(api.Scheme, api.Codecs.UniversalDecoder())
for _, obj := range objects { for _, obj := range objects {
if err := o.Add(obj); err != nil { if err := o.Add(obj); err != nil {
panic(err) panic(err)
...@@ -41,7 +41,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { ...@@ -41,7 +41,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
} }
fakePtr := testing.Fake{} fakePtr := testing.Fake{}
fakePtr.AddReactor("*", "*", testing.ObjectReaction(o, api.Registry.RESTMapper())) fakePtr.AddReactor("*", "*", testing.ObjectReaction(o))
fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil))
......
...@@ -32,6 +32,8 @@ type FakeNodeMetricses struct { ...@@ -32,6 +32,8 @@ type FakeNodeMetricses struct {
var nodemetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1alpha1", Resource: "nodemetricses"} var nodemetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1alpha1", Resource: "nodemetricses"}
var nodemetricsesKind = schema.GroupVersionKind{Group: "metrics", Version: "v1alpha1", Kind: "NodeMetrics"}
func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.NodeMetrics, err error) { func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.NodeMetrics, err error) {
obj, err := c.Fake. obj, err := c.Fake.
Invokes(testing.NewRootGetAction(nodemetricsesResource, name), &v1alpha1.NodeMetrics{}) Invokes(testing.NewRootGetAction(nodemetricsesResource, name), &v1alpha1.NodeMetrics{})
...@@ -43,7 +45,7 @@ func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1a ...@@ -43,7 +45,7 @@ func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1a
func (c *FakeNodeMetricses) List(opts v1.ListOptions) (result *v1alpha1.NodeMetricsList, err error) { func (c *FakeNodeMetricses) List(opts v1.ListOptions) (result *v1alpha1.NodeMetricsList, err error) {
obj, err := c.Fake. obj, err := c.Fake.
Invokes(testing.NewRootListAction(nodemetricsesResource, opts), &v1alpha1.NodeMetricsList{}) Invokes(testing.NewRootListAction(nodemetricsesResource, nodemetricsesKind, opts), &v1alpha1.NodeMetricsList{})
if obj == nil { if obj == nil {
return nil, err return nil, err
} }
......
...@@ -33,6 +33,8 @@ type FakePodMetricses struct { ...@@ -33,6 +33,8 @@ type FakePodMetricses struct {
var podmetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1alpha1", Resource: "podmetricses"} var podmetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1alpha1", Resource: "podmetricses"}
var podmetricsesKind = schema.GroupVersionKind{Group: "metrics", Version: "v1alpha1", Kind: "PodMetrics"}
func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.PodMetrics, err error) { func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.PodMetrics, err error) {
obj, err := c.Fake. obj, err := c.Fake.
Invokes(testing.NewGetAction(podmetricsesResource, c.ns, name), &v1alpha1.PodMetrics{}) Invokes(testing.NewGetAction(podmetricsesResource, c.ns, name), &v1alpha1.PodMetrics{})
...@@ -45,7 +47,7 @@ func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1al ...@@ -45,7 +47,7 @@ func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1al
func (c *FakePodMetricses) List(opts v1.ListOptions) (result *v1alpha1.PodMetricsList, err error) { func (c *FakePodMetricses) List(opts v1.ListOptions) (result *v1alpha1.PodMetricsList, err error) {
obj, err := c.Fake. obj, err := c.Fake.
Invokes(testing.NewListAction(podmetricsesResource, c.ns, opts), &v1alpha1.PodMetricsList{}) Invokes(testing.NewListAction(podmetricsesResource, podmetricsesKind, c.ns, opts), &v1alpha1.PodMetricsList{})
if obj == nil { if obj == nil {
return nil, err return nil, err
......
...@@ -19,9 +19,9 @@ package fake ...@@ -19,9 +19,9 @@ package fake
import ( import (
"fmt" "fmt"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/testing" "k8s.io/client-go/testing"
"k8s.io/metrics/pkg/apis/custom_metrics/v1alpha1" "k8s.io/metrics/pkg/apis/custom_metrics/v1alpha1"
cmclient "k8s.io/metrics/pkg/client/custom_metrics" cmclient "k8s.io/metrics/pkg/client/custom_metrics"
...@@ -52,13 +52,12 @@ func (i GetForActionImpl) GetSubresource() string { ...@@ -52,13 +52,12 @@ func (i GetForActionImpl) GetSubresource() string {
} }
func NewGetForAction(groupKind schema.GroupKind, namespace, name string, metricName string, labelSelector labels.Selector) GetForActionImpl { func NewGetForAction(groupKind schema.GroupKind, namespace, name string, metricName string, labelSelector labels.Selector) GetForActionImpl {
mapping, err := api.Registry.RESTMapper().RESTMapping(groupKind) // the version doesn't matter
if err != nil { gvk := groupKind.WithVersion("")
panic(fmt.Sprintf("unable to get REST mapping for groupKind %s while building GetFor action: %v", groupKind.String, err)) gvr, _ := meta.UnsafeGuessKindToResource(gvk)
}
groupResourceForKind := schema.GroupResource{ groupResourceForKind := schema.GroupResource{
Group: mapping.GroupVersionKind.Group, Group: gvr.Group,
Resource: mapping.Resource, Resource: gvr.Resource,
} }
resource := schema.GroupResource{ resource := schema.GroupResource{
Group: v1alpha1.SchemeGroupVersion.Group, Group: v1alpha1.SchemeGroupVersion.Group,
...@@ -72,13 +71,12 @@ func NewGetForAction(groupKind schema.GroupKind, namespace, name string, metricN ...@@ -72,13 +71,12 @@ func NewGetForAction(groupKind schema.GroupKind, namespace, name string, metricN
} }
func NewRootGetForAction(groupKind schema.GroupKind, name string, metricName string, labelSelector labels.Selector) GetForActionImpl { func NewRootGetForAction(groupKind schema.GroupKind, name string, metricName string, labelSelector labels.Selector) GetForActionImpl {
mapping, err := api.Registry.RESTMapper().RESTMapping(groupKind) // the version doesn't matter
if err != nil { gvk := groupKind.WithVersion("")
panic(fmt.Sprintf("unable to get REST mapping for groupKind %s while building GetFor action: %v", groupKind.String, err)) gvr, _ := meta.UnsafeGuessKindToResource(gvk)
}
groupResourceForKind := schema.GroupResource{ groupResourceForKind := schema.GroupResource{
Group: mapping.GroupVersionKind.Group, Group: gvr.Group,
Resource: mapping.Resource, Resource: gvr.Resource,
} }
resource := schema.GroupResource{ resource := schema.GroupResource{
Group: v1alpha1.SchemeGroupVersion.Group, Group: v1alpha1.SchemeGroupVersion.Group,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment