Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
177dcb99
Unverified
Commit
177dcb99
authored
Mar 08, 2018
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
match KindFor first
parent
40143fd6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
18 deletions
+21
-18
builder.go
pkg/kubectl/resource/builder.go
+21
-18
No files found.
pkg/kubectl/resource/builder.go
View file @
177dcb99
...
...
@@ -599,9 +599,21 @@ func (b *Builder) SingleResourceType() *Builder {
}
// mappingFor returns the RESTMapping for the Kind given, or the Kind referenced by the resource.
//
prefers a fully specified GroupVersionKind match. If we don't have one, match on a fully specified
//
GroupVersionResource, or fallback to a match on GroupResource
.
//
Prefers a fully specified GroupVersionResource match. If one is not found, we match on a fully
//
specified GroupVersionKind, or fallback to a match on GroupKind
.
func
(
b
*
Builder
)
mappingFor
(
resourceOrKindArg
string
)
(
*
meta
.
RESTMapping
,
error
)
{
fullySpecifiedGVR
,
groupResource
:=
schema
.
ParseResourceArg
(
resourceOrKindArg
)
gvk
:=
schema
.
GroupVersionKind
{}
if
fullySpecifiedGVR
!=
nil
{
gvk
,
_
=
b
.
mapper
.
KindFor
(
*
fullySpecifiedGVR
)
}
if
gvk
.
Empty
()
{
gvk
,
_
=
b
.
mapper
.
KindFor
(
groupResource
.
WithVersion
(
""
))
}
if
!
gvk
.
Empty
()
{
return
b
.
mapper
.
RESTMapping
(
gvk
.
GroupKind
(),
gvk
.
Version
)
}
fullySpecifiedGVK
,
groupKind
:=
schema
.
ParseKindArg
(
resourceOrKindArg
)
if
fullySpecifiedGVK
==
nil
{
gvk
:=
groupKind
.
WithVersion
(
""
)
...
...
@@ -611,27 +623,18 @@ func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error
if
!
fullySpecifiedGVK
.
Empty
()
{
if
mapping
,
err
:=
b
.
mapper
.
RESTMapping
(
fullySpecifiedGVK
.
GroupKind
(),
fullySpecifiedGVK
.
Version
);
err
==
nil
{
return
mapping
,
nil
}
else
{
if
mapping
,
err
:=
b
.
mapper
.
RESTMapping
(
groupKind
,
""
);
err
==
nil
{
return
mapping
,
nil
}
}
}
fullySpecifiedGVR
,
groupResource
:=
schema
.
ParseResourceArg
(
resourceOrKindArg
)
gvk
:=
schema
.
GroupVersionKind
{}
if
fullySpecifiedGVR
!=
nil
{
gvk
,
_
=
b
.
mapper
.
KindFor
(
*
fullySpecifiedGVR
)
}
if
gvk
.
Empty
()
{
var
err
error
gvk
,
err
=
b
.
mapper
.
KindFor
(
groupResource
.
WithVersion
(
""
))
if
err
!=
nil
{
return
nil
,
err
}
mapping
,
err
:=
b
.
mapper
.
RESTMapping
(
groupKind
,
gvk
.
Version
)
if
err
!=
nil
{
// if we error out here, it is because we could not match a resource or a kind
// for the given argument. To maintain consistency with previous behavior,
// announce that a resource type could not be found.
return
nil
,
fmt
.
Errorf
(
"the server doesn't have a resource type %q"
,
groupResource
.
Resource
)
}
return
b
.
mapper
.
RESTMapping
(
gvk
.
GroupKind
(),
gvk
.
Version
)
return
mapping
,
nil
}
func
(
b
*
Builder
)
resourceMappings
()
([]
*
meta
.
RESTMapping
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment