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

View File

@ -96,8 +96,19 @@ func NewRESTMapper(groupResources []*APIGroupResources, versionInterfaces meta.V
if !resource.Namespaced { if !resource.Namespaced {
scope = meta.RESTScopeRoot 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) versionMapper.Add(gv.WithKind(resource.Kind+"List"), scope)
} }
// TODO why is this type not in discovery (at least for "v1") // TODO why is this type not in discovery (at least for "v1")