Skip to content

Commit

Permalink
Merge pull request #52545 from liggitt/automated-cherry-pick-of-#5001…
Browse files Browse the repository at this point in the history
…2-upstream-release-1.7

Automatic merge from submit-queue.

Automated cherry pick of #50012

Cherry pick of #50012 on release-1.7.

#50012: use specified discovery information if possible

```release-note
custom resources that use unconventional pluralization now work properly with kubectl
```
  • Loading branch information
Kubernetes Submit Queue committed Oct 2, 2017
2 parents 10fbd6b + dc55e3f commit dd388c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions staging/src/k8s.io/apimachinery/pkg/api/meta/restmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ func NewDefaultRESTMapper(defaultGroupVersions []schema.GroupVersion, f VersionI

func (m *DefaultRESTMapper) Add(kind schema.GroupVersionKind, scope RESTScope) {
plural, singular := UnsafeGuessKindToResource(kind)
m.AddSpecific(kind, plural, singular, scope)
}

func (m *DefaultRESTMapper) AddSpecific(kind schema.GroupVersionKind, plural, singular schema.GroupVersionResource, scope RESTScope) {
m.singularToPlural[singular] = plural
m.pluralToSingular[plural] = singular

Expand Down
15 changes: 13 additions & 2 deletions staging/src/k8s.io/client-go/discovery/restmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit dd388c7

Please sign in to comment.