mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-15 23:03:40 +00:00
feat(cli-runtime): wrap meta.NoKindMatchErrors
This commit is contained in:
parent
c015565db3
commit
10a6885da1
@ -803,7 +803,7 @@ func (b *Builder) mappingFor(resourceOrKindArg string) (*meta.RESTMapping, error
|
||||
// if the error is _not_ a *meta.NoKindMatchError, then we had trouble doing discovery,
|
||||
// so we should return the original error since it may help a user diagnose what is actually wrong
|
||||
if meta.IsNoMatchError(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: %w", groupResource.Resource, err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ import (
|
||||
"k8s.io/client-go/rest/fake"
|
||||
restclientwatch "k8s.io/client-go/rest/watch"
|
||||
"k8s.io/client-go/restmapper"
|
||||
|
||||
// TODO we need to remove this linkage and create our own scheme
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
@ -1050,7 +1051,7 @@ func TestRestMappingErrors(t *testing.T) {
|
||||
// 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\"") {
|
||||
if !errors.Is(err, &meta.NoKindMatchError{}) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (m *mapper) infoForData(data []byte, source string) (*Info, error) {
|
||||
mapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
|
||||
if err != nil {
|
||||
if _, ok := err.(*meta.NoKindMatchError); ok {
|
||||
return nil, fmt.Errorf("resource mapping not found for name: %q namespace: %q from %q: %v\nensure CRDs are installed first",
|
||||
return nil, fmt.Errorf("resource mapping not found for name: %q namespace: %q from %q: %w\nensure CRDs are installed first",
|
||||
name, namespace, source, err)
|
||||
}
|
||||
return nil, fmt.Errorf("unable to recognize %q: %v", source, err)
|
||||
|
Loading…
Reference in New Issue
Block a user