k8s/io/kubernetes/pkg/api/unversioned.GroupVersionResource 示例代码

2022-03-03

以下示例是关于golang中包含unversioned.GroupVersionResource用法的示例代码,想了解unversioned.GroupVersionResource的具体用法?unversioned.GroupVersionResource怎么用?unversioned.GroupVersionResource使用的例子?那么可以参考以下10个相关示例代码来学习它的具体使用方法。

示例1:
multirestmapper_test.go开发语言: Go项目名称: amygdala代码行数: 298
31		mapper MultiRESTMapper
32		input  unversioned.GroupVersionResource
33		result unversioned.GroupVersionResource
39			input:  unversioned.GroupVersionResource{Resource: "foo"},
40			result: unversioned.GroupVersionResource{},
41			err:    &NoResourceMatchError{PartialResource: unversioned.GroupVersionResource{Resource: "foo"}},
44			name:   "ignore not found",
45			mapper: MultiRESTMapper{fixedRESTMapper{err: &NoResourceMatchError{PartialResource: unversioned.GroupVersionResource{Resource: "IGNORE_THIS"}}}},
46			input:  unversioned.GroupVersionResource{Resource: "foo"},
271
272func (m fixedRESTMapper) ResourcesFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error) {
273	return m.resourcesFor, m.err
279
280func (m fixedRESTMapper) ResourceFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error) {
281	return m.resourceFor, m.err
示例2:
restmapper_test.go开发语言: Go项目名称: amygdala代码行数: 550
61	testCases := []struct {
62		Resource               unversioned.GroupVersionResource
63		GroupVersionToRegister unversioned.GroupVersion
66	}{
67		{Resource: unversioned.GroupVersionResource{Resource: "internalobjec"}, Err: true},
68		{Resource: unversioned.GroupVersionResource{Resource: "internalObjec"}, Err: true},
69
70		{Resource: unversioned.GroupVersionResource{Resource: "internalobject"}, ExpectedGVK: testGroupVersion.WithKind("InternalObject")},
71		{Resource: unversioned.GroupVersionResource{Resource: "internalobjects"}, ExpectedGVK: testGroupVersion.WithKind("InternalObject")},
96	testCases := []struct {
97		Resource         unversioned.GroupVersionResource
98		GroupVersionKind unversioned.GroupVersionKind
100	}{
101		{Resource: unversioned.GroupVersionResource{Resource: "myObject"}, GroupVersionKind: unversioned.GroupVersionKind{Group: "testapi", Version: "test", Kind: "MyObject"}},
102		{Resource: unversioned.GroupVersionResource{Resource: "myobject"}, GroupVersionKind: unversioned.GroupVersionKind{Group: "testapi2", Version: "test", Kind: "MyObject"}},
示例3:
restmapper.go开发语言: Go项目名称: amygdala代码行数: 508
78	kindToScope          map[unversioned.GroupVersionKind]RESTScope
79	singularToPlural     map[unversioned.GroupVersionResource]unversioned.GroupVersionResource
80	pluralToSingular     map[unversioned.GroupVersionResource]unversioned.GroupVersionResource
140// KindToResource converts Kind to a resource name.
141func KindToResource(kind unversioned.GroupVersionKind) ( /*plural*/ unversioned.GroupVersionResource /*singular*/, unversioned.GroupVersionResource) {
142	kindName := kind.Kind
143	if len(kindName) == 0 {
144		return unversioned.GroupVersionResource{}, unversioned.GroupVersionResource{}
145	}
196
197func (m *DefaultRESTMapper) ResourcesFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error) {
198	hasResource := len(resource.Resource) > 0
260
261func (m *DefaultRESTMapper) ResourceFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error) {
262	resources, err := m.ResourcesFor(resource)
示例4:
priority_test.go开发语言: Go项目名称: amygdala代码行数: 206
30		delegate         RESTMapper
31		resourcePatterns []unversioned.GroupVersionResource
32		result           unversioned.GroupVersionResource
36			name:     "single hit",
37			delegate: fixedRESTMapper{resourcesFor: []unversioned.GroupVersionResource{{Resource: "single-hit"}}},
38			result:   unversioned.GroupVersionResource{Resource: "single-hit"},
41			name: "ambiguous match",
42			delegate: fixedRESTMapper{resourcesFor: []unversioned.GroupVersionResource{
43				{Group: "one", Version: "a", Resource: "first"},
49			name: "group selection",
50			delegate: fixedRESTMapper{resourcesFor: []unversioned.GroupVersionResource{
51				{Group: "one", Version: "a", Resource: "first"},
53			}},
54			resourcePatterns: []unversioned.GroupVersionResource{
55				{Group: "one", Version: AnyVersion, Resource: AnyResource},
示例5:
priority.go开发语言: Go项目名称: amygdala代码行数: 173
41	// matches as the list to continue matching against.
42	ResourcePriority []unversioned.GroupVersionResource
43
55// ResourceFor finds all resources, then passes them through the ResourcePriority patterns to find a single matching hit.
56func (m PriorityRESTMapper) ResourceFor(partiallySpecifiedResource unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error) {
57	originalGVRs, err := m.Delegate.ResourcesFor(partiallySpecifiedResource)
64
65	remainingGVRs := append([]unversioned.GroupVersionResource{}, originalGVRs...)
66	for _, pattern := range m.ResourcePriority {
126
127func resourceMatches(pattern unversioned.GroupVersionResource, resource unversioned.GroupVersionResource) bool {
128	if pattern.Group != AnyGroup && pattern.Group != resource.Group {
166
167func (m PriorityRESTMapper) ResourcesFor(partiallySpecifiedResource unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error) {
168	return m.Delegate.ResourcesFor(partiallySpecifiedResource)
示例6:
namespace_controller_utils.go开发语言: Go项目名称: amygdala代码行数: 480
56	op  operation
57	gvr unversioned.GroupVersionResource
58}
145	opCache operationNotSupportedCache,
146	gvr unversioned.GroupVersionResource,
147	namespace string,
187	opCache operationNotSupportedCache,
188	gvr unversioned.GroupVersionResource,
189	namespace string,
223	opCache operationNotSupportedCache,
224	gvr unversioned.GroupVersionResource,
225	namespace string,
251	opCache operationNotSupportedCache,
252	gvr unversioned.GroupVersionResource,
253	namespace string,
示例7:
codec.go开发语言: Go项目名称: amygdala代码行数: 384
45
46func (t *thirdPartyResourceDataMapper) getResource() unversioned.GroupVersionResource {
47	plural, _ := meta.KindToResource(t.getKind())
55
56func (t *thirdPartyResourceDataMapper) isThirdPartyResource(partialResource unversioned.GroupVersionResource) bool {
57	actualResource := t.getResource()
70
71func (t *thirdPartyResourceDataMapper) ResourcesFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error) {
72	if t.isThirdPartyResource(resource) {
73		return []unversioned.GroupVersionResource{t.getResource()}, nil
74	}
84
85func (t *thirdPartyResourceDataMapper) ResourceFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error) {
86	if t.isThirdPartyResource(resource) {
示例8:
kubectl.go开发语言: Go项目名称: amygdala代码行数: 178
87
88func (e ShortcutExpander) KindsFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionKind, error) {
89	return e.RESTMapper.KindsFor(expandResourceShortcut(resource))
91
92func (e ShortcutExpander) ResourcesFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error) {
93	return e.RESTMapper.ResourcesFor(expandResourceShortcut(resource))
95
96func (e ShortcutExpander) ResourceFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error) {
97	return e.RESTMapper.ResourceFor(expandResourceShortcut(resource))
100func (e ShortcutExpander) ResourceSingularizer(resource string) (string, error) {
101	return e.RESTMapper.ResourceSingularizer(expandResourceShortcut(unversioned.GroupVersionResource{Resource: resource}).Resource)
102}
138// indeed a shortcut. Otherwise, will return resource unmodified.
139func expandResourceShortcut(resource unversioned.GroupVersionResource) unversioned.GroupVersionResource {
140	if expanded, ok := shortForms[resource.Resource]; ok {
示例9:
multirestmapper.go开发语言: Go项目名称: amygdala代码行数: 194
52
53func (m MultiRESTMapper) ResourcesFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error) {
54	allGVRs := []unversioned.GroupVersionResource{}
87
88func (m MultiRESTMapper) KindsFor(resource unversioned.GroupVersionResource) (gvk []unversioned.GroupVersionKind, err error) {
89	allGVKs := []unversioned.GroupVersionKind{}
122
123func (m MultiRESTMapper) ResourceFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error) {
124	resources, err := m.ResourcesFor(resource)
125	if err != nil {
126		return unversioned.GroupVersionResource{}, err
127	}
131
132	return unversioned.GroupVersionResource{}, &AmbiguousResourceError{PartialResource: resource, MatchingResources: resources}
133}
示例10:
namespace_controller_test.go开发语言: Go项目名称: amygdala代码行数: 282
275// testGroupVersionResources returns a mocked up set of resources across different api groups for testing namespace controller.
276func testGroupVersionResources() []unversioned.GroupVersionResource {
277	results := []unversioned.GroupVersionResource{}
278	results = append(results, unversioned.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"})
279	results = append(results, unversioned.GroupVersionResource{Group: "", Version: "v1", Resource: "services"})
280	results = append(results, unversioned.GroupVersionResource{Group: "extensions", Version: "v1beta1", Resource: "deployments"})
281	return results

本文地址:https://www.itbaoku.cn/snippets/415811.html