Skip to content

Commit

Permalink
Merge pull request #67393 from nikhita/automated-cherry-pick-of-#6624…
Browse files Browse the repository at this point in the history
…9-upstream-release-1.10

Automatic merge from submit-queue.

Automated cherry pick of #66249: fill in normal restmapping info with the legacy guess

Fixes 1.10 part of #67235

Cherry pick of #66249 on release-1.10.

#66249: fill in normal restmapping info with the legacy guess

```release-note
Fix creation of custom resources when the CRD contains non-conventional pluralization and subresources
```
  • Loading branch information
Kubernetes Submit Queue committed Aug 17, 2018
2 parents ff529ab + 5a757b0 commit b16193f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions staging/src/k8s.io/client-go/discovery/restmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,20 @@ func NewRESTMapper(groupResources []*APIGroupResources, versionInterfaces meta.V
scope = meta.RESTScopeRoot
}

// 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)
// if we have a slash, then this is a subresource and we shouldn't create mappings for those.
if strings.Contains(resource.Name, "/") {
continue
}

plural := gv.WithResource(resource.Name)
singular := gv.WithResource(resource.SingularName)
versionMapper.AddSpecific(gv.WithKind(resource.Kind), plural, singular, scope)
// this is for legacy resources and servers which don't list singular forms. For those we must still guess.
if len(resource.SingularName) == 0 {
_, singular = meta.UnsafeGuessKindToResource(gv.WithKind(resource.Kind))
}

versionMapper.AddSpecific(gv.WithKind(strings.ToLower(resource.Kind)), plural, singular, scope)
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)
}
Expand Down

0 comments on commit b16193f

Please sign in to comment.