Skip to content
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

Make resources' names in lowercase in generated clients #19958

Merged
merged 3 commits into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions cmd/libs/go2idl/client-gen/generators/client-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ func NameSystems() namer.NameSystems {
pluralExceptions := map[string]string{
"Endpoints": "Endpoints",
"ComponentStatus": "ComponentStatus",
"Ingress": "Ingress",
}
return namer.NameSystems{
"public": namer.NewPublicNamer(0),
"private": namer.NewPrivateNamer(0),
"raw": namer.NewRawNamer("", nil),
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
"privatePlural": namer.NewPrivatePluralNamer(pluralExceptions),
"public": namer.NewPublicNamer(0),
"private": namer.NewPrivateNamer(0),
"raw": namer.NewRawNamer("", nil),
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
"privatePlural": namer.NewPrivatePluralNamer(pluralExceptions),
"allLowercasePlural": namer.NewAllLowercasePluralNamer(pluralExceptions),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ type Fake$.type|publicPlural$ struct {
var listTemplate = `
func (c *Fake$.type|publicPlural$) List(opts $.apiListOptions|raw$) (result *$.type|raw$List, err error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewListAction|raw$("$.type|privatePlural$", c.ns, opts), &$.type|raw$List{})
$else$Invokes($.NewRootListAction|raw$("$.type|privatePlural$", opts), &$.type|raw$List{})$end$
$if .namespaced$Invokes($.NewListAction|raw$("$.type|allLowercasePlural$", c.ns, opts), &$.type|raw$List{})
$else$Invokes($.NewRootListAction|raw$("$.type|allLowercasePlural$", opts), &$.type|raw$List{})$end$
if obj == nil {
return nil, err
}
Expand All @@ -169,8 +169,8 @@ func (c *Fake$.type|publicPlural$) List(opts $.apiListOptions|raw$) (result *$.t
var listUsingOptionsTemplate = `
func (c *Fake$.type|publicPlural$) List(opts $.apiListOptions|raw$) (result *$.type|raw$List, err error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewListAction|raw$("$.type|privatePlural$", c.ns, opts), &$.type|raw$List{})
$else$Invokes($.NewRootListAction|raw$("$.type|privatePlural$", opts), &$.type|raw$List{})$end$
$if .namespaced$Invokes($.NewListAction|raw$("$.type|allLowercasePlural$", c.ns, opts), &$.type|raw$List{})
$else$Invokes($.NewRootListAction|raw$("$.type|allLowercasePlural$", opts), &$.type|raw$List{})$end$
if obj == nil {
return nil, err
}
Expand All @@ -192,8 +192,8 @@ func (c *Fake$.type|publicPlural$) List(opts $.apiListOptions|raw$) (result *$.t
var getTemplate = `
func (c *Fake$.type|publicPlural$) Get(name string) (result *$.type|raw$, err error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewGetAction|raw$("$.type|privatePlural$", c.ns, name), &$.type|raw${})
$else$Invokes($.NewRootGetAction|raw$("$.type|privatePlural$", name), &$.type|raw${})$end$
$if .namespaced$Invokes($.NewGetAction|raw$("$.type|allLowercasePlural$", c.ns, name), &$.type|raw${})
$else$Invokes($.NewRootGetAction|raw$("$.type|allLowercasePlural$", name), &$.type|raw${})$end$
if obj == nil {
return nil, err
}
Expand All @@ -204,8 +204,8 @@ func (c *Fake$.type|publicPlural$) Get(name string) (result *$.type|raw$, err er
var deleteTemplate = `
func (c *Fake$.type|publicPlural$) Delete(name string, options *$.apiDeleteOptions|raw$) error {
_, err := c.Fake.
$if .namespaced$Invokes($.NewDeleteAction|raw$("$.type|privatePlural$", c.ns, name), &$.type|raw${})
$else$Invokes($.NewRootDeleteAction|raw$("$.type|privatePlural$", name), &$.type|raw${})$end$
$if .namespaced$Invokes($.NewDeleteAction|raw$("$.type|allLowercasePlural$", c.ns, name), &$.type|raw${})
$else$Invokes($.NewRootDeleteAction|raw$("$.type|allLowercasePlural$", name), &$.type|raw${})$end$
return err
}
`
Expand All @@ -223,8 +223,8 @@ func (c *Fake$.type|publicPlural$) DeleteCollection(options *$.apiDeleteOptions|
var createTemplate = `
func (c *Fake$.type|publicPlural$) Create($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewCreateAction|raw$("$.type|privatePlural$", c.ns, $.type|private$), &$.type|raw${})
$else$Invokes($.NewRootCreateAction|raw$("$.type|privatePlural$", $.type|private$), &$.type|raw${})$end$
$if .namespaced$Invokes($.NewCreateAction|raw$("$.type|allLowercasePlural$", c.ns, $.type|private$), &$.type|raw${})
$else$Invokes($.NewRootCreateAction|raw$("$.type|allLowercasePlural$", $.type|private$), &$.type|raw${})$end$
if obj == nil {
return nil, err
}
Expand All @@ -235,8 +235,8 @@ func (c *Fake$.type|publicPlural$) Create($.type|private$ *$.type|raw$) (result
var updateTemplate = `
func (c *Fake$.type|publicPlural$) Update($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewUpdateAction|raw$("$.type|privatePlural$", c.ns, $.type|private$), &$.type|raw${})
$else$Invokes($.NewRootUpdateAction|raw$("$.type|privatePlural$", $.type|private$), &$.type|raw${})$end$
$if .namespaced$Invokes($.NewUpdateAction|raw$("$.type|allLowercasePlural$", c.ns, $.type|private$), &$.type|raw${})
$else$Invokes($.NewRootUpdateAction|raw$("$.type|allLowercasePlural$", $.type|private$), &$.type|raw${})$end$
if obj == nil {
return nil, err
}
Expand All @@ -247,8 +247,8 @@ func (c *Fake$.type|publicPlural$) Update($.type|private$ *$.type|raw$) (result
var updateStatusTemplate = `
func (c *Fake$.type|publicPlural$) UpdateStatus($.type|private$ *$.type|raw$) (*$.type|raw$, error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$("$.type|privatePlural$", "status", c.ns, $.type|private$), &$.type|raw${})
$else$Invokes($.NewRootUpdateSubresourceAction|raw$("$.type|privatePlural$", "status", $.type|private$), &$.type|raw${})$end$
$if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$("$.type|allLowercasePlural$", "status", c.ns, $.type|private$), &$.type|raw${})
$else$Invokes($.NewRootUpdateSubresourceAction|raw$("$.type|allLowercasePlural$", "status", $.type|private$), &$.type|raw${})$end$
if obj == nil {
return nil, err
}
Expand All @@ -260,7 +260,7 @@ var watchTemplate = `
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
func (c *Fake$.type|publicPlural$) Watch(opts $.apiListOptions|raw$) ($.watchInterface|raw$, error) {
return c.Fake.
$if .namespaced$InvokesWatch($.NewWatchAction|raw$("$.type|privatePlural$", c.ns, opts))
$else$InvokesWatch($.NewRootWatchAction|raw$("$.type|privatePlural$", opts))$end$
$if .namespaced$InvokesWatch($.NewWatchAction|raw$("$.type|allLowercasePlural$", c.ns, opts))
$else$InvokesWatch($.NewRootWatchAction|raw$("$.type|allLowercasePlural$", opts))$end$
}
`
29 changes: 18 additions & 11 deletions cmd/libs/go2idl/client-gen/generators/generator-for-type.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (c *$.type|privatePlural$) List(opts $.apiListOptions|raw$) (result *$.type
result = &$.type|raw$List{}
err = c.client.Get().
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|privatePlural$").
Resource("$.type|allLowercasePlural$").
VersionedParams(&opts, api.Scheme).
Do().
Into(result)
Expand All @@ -219,7 +219,7 @@ func (c *$.type|privatePlural$) Get(name string) (result *$.type|raw$, err error
result = &$.type|raw${}
err = c.client.Get().
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|privatePlural$").
Resource("$.type|allLowercasePlural$").
Name(name).
Do().
Into(result)
Expand All @@ -232,7 +232,7 @@ var deleteTemplate = `
func (c *$.type|privatePlural$) Delete(name string, options *$.apiDeleteOptions|raw$) error {
return c.client.Delete().
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|privatePlural$").
Resource("$.type|allLowercasePlural$").
Name(name).
Body(options).
Do().
Expand All @@ -245,7 +245,7 @@ var deleteCollectionTemplate = `
func (c *$.type|privatePlural$) DeleteCollection(options *$.apiDeleteOptions|raw$, listOptions $.apiListOptions|raw$) error {
return c.client.Delete().
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|privatePlural$").
Resource("$.type|allLowercasePlural$").
VersionedParams(&listOptions, api.Scheme).
Body(options).
Do().
Expand All @@ -259,7 +259,7 @@ func (c *$.type|privatePlural$) Create($.type|private$ *$.type|raw$) (result *$.
result = &$.type|raw${}
err = c.client.Post().
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|privatePlural$").
Resource("$.type|allLowercasePlural$").
Body($.type|private$).
Do().
Into(result)
Expand All @@ -273,7 +273,7 @@ func (c *$.type|privatePlural$) Update($.type|private$ *$.type|raw$) (result *$.
result = &$.type|raw${}
err = c.client.Put().
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|privatePlural$").
Resource("$.type|allLowercasePlural$").
Name($.type|private$.Name).
Body($.type|private$).
Do().
Expand All @@ -283,10 +283,17 @@ func (c *$.type|privatePlural$) Update($.type|private$ *$.type|raw$) (result *$.
`

var updateStatusTemplate = `
func (c *$.type|privatePlural$) UpdateStatus($.type|private$ *$.type|raw$) (*$.type|raw$, error) {
result := &$.type|raw${}
err := c.client.Put().Resource("$.type|privatePlural$").Name($.type|private$.Name).SubResource("status").Body($.type|private$).Do().Into(result)
return result, err
func (c *$.type|privatePlural$) UpdateStatus($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) {
result = &$.type|raw${}
err = c.client.Put().
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|allLowercasePlural$").
Name($.type|private$.Name).
SubResource("status").
Body($.type|private$).
Do().
Into(result)
return
}
`

Expand All @@ -296,7 +303,7 @@ func (c *$.type|privatePlural$) Watch(opts $.apiListOptions|raw$) ($.watchInterf
return c.client.Get().
Prefix("watch").
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|privatePlural$").
Resource("$.type|allLowercasePlural$").
VersionedParams(&opts, api.Scheme).
Watch()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *testTypes) Create(testType *testgroup.TestType) (result *testgroup.Test
result = &testgroup.TestType{}
err = c.client.Post().
Namespace(c.ns).
Resource("testTypes").
Resource("testtypes").
Body(testType).
Do().
Into(result)
Expand All @@ -72,25 +72,32 @@ func (c *testTypes) Update(testType *testgroup.TestType) (result *testgroup.Test
result = &testgroup.TestType{}
err = c.client.Put().
Namespace(c.ns).
Resource("testTypes").
Resource("testtypes").
Name(testType.Name).
Body(testType).
Do().
Into(result)
return
}

func (c *testTypes) UpdateStatus(testType *testgroup.TestType) (*testgroup.TestType, error) {
result := &testgroup.TestType{}
err := c.client.Put().Resource("testTypes").Name(testType.Name).SubResource("status").Body(testType).Do().Into(result)
return result, err
func (c *testTypes) UpdateStatus(testType *testgroup.TestType) (result *testgroup.TestType, err error) {
result = &testgroup.TestType{}
err = c.client.Put().
Namespace(c.ns).
Resource("testtypes").
Name(testType.Name).
SubResource("status").
Body(testType).
Do().
Into(result)
return
}

// Delete takes name of the testType and deletes it. Returns an error if one occurs.
func (c *testTypes) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("testTypes").
Resource("testtypes").
Name(name).
Body(options).
Do().
Expand All @@ -101,7 +108,7 @@ func (c *testTypes) Delete(name string, options *api.DeleteOptions) error {
func (c *testTypes) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("testTypes").
Resource("testtypes").
VersionedParams(&listOptions, api.Scheme).
Body(options).
Do().
Expand All @@ -113,7 +120,7 @@ func (c *testTypes) Get(name string) (result *testgroup.TestType, err error) {
result = &testgroup.TestType{}
err = c.client.Get().
Namespace(c.ns).
Resource("testTypes").
Resource("testtypes").
Name(name).
Do().
Into(result)
Expand All @@ -125,7 +132,7 @@ func (c *testTypes) List(opts api.ListOptions) (result *testgroup.TestTypeList,
result = &testgroup.TestTypeList{}
err = c.client.Get().
Namespace(c.ns).
Resource("testTypes").
Resource("testtypes").
VersionedParams(&opts, api.Scheme).
Do().
Into(result)
Expand All @@ -137,7 +144,7 @@ func (c *testTypes) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.client.Get().
Prefix("watch").
Namespace(c.ns).
Resource("testTypes").
Resource("testtypes").
VersionedParams(&opts, api.Scheme).
Watch()
}
12 changes: 11 additions & 1 deletion cmd/libs/go2idl/namer/plural_namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package namer

import "k8s.io/kubernetes/cmd/libs/go2idl/types"
import (
"strings"

"k8s.io/kubernetes/cmd/libs/go2idl/types"
)

type pluralNamer struct {
// key is the case-sensitive type name, value is the case-insensitive
Expand All @@ -37,6 +41,12 @@ func NewPrivatePluralNamer(exceptions map[string]string) *pluralNamer {
return &pluralNamer{exceptions, IL}
}

// NewAllLowercasePluralNamer returns a namer that returns the plural form of the input
// type's name, with all letters in lowercase.
func NewAllLowercasePluralNamer(exceptions map[string]string) *pluralNamer {
return &pluralNamer{exceptions, strings.ToLower}
}

// Name returns the plural form of the type's name. If the type's name is found
// in the exceptions map, the map value is returned.
func (r *pluralNamer) Name(t *types.Type) string {
Expand Down
29 changes: 18 additions & 11 deletions pkg/client/typed/generated/extensions/unversioned/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *daemonSets) Create(daemonSet *extensions.DaemonSet) (result *extensions
result = &extensions.DaemonSet{}
err = c.client.Post().
Namespace(c.ns).
Resource("daemonSets").
Resource("daemonsets").
Body(daemonSet).
Do().
Into(result)
Expand All @@ -72,25 +72,32 @@ func (c *daemonSets) Update(daemonSet *extensions.DaemonSet) (result *extensions
result = &extensions.DaemonSet{}
err = c.client.Put().
Namespace(c.ns).
Resource("daemonSets").
Resource("daemonsets").
Name(daemonSet.Name).
Body(daemonSet).
Do().
Into(result)
return
}

func (c *daemonSets) UpdateStatus(daemonSet *extensions.DaemonSet) (*extensions.DaemonSet, error) {
result := &extensions.DaemonSet{}
err := c.client.Put().Resource("daemonSets").Name(daemonSet.Name).SubResource("status").Body(daemonSet).Do().Into(result)
return result, err
func (c *daemonSets) UpdateStatus(daemonSet *extensions.DaemonSet) (result *extensions.DaemonSet, err error) {
result = &extensions.DaemonSet{}
err = c.client.Put().
Namespace(c.ns).
Resource("daemonsets").
Name(daemonSet.Name).
SubResource("status").
Body(daemonSet).
Do().
Into(result)
return
}

// Delete takes name of the daemonSet and deletes it. Returns an error if one occurs.
func (c *daemonSets) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("daemonSets").
Resource("daemonsets").
Name(name).
Body(options).
Do().
Expand All @@ -101,7 +108,7 @@ func (c *daemonSets) Delete(name string, options *api.DeleteOptions) error {
func (c *daemonSets) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("daemonSets").
Resource("daemonsets").
VersionedParams(&listOptions, api.Scheme).
Body(options).
Do().
Expand All @@ -113,7 +120,7 @@ func (c *daemonSets) Get(name string) (result *extensions.DaemonSet, err error)
result = &extensions.DaemonSet{}
err = c.client.Get().
Namespace(c.ns).
Resource("daemonSets").
Resource("daemonsets").
Name(name).
Do().
Into(result)
Expand All @@ -125,7 +132,7 @@ func (c *daemonSets) List(opts api.ListOptions) (result *extensions.DaemonSetLis
result = &extensions.DaemonSetList{}
err = c.client.Get().
Namespace(c.ns).
Resource("daemonSets").
Resource("daemonsets").
VersionedParams(&opts, api.Scheme).
Do().
Into(result)
Expand All @@ -137,7 +144,7 @@ func (c *daemonSets) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.client.Get().
Prefix("watch").
Namespace(c.ns).
Resource("daemonSets").
Resource("daemonsets").
VersionedParams(&opts, api.Scheme).
Watch()
}