Skip to content

Commit cd0b10f

Browse files
authored
Merge pull request #799 from mcristina422/inflect
fix: Replace deprecated module inflect
2 parents e30f652 + 648d42b commit cd0b10f

12 files changed

+33
-46
lines changed

cmd/util/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"strings"
3030
"text/template"
3131

32-
"github.com/markbates/inflect"
32+
"github.com/gobuffalo/flect"
3333
)
3434

3535
var Domain string
@@ -55,7 +55,7 @@ func Write(path, templateName, templateValue string, data interface{}) bool {
5555
template.FuncMap{
5656
"title": strings.Title,
5757
"lower": strings.ToLower,
58-
"plural": inflect.NewDefaultRuleset().Pluralize,
58+
"plural": flect.Pluralize,
5959
},
6060
).Parse(templateValue))
6161

cmd/webhook.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"os/exec"
2424
"strings"
2525

26-
"github.com/markbates/inflect"
26+
"github.com/gobuffalo/flect"
2727
"github.com/spf13/cobra"
2828
flag "github.com/spf13/pflag"
2929

@@ -65,7 +65,7 @@ This command is only available for v1 scaffolding project.
6565
fmt.Println("Writing scaffold for you to edit...")
6666

6767
if len(o.res.Resource) == 0 {
68-
o.res.Resource = inflect.NewDefaultRuleset().Pluralize(strings.ToLower(o.res.Kind))
68+
o.res.Resource = flect.Pluralize(strings.ToLower(o.res.Kind))
6969
}
7070

7171
err = (&scaffold.Scaffold{}).Execute(input.Options{},

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ module sigs.k8s.io/kubebuilder
33
go 1.12
44

55
require (
6-
github.com/gobuffalo/envy v1.6.15 // indirect
6+
github.com/gobuffalo/flect v0.1.5
77
github.com/inconshreveable/mousetrap v1.0.0 // indirect
8-
github.com/markbates/inflect v1.0.4
8+
github.com/kr/pretty v0.1.0 // indirect
99
github.com/onsi/ginkgo v1.8.0
1010
github.com/onsi/gomega v1.5.0
11-
github.com/rogpeppe/go-internal v1.2.2 // indirect
1211
github.com/spf13/afero v1.2.2
1312
github.com/spf13/cobra v0.0.3
1413
github.com/spf13/pflag v1.0.3
1514
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
1615
golang.org/x/sys v0.0.0-20190506115046-ca7f33d4116e // indirect
1716
golang.org/x/text v0.3.2 // indirect
1817
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c
18+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
1919
gopkg.in/yaml.v2 v2.2.2
2020
)

go.sum

+2-13
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
55
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
6-
github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
7-
github.com/gobuffalo/envy v1.6.15 h1:OsV5vOpHYUpP7ZLS6sem1y40/lNX1BZj+ynMiRi21lQ=
8-
github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
6+
github.com/gobuffalo/flect v0.1.5 h1:xpKq9ap8MbYfhuPCF0dBH854Gp9CxZjr/IocxELFflo=
7+
github.com/gobuffalo/flect v0.1.5/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80=
98
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
109
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1110
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
1211
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
1312
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
1413
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
15-
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
16-
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
1714
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1815
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
1916
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2017
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2118
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
22-
github.com/markbates/inflect v1.0.4 h1:5fh1gzTFhfae06u3hzHYO9xe3l3v3nW5Pwt3naLTP5g=
23-
github.com/markbates/inflect v1.0.4/go.mod h1:1fR9+pO2KHEO9ZRtto13gDwwZaAKstQzferVeWqbgNs=
2419
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
2520
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
2621
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
@@ -29,18 +24,13 @@ github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
2924
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
3025
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3126
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
32-
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
33-
github.com/rogpeppe/go-internal v1.2.2 h1:J7U/N7eRtzjhs26d6GqMh2HBuXP8/Z64Densiiieafo=
34-
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
3527
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
3628
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
3729
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
3830
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
3931
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
4032
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
4133
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
42-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
43-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
4434
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
4535
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4636
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
@@ -67,7 +57,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
6757
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6858
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
6959
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
70-
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
7160
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
7261
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
7362
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=

pkg/scaffold/v1/controller/controller.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"path/filepath"
2424
"strings"
2525

26-
"github.com/markbates/inflect"
26+
"github.com/gobuffalo/flect"
2727
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
2828
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
2929
)
@@ -67,8 +67,7 @@ func (a *Controller) GetInput() (input.Input, error) {
6767
a.ResourcePackage, a.GroupDomain = getResourceInfo(coreGroups, a.Resource, a.Input)
6868

6969
if a.Plural == "" {
70-
rs := inflect.NewDefaultRuleset()
71-
a.Plural = rs.Pluralize(strings.ToLower(a.Resource.Kind))
70+
a.Plural = flect.Pluralize(strings.ToLower(a.Resource.Kind))
7271
}
7372

7473
if a.Path == "" {

pkg/scaffold/v1/resource/resource.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"regexp"
2222
"strings"
2323

24-
"github.com/markbates/inflect"
24+
"github.com/gobuffalo/flect"
2525
)
2626

2727
// Resource contains the information required to scaffold files for a resource.
@@ -60,9 +60,8 @@ func (r *Resource) Validate() error {
6060
return fmt.Errorf("kind cannot be empty")
6161
}
6262

63-
rs := inflect.NewDefaultRuleset()
6463
if len(r.Resource) == 0 {
65-
r.Resource = rs.Pluralize(strings.ToLower(r.Kind))
64+
r.Resource = flect.Pluralize(strings.ToLower(r.Kind))
6665
}
6766

6867
groupMatch := regexp.MustCompile("^[a-z]+$")
@@ -75,9 +74,8 @@ func (r *Resource) Validate() error {
7574
return fmt.Errorf(
7675
"version must match ^v\\d+(alpha\\d+|beta\\d+)?$ (was %s)", r.Version)
7776
}
78-
79-
if r.Kind != inflect.Camelize(r.Kind) {
80-
return fmt.Errorf("Kind must be camelcase (expected %s was %s)", inflect.Camelize(r.Kind), r.Kind)
77+
if r.Kind != flect.Pascalize(r.Kind) {
78+
return fmt.Errorf("kind must be camelcase (expected %s was %s)", flect.Pascalize(r.Kind), r.Kind)
8179
}
8280

8381
return nil

pkg/scaffold/v1/resource/resource_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ var _ = Describe("Resource", func() {
9090
instance = &resource.Resource{Group: "crew", Kind: "firstMate", Version: "v1"}
9191
Expect(instance.Validate()).NotTo(Succeed())
9292
Expect(instance.Validate().Error()).To(ContainSubstring(
93-
`Kind must be camelcase (expected FirstMate was firstMate)`))
93+
`kind must be camelcase (expected FirstMate was firstMate)`))
9494

9595
instance = &resource.Resource{Group: "crew", Kind: "firstmate", Version: "v1"}
9696
Expect(instance.Validate()).NotTo(Succeed())
9797
Expect(instance.Validate().Error()).To(ContainSubstring(
98-
`Kind must be camelcase (expected Firstmate was firstmate)`))
98+
`kind must be camelcase (expected Firstmate was firstmate)`))
9999
})
100100

101101
It("should default the Resource by pluralizing the Kind", func() {
@@ -112,6 +112,12 @@ var _ = Describe("Resource", func() {
112112
Expect(instance.Resource).To(Equal("helmswomen"))
113113
})
114114

115+
It("should allow Cat as a Kind", func() {
116+
instance := &resource.Resource{Group: "crew", Kind: "Cat", Version: "v1"}
117+
Expect(instance.Validate()).To(Succeed())
118+
Expect(instance.Resource).To(Equal("cats"))
119+
})
120+
115121
It("should keep the Resource if specified", func() {
116122
instance := &resource.Resource{Group: "crew", Kind: "FirstMate", Version: "v1", Resource: "myresource"}
117123
Expect(instance.Validate()).To(Succeed())

pkg/scaffold/v2/controller.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"path/filepath"
2424
"strings"
2525

26-
"github.com/markbates/inflect"
26+
"github.com/gobuffalo/flect"
2727

2828
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
2929
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
@@ -52,8 +52,7 @@ func (a *Controller) GetInput() (input.Input, error) {
5252
a.ResourcePackage, a.GroupDomain = getResourceInfo(a.Resource, a.Input)
5353

5454
if a.Plural == "" {
55-
rs := inflect.NewDefaultRuleset()
56-
a.Plural = rs.Pluralize(strings.ToLower(a.Resource.Kind))
55+
a.Plural = flect.Pluralize(strings.ToLower(a.Resource.Kind))
5756
}
5857

5958
if a.Path == "" {

pkg/scaffold/v2/controller_suitetest.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"path/filepath"
2222
"strings"
2323

24-
"github.com/markbates/inflect"
24+
"github.com/gobuffalo/flect"
2525
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
2626
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
2727
"sigs.k8s.io/kubebuilder/pkg/scaffold/v2/internal"
@@ -132,8 +132,7 @@ func (a *ControllerSuiteTest) Update() error {
132132

133133
a.ResourcePackage, a.GroupDomain = getResourceInfo(a.Resource, a.Input)
134134
if a.Plural == "" {
135-
rs := inflect.NewDefaultRuleset()
136-
a.Plural = rs.Pluralize(strings.ToLower(a.Resource.Kind))
135+
a.Plural = flect.Pluralize(strings.ToLower(a.Resource.Kind))
137136
}
138137

139138
ctrlImportCodeFragment := fmt.Sprintf(`"%s/controllers"

pkg/scaffold/v2/crd/enablecainjection_patch.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"path/filepath"
2222
"strings"
2323

24-
"github.com/markbates/inflect"
24+
"github.com/gobuffalo/flect"
2525

2626
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
2727
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
@@ -38,8 +38,7 @@ type EnableCAInjectionPatch struct {
3838
// GetInput implements input.File
3939
func (p *EnableCAInjectionPatch) GetInput() (input.Input, error) {
4040
if p.Path == "" {
41-
rs := inflect.NewDefaultRuleset()
42-
plural := rs.Pluralize(strings.ToLower(p.Resource.Kind))
41+
plural := flect.Pluralize(strings.ToLower(p.Resource.Kind))
4342
p.Path = filepath.Join("config", "crd", "patches",
4443
fmt.Sprintf("cainjection_in_%s.yaml", plural))
4544
}

pkg/scaffold/v2/crd/enablewebhook_patch.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"path/filepath"
2222
"strings"
2323

24-
"github.com/markbates/inflect"
24+
"github.com/gobuffalo/flect"
2525

2626
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
2727
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
@@ -38,8 +38,7 @@ type EnableWebhookPatch struct {
3838
// GetInput implements input.File
3939
func (p *EnableWebhookPatch) GetInput() (input.Input, error) {
4040
if p.Path == "" {
41-
rs := inflect.NewDefaultRuleset()
42-
plural := rs.Pluralize(strings.ToLower(p.Resource.Kind))
41+
plural := flect.Pluralize(strings.ToLower(p.Resource.Kind))
4342
p.Path = filepath.Join("config", "crd", "patches",
4443
fmt.Sprintf("webhook_in_%s.yaml", plural))
4544
}

pkg/scaffold/v2/crd/kustomization.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"path/filepath"
2222
"strings"
2323

24-
"github.com/markbates/inflect"
24+
"github.com/gobuffalo/flect"
2525

2626
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
2727
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
@@ -61,8 +61,7 @@ func (c *Kustomization) Update() error {
6161

6262
// TODO(directxman12): not technically valid if something changes from the default
6363
// (we'd need to parse the markers)
64-
rs := inflect.NewDefaultRuleset()
65-
plural := rs.Pluralize(strings.ToLower(c.Resource.Kind))
64+
plural := flect.Pluralize(strings.ToLower(c.Resource.Kind))
6665

6766
kustomizeResourceCodeFragment := fmt.Sprintf("- bases/%s.%s_%s.yaml\n", c.Resource.Group, c.Domain, plural)
6867
kustomizeWebhookPatchCodeFragment := fmt.Sprintf("#- patches/webhook_in_%s.yaml\n", plural)

0 commit comments

Comments
 (0)