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

The correct file name should be used in the comments of [kind]_types.go #1925

Closed
south37 opened this issue Dec 30, 2020 · 3 comments · Fixed by #1927
Closed

The correct file name should be used in the comments of [kind]_types.go #1925

south37 opened this issue Dec 30, 2020 · 3 comments · Fixed by #1927
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@south37
Copy link
Contributor

south37 commented Dec 30, 2020

What broke (please include exact error messages if you can)

When we use $ kubebuilder create api, it generates a file like [kind]_types.go. In this file, there is a comment that indicates which file to change when adding a field.

However, the file name in the comment is different from the generated file name. This difference can confuse people.

The example is shown below.

$ kubebuilder create api --group webapp --version v1 --kind Guestbook
Create Resource [y/n]
y
Create Controller [y/n]
y
Writing scaffold for you to edit...
api/v1/guestbook_types.go
controllers/guestbook_controller.go
Running make:
$ make
$PATH/.go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager main.go
kubebuilder create api --group webapp --version v1 --kind Guestbook  6.82s user 5.43s system 153% cpu 7.959 total
$ cat api/v1/guestbook_types.go | grep 'Edit Guestbook_types\.go'
        // Foo is an example field of Guestbook. Edit Guestbook_types.go to remove/update

In the above example, Guestbook_types.go is written in a comment. This is different from the correct file name guestbook_types.go.

What did you expect to happen? What do you think went wrong?

A comment should use a correct file name. In the above example, guestbook_types.go should be used.

What versions of software are you using?

$ go version
go version go1.15.3 darwin/amd64

$ kubebuilder version
Version: version.Version{KubeBuilderVersion:"2.3.1", KubernetesVendor:"1.16.4", GitCommit:"8b53abeb4280186e494b726edf8f54ca7aa64a49", BuildDate:"2020-03-26T16:42:00Z", GoOs:"unknown", GoArch:"unknown"}

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.1", GitCommit:"c4d752765b3bbac2237bf87cf0b1c2e307844666", GitTreeState:"clean", BuildDate:"2020-12-19T07:38:38Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1", GitCommit:"206bcadf021e76c27513500ca24182692aabd17e", GitTreeState:"clean", BuildDate:"2020-09-14T07:30:52Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
$ cat go.mod | grep controller-runtime
        sigs.k8s.io/controller-runtime v0.5.0
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H114

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Dec 30, 2020
@camilamacedo86
Copy link
Member

Hi @south37,

I checked that the same behaviour still for v3/ as well. See: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v3/api/v1/admiral_types.go#L31

The fix here shows very easy. We just need to change the Edit {{ .Resource.Kind }}_types.go to remove/update here and here to use the a lower case value strings.ToLower(u.Resource.Kind)).

Would you like to contribute to the project by doing the PR to fix it?

@south37
Copy link
Contributor Author

south37 commented Dec 30, 2020

Hi @camilamacedo86,

Thanks for your quick response and the helpful advice! 😄
I'd like to contribute by creating a PR! 💡

@south37
Copy link
Contributor Author

south37 commented Dec 30, 2020

I created a PR to fix this issue💡
cf. #1927

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants