-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug with pluralization of third party resources #25374
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import ( | |
"time" | ||
|
||
"k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/api/meta" | ||
"k8s.io/kubernetes/pkg/api/rest" | ||
"k8s.io/kubernetes/pkg/api/unversioned" | ||
apiv1 "k8s.io/kubernetes/pkg/api/v1" | ||
|
@@ -655,7 +656,13 @@ func (m *Master) InstallThirdPartyResource(rsrc *extensions.ThirdPartyResource) | |
if err != nil { | ||
return err | ||
} | ||
thirdparty := m.thirdpartyapi(group, kind, rsrc.Versions[0].Name) | ||
plural, _ := meta.KindToResource(unversioned.GroupVersionKind{ | ||
Group: group, | ||
Version: rsrc.Versions[0].Name, | ||
Kind: kind, | ||
}) | ||
|
||
thirdparty := m.thirdpartyapi(group, kind, rsrc.Versions[0].Name, plural.Resource) | ||
if err := thirdparty.InstallREST(m.HandlerContainer); err != nil { | ||
glog.Fatalf("Unable to setup thirdparty api: %v", err) | ||
} | ||
|
@@ -670,19 +677,20 @@ func (m *Master) InstallThirdPartyResource(rsrc *extensions.ThirdPartyResource) | |
PreferredVersion: groupVersion, | ||
} | ||
apiserver.AddGroupWebService(api.Codecs, m.HandlerContainer, path, apiGroup) | ||
m.addThirdPartyResourceStorage(path, thirdparty.Storage[strings.ToLower(kind)+"s"].(*thirdpartyresourcedataetcd.REST), apiGroup) | ||
|
||
m.addThirdPartyResourceStorage(path, thirdparty.Storage[plural.Resource].(*thirdpartyresourcedataetcd.REST), apiGroup) | ||
apiserver.InstallServiceErrorHandler(api.Codecs, m.HandlerContainer, m.NewRequestInfoResolver(), []string{thirdparty.GroupVersion.String()}) | ||
return nil | ||
} | ||
|
||
func (m *Master) thirdpartyapi(group, kind, version string) *apiserver.APIGroupVersion { | ||
func (m *Master) thirdpartyapi(group, kind, version, pluralResource string) *apiserver.APIGroupVersion { | ||
resourceStorage := thirdpartyresourcedataetcd.NewREST( | ||
generic.RESTOptions{Storage: m.thirdPartyStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: m.deleteCollectionWorkers}, group, kind) | ||
|
||
apiRoot := makeThirdPartyPath("") | ||
|
||
storage := map[string]rest.Storage{ | ||
strings.ToLower(kind) + "s": resourceStorage, | ||
pluralResource: resourceStorage, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we're relying on meta.KindToResource's pluralization code working for arbitrary strings? I guess that's an improvement to just appending an 's'. Should we instead allow them to put a pluralized version in the specification? @smarterclayton here's another great reason not to use plurals in our paths... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. KindToResource is what the kubectl client code uses afaik, so at least its consistent? |
||
} | ||
|
||
optionsExternalVersion := registered.GroupOrDie(api.GroupName).GroupVersion | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking: that second parameter is not an error, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second parameter is the 'singular' version of the resource.