kubernetes / kube-openapi

Kubernetes OpenAPI spec generation & serving
Apache License 2.0
317 stars 205 forks source link

Do not import github.com/google/go-cmp/cmp outside tests. #430

Closed dominiquelefevre closed 1 year ago

dominiquelefevre commented 1 year ago

Go-cmp relies heavily on reflection in ways that casue the golang compiler to disable the dead code elimination. Even declaring a variable of type cmp.Option disables the DCE.

Pkg/validation/spec has SwaggerDiffOptions that is only used in tests, but is declared in the package itself. This disables the DCE in every user of k8s.io/client-go. Move SwaggerDiffOptions to swagger_test.go where it belongs.

linux-foundation-easycla[bot] commented 1 year ago

CLA Signed

The committers listed above are authorized under a signed CLA.

k8s-ci-robot commented 1 year ago

Welcome @dominiquelefevre!

It looks like this is your first PR to kubernetes/kube-openapi 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-openapi has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

apelisse commented 1 year ago

All of spec/fuzz.go is used for tests and should never be imported in an actual program, not just the diff options. Should we move the whole file in a spectest package?

dominiquelefevre commented 1 year ago

All of spec/fuzz.go is used for tests and should never be imported in an actual program, not just the diff options. Should we move the whole file in a spectest package?

Oh, that's absolutely reasonable. Renamed the whole file to fuzz_test.go so that it is included into test builds only.

apelisse commented 1 year ago

Are we 100% sure that none of this is used outside of this repo? Will this break kubernetes/kubernetes?

dominiquelefevre commented 1 year ago

Are we 100% sure that none of this is used outside of this repo? Will this break kubernetes/kubernetes?

I've grepped the k8s source for SwaggerFuzzFuncs and SwaggerDiffOptions. Kube-openapi's pkg/validation/spec is the only place where I find them.

Moreover, I've tested the patch with a project of my own that uses a bunch of k8s.io/* libs and even k8s.io/apiserver. It compiles just fine.

dominiquelefevre commented 1 year ago

ping @apelisse

apelisse commented 1 year ago

I don't see this being used anywhere, so it looks good to me. /assign @liggitt

liggitt commented 1 year ago

/approve /lgtm

dominiquelefevre commented 1 year ago

Hi, anybody out here? @sttts please have a look at the patch.

sttts commented 1 year ago

/approve

k8s-ci-robot commented 1 year ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dominiquelefevre, liggitt, sttts

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes/kube-openapi/blob/master/OWNERS)~~ [sttts] - ~~[pkg/validation/OWNERS](https://github.com/kubernetes/kube-openapi/blob/master/pkg/validation/OWNERS)~~ [liggitt,sttts] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment