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

✨ Add selectablefield marker #1050

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

everesio
Copy link

@everesio everesio commented Sep 6, 2024

Add support for selectable fields for custom resources #1039

Copy link

linux-foundation-easycla bot commented Sep 6, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Sep 6, 2024
@k8s-ci-robot
Copy link
Contributor

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. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 6, 2024
@k8s-ci-robot
Copy link
Contributor

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. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 6, 2024
@everesio everesio changed the title feat: Add selectablefield marker (:sparkles:) Add selectablefield marker Sep 6, 2024
@everesio everesio changed the title (:sparkles:) Add selectablefield marker ✨ Add selectablefield marker Sep 6, 2024
pkg/crd/markers/crd.go Show resolved Hide resolved
@@ -55,6 +55,9 @@ var CRDMarkers = []*definitionWithHelp{

must(markers.MakeDefinition("kubebuilder:metadata", markers.DescribesType, Metadata{})).
WithHelp(Metadata{}.Help()),

must(markers.MakeDefinition("kubebuilder:selectablefield", markers.DescribesType, SelectableField{})).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a few of these to

// +kubebuilder:metadata:annotations="api-approved.kubernetes.io=https://github.com/kubernetes-sigs/controller-tools";"cert-manager.io/inject-ca-from-secret=cert-manager/cert-manager-webhook-ca"

IIRC they then also have to be added here: https://github.com/kubernetes-sigs/controller-tools/blob/7ef21aae5452047af82f020774639c94aa659eca/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

(but you can just check the failing test after the marker was added to the type)

@sbueringer
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 9, 2024
@sbueringer
Copy link
Member

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

@everesio
Copy link
Author

@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
Copy link
Author

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 everesio@fa0ae90

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
Copy link
Member

@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
Copy link
Author

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

@sbueringer sbueringer added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Sep 24, 2024
@sbueringer
Copy link
Member

Thank you!!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 24, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 22f9975283d774300b2e665b744c8c83bd605d23

@k8s-ci-robot
Copy link
Contributor

[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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 24, 2024
@k8s-ci-robot k8s-ci-robot merged commit f79cfef into kubernetes-sigs:main Sep 24, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants