diff --git a/staging/src/k8s.io/cli-runtime/pkg/resource/builder.go b/staging/src/k8s.io/cli-runtime/pkg/resource/builder.go index 47ec83bbbad..36a9b3f2f26 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/resource/builder.go +++ b/staging/src/k8s.io/cli-runtime/pkg/resource/builder.go @@ -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 } diff --git a/staging/src/k8s.io/cli-runtime/pkg/resource/builder_test.go b/staging/src/k8s.io/cli-runtime/pkg/resource/builder_test.go index 3ec23461ece..6f5232cd3ae 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/resource/builder_test.go +++ b/staging/src/k8s.io/cli-runtime/pkg/resource/builder_test.go @@ -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) } } diff --git a/staging/src/k8s.io/cli-runtime/pkg/resource/mapper.go b/staging/src/k8s.io/cli-runtime/pkg/resource/mapper.go index 5180610e206..03b66684205 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/resource/mapper.go +++ b/staging/src/k8s.io/cli-runtime/pkg/resource/mapper.go @@ -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)