From 6c2dc43bdac4d530177469cba26f6bf94c5d1f45 Mon Sep 17 00:00:00 2001 From: deads2k Date: Wed, 2 Aug 2017 08:42:33 -0400 Subject: [PATCH] use specified discovery information if possible Kubernetes-commit: dc55e3f76b392fadddd34f88c4a72f73e9f30cf6 --- discovery/restmapper.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/discovery/restmapper.go b/discovery/restmapper.go index 9651716bd..6d1de8c1b 100644 --- a/discovery/restmapper.go +++ b/discovery/restmapper.go @@ -96,8 +96,19 @@ func NewRESTMapper(groupResources []*APIGroupResources, versionInterfaces meta.V if !resource.Namespaced { scope = meta.RESTScopeRoot } - versionMapper.Add(gv.WithKind(resource.Kind), scope) - // TODO only do this if it supports listing + + // this is for legacy resources and servers which don't list singular forms. For those we must still guess. + if len(resource.SingularName) == 0 { + versionMapper.Add(gv.WithKind(resource.Kind), scope) + // TODO this is producing unsafe guesses that don't actually work, but it matches previous behavior + versionMapper.Add(gv.WithKind(resource.Kind+"List"), scope) + continue + } + + plural := gv.WithResource(resource.Name) + singular := gv.WithResource(resource.SingularName) + versionMapper.AddSpecific(gv.WithKind(resource.Kind), plural, singular, scope) + // TODO this is producing unsafe guesses that don't actually work, but it matches previous behavior versionMapper.Add(gv.WithKind(resource.Kind+"List"), scope) } // TODO why is this type not in discovery (at least for "v1")