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
bc381fb5
Unverified
Commit
bc381fb5
authored
Jan 31, 2019
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return original error, unless error is *meta.NoKindMatchError
parent
d388b3ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
5 deletions
+72
-5
builder.go
....io/cli-runtime/pkg/genericclioptions/resource/builder.go
+5
-5
builder_test.go
...li-runtime/pkg/genericclioptions/resource/builder_test.go
+67
-0
No files found.
staging/src/k8s.io/cli-runtime/pkg/genericclioptions/resource/builder.go
View file @
bc381fb5
...
@@ -708,12 +708,12 @@ func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error
...
@@ -708,12 +708,12 @@ func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error
// if we error out here, it is because we could not match a resource or a kind
// 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,
// for the given argument. To maintain consistency with previous behavior,
// announce that a resource type could not be found.
// announce that a resource type could not be found.
// if the error is
a URL error, then we had trouble doing discovery, so we should return the original
// if the error is
_not_ a *meta.NoKindMatchError, then we had trouble doing discovery,
// error since it may help a user diagnose what is actually wrong
//
so we should return the original
error since it may help a user diagnose what is actually wrong
if
_
,
ok
:=
err
.
(
*
url
.
Error
);
ok
{
if
meta
.
IsNoMatchError
(
err
)
{
return
nil
,
err
return
nil
,
fmt
.
Errorf
(
"the server doesn't have a resource type %q"
,
groupResource
.
Resource
)
}
}
return
nil
,
fmt
.
Errorf
(
"the server doesn't have a resource type %q"
,
groupResource
.
Resource
)
return
nil
,
err
}
}
return
mapping
,
nil
return
mapping
,
nil
...
...
staging/src/k8s.io/cli-runtime/pkg/genericclioptions/resource/builder_test.go
View file @
bc381fb5
...
@@ -282,6 +282,30 @@ func newDefaultBuilderWith(fakeClientFn FakeClientFunc) *Builder {
...
@@ -282,6 +282,30 @@ func newDefaultBuilderWith(fakeClientFn FakeClientFunc) *Builder {
WithScheme
(
scheme
.
Scheme
,
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
WithScheme
(
scheme
.
Scheme
,
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
}
}
type
errorRestMapper
struct
{
meta
.
RESTMapper
err
error
}
func
(
l
*
errorRestMapper
)
RESTMapping
(
gk
schema
.
GroupKind
,
versions
...
string
)
(
*
meta
.
RESTMapping
,
error
)
{
return
nil
,
l
.
err
}
func
newDefaultBuilderWithMapperError
(
fakeClientFn
FakeClientFunc
,
err
error
)
*
Builder
{
return
NewFakeBuilder
(
fakeClientFn
,
func
()
(
meta
.
RESTMapper
,
error
)
{
return
&
errorRestMapper
{
RESTMapper
:
testrestmapper
.
TestOnlyStaticRESTMapper
(
scheme
.
Scheme
),
err
:
err
,
},
nil
},
func
()
(
restmapper
.
CategoryExpander
,
error
)
{
return
FakeCategoryExpander
,
nil
})
.
WithScheme
(
scheme
.
Scheme
,
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
}
func
TestPathBuilderAndVersionedObjectNotDefaulted
(
t
*
testing
.
T
)
{
func
TestPathBuilderAndVersionedObjectNotDefaulted
(
t
*
testing
.
T
)
{
b
:=
newDefaultBuilder
()
.
b
:=
newDefaultBuilder
()
.
FilenameParam
(
false
,
&
FilenameOptions
{
Recursive
:
false
,
Filenames
:
[]
string
{
"../../../artifacts/kitten-rc.yaml"
}})
FilenameParam
(
false
,
&
FilenameOptions
{
Recursive
:
false
,
Filenames
:
[]
string
{
"../../../artifacts/kitten-rc.yaml"
}})
...
@@ -634,6 +658,49 @@ func TestResourceByName(t *testing.T) {
...
@@ -634,6 +658,49 @@ func TestResourceByName(t *testing.T) {
}
}
}
}
func
TestRestMappingErrors
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
b
:=
newDefaultBuilderWith
(
fakeClientWith
(
""
,
t
,
map
[
string
]
string
{
"/namespaces/test/pods/foo"
:
runtime
.
EncodeOrDie
(
corev1Codec
,
&
pods
.
Items
[
0
]),
}))
.
NamespaceParam
(
"test"
)
if
b
.
Do
()
.
Err
()
==
nil
{
t
.
Errorf
(
"unexpected non-error"
)
}
test
:=
&
testVisitor
{}
singleItemImplied
:=
false
b
.
ResourceTypeOrNameArgs
(
true
,
"foo"
,
"bar"
)
// ensure that requesting a resource we _know_ not to exist results in an expected *meta.NoKindMatchError
err
:=
b
.
Do
()
.
IntoSingleItemImplied
(
&
singleItemImplied
)
.
Visit
(
test
.
Handle
)
if
err
!=
nil
{
if
!
strings
.
Contains
(
err
.
Error
(),
"server doesn't have a resource type
\"
foo
\"
"
)
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
expectedErr
:=
fmt
.
Errorf
(
"expected error"
)
b
=
newDefaultBuilderWithMapperError
(
fakeClientWith
(
""
,
t
,
map
[
string
]
string
{
"/namespaces/test/pods/foo"
:
runtime
.
EncodeOrDie
(
corev1Codec
,
&
pods
.
Items
[
0
]),
}),
expectedErr
)
.
NamespaceParam
(
"test"
)
if
b
.
Do
()
.
Err
()
==
nil
{
t
.
Errorf
(
"unexpected non-error"
)
}
// ensure we request a resource we know not to exist. This way, we
// end up taking the codepath we want to test in the resource builder
b
.
ResourceTypeOrNameArgs
(
true
,
"foo"
,
"bar"
)
// ensure that receiving an error for any reason other than a non-existent resource is returned as-is
err
=
b
.
Do
()
.
IntoSingleItemImplied
(
&
singleItemImplied
)
.
Visit
(
test
.
Handle
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
expectedErr
.
Error
())
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
func
TestMultipleResourceByTheSameName
(
t
*
testing
.
T
)
{
func
TestMultipleResourceByTheSameName
(
t
*
testing
.
T
)
{
pods
,
svcs
:=
testData
()
pods
,
svcs
:=
testData
()
b
:=
newDefaultBuilderWith
(
fakeClientWith
(
""
,
t
,
map
[
string
]
string
{
b
:=
newDefaultBuilderWith
(
fakeClientWith
(
""
,
t
,
map
[
string
]
string
{
...
...
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