Merge pull request #50012 from deads2k/cli-17-discovery

Automatic merge from submit-queue

use specified discovery information if possible

Fixes https://github.com/kubernetes/kubernetes/issues/49948

This uses the available discovery information if available, but it seems we never updated "normal" resources to show the singular name, so its often not available.  I've left this code compatible.

@enisoc @ash2k
@kubernetes/sig-api-machinery-misc

```release-note
custom resources that use unconventional pluralization now work properly with kubectl and garbage collection
```

Kubernetes-commit: e190f391129260527c119fe319216212c916ae5d
This commit is contained in:
Kubernetes Publisher 2017-09-14 22:14:21 -07:00
commit 0fd8a31bad
2 changed files with 62 additions and 51 deletions

98
Godeps/Godeps.json generated
View File

@ -472,199 +472,199 @@
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/errors",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery/registered",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1alpha1",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion/unstructured",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/fields",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/labels",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/cache",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/clock",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/json",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/net",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/sets",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/validation",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/version",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
"Rev": "1168e538ea3ccf444854d1fdd5681d2d876680a7"
"Rev": "7a5075a882d5309838390efd479693d06746c831"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/common",

View File

@ -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")