Merge pull request #107363 from eddiezane/ez/kubectl-1118-crd-error

Improve error message for missing CRDs
This commit is contained in:
Kubernetes Prow Robot 2022-03-02 19:46:47 -08:00 committed by GitHub
commit 306d7724dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ import (
"fmt"
"reflect"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
@ -64,6 +65,10 @@ 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",
name, namespace, source, err)
}
return nil, fmt.Errorf("unable to recognize %q: %v", source, err)
}
ret.Mapping = mapping