kubernetes-sigs / controller-tools

Tools to use with the controller-runtime libraries
Apache License 2.0
721 stars 416 forks source link

:sparkles: Add selectablefield marker #1050

Closed everesio closed 4 days ago

everesio commented 3 weeks ago

Add support for selectable fields for custom resources https://github.com/kubernetes-sigs/controller-tools/issues/1039

linux-foundation-easycla[bot] commented 3 weeks ago

CLA Signed

The committers listed above are authorized under a signed CLA.

k8s-ci-robot commented 3 weeks ago

Welcome @everesio!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. 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-sigs/controller-tools 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:

k8s-ci-robot commented 3 weeks ago

Hi @everesio. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
sbueringer commented 2 weeks ago

/ok-to-test

sbueringer commented 1 week ago

@everesio Do you have time to address the findings above?

everesio commented 5 days ago

@sbueringer Sorry, I thought the remarks were directed at the other reviewers. I can address the findings. Let's clarify the issues:

  1. Do you want to have some test which will the "if selectableFields == nil" check ? If similar test exists for printcolumn i can do it analogically.
  2. I will add a new marker to the testdata.kubebuilder.io_cronjobs.yaml and check the parser_integration_test.go
everesio commented 5 days ago

I am just wondering if there is a regression, as the generated specification creates more differences than expected. This issue also occurs on the main branch without my changes.

The binary was built with make release-binary and later in the pkg/crd/testdata the command ../../../out/controller-gen crd paths=. output:dir=. was invoked

See result https://github.com/everesio/controller-tools/commit/fa0ae906c2fc6f89db426af0480bfe2dc5be9d66

Generated output with warnings:

➜  testdata git:(selectable-field-test) ../../../out/controller-gen crd paths=. output:dir=.
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:273:23: found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:273:2: must apply multipleof to a numeric value, found 
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:273:2: must apply minimum to a numeric value, found 
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:273:2: must apply maximum to a numeric value, found 
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:278:25: found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:278:2: must apply minimum to a numeric value, found 
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:278:2: must apply maximum to a numeric value, found 
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:278:2: must apply multipleof to a numeric value, found 
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:291:2: encountered struct field "unexportedField" without JSON tag in type "CronJobSpec"
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:423:2: encountered struct field "bar" without JSON tag in type "unexportedStruct"
/home/michal/go/src/sigs.k8s.io/controller-tools/pkg/crd/testdata/cronjob_types.go:431:2: encountered struct field "qux" without JSON tag in type "ExportedStruct"
Error: not all generators ran successfully
sbueringer commented 4 days ago

@sbueringer Sorry, I thought the remarks were directed at the other reviewers. I can address the findings. Let's clarify the issues:

No worries!

  1. Do you want to have some test which will the "if selectableFields == nil" check ? If similar test exists for printcolumn i can do it analogically.

I was mostly wondering when this case would happen. But it seems like it's just a safeguard against a case that should never happen in practice. I think let's leave it as is and also not try to add test coverage for it

I am just wondering if there is a regression, as the generated specification creates more differences than expected. This issue also occurs on the main branch without my changes.

Not sure I have a good answer to that. What I did in the past was to modify cronjob_types.go and then run the tests in parser_integration_test.go. The resulting output than made it clear how the YAML with the CRD has to be modified.

I would propose to do the same here to unblock this PR and then maybe open a separate issue to investigate why these testdata YAMLs differ from the ones that controller-gen would produce.

everesio commented 4 days ago

Test added. I've modified cronjob_types.go and testdata.kubebuilder.io_cronjobs.yaml

sbueringer commented 4 days ago

Thank you!!

/lgtm /approve

k8s-ci-robot commented 4 days ago

LGTM label has been added.

Git tree hash: 22f9975283d774300b2e665b744c8c83bd605d23

k8s-ci-robot commented 4 days ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: everesio, sbueringer

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-sigs/controller-tools/blob/main/OWNERS)~~ [sbueringer] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment