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

✨ Added support for empty group in kubebuilder api creation with v3+ #1404 #1679

Merged
merged 1 commit into from
Sep 25, 2020

Conversation

prafull01
Copy link
Contributor

@prafull01 prafull01 commented Sep 13, 2020

Description of the change:

  1. Added support for the kubebuilder api creation without providing any group. If no group is provided then instead of "group"."domain", apiVersion will have only "domain"
  2. Added validation that you can't provide group and domain both as empty
  3. Added multi group support for the empty group by not creating a directory for the empty group in the apis and controller directory.

Motivation for the change:

It will improve user experience in api creation using kubebuilder.
It will solve the workarounds used by user to just have their domain name as the apiVersion.

Fixes #1404

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 13, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @prafull01!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. 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/kubebuilder 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
Copy link
Contributor

Hi @prafull01. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 13, 2020
@gabbifish
Copy link
Contributor

/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 14, 2020
@prafull01
Copy link
Contributor Author

/retest

Copy link
Contributor

@gabbifish gabbifish left a comment

Choose a reason for hiding this comment

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

Thank you for seeing #1404 through! I had some minor nits, but this looks good to me :)

pkg/model/resource/options.go Outdated Show resolved Hide resolved
pkg/model/resource/options.go Outdated Show resolved Hide resolved
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

HI @prafull01.,

Really thank you for the contribution 👍 It is great. IMO we need to apply this only to v3+, we need make the tool be able to work with empty groups instead of replacing the empty string by core and it is missing this scenario to the generate_testadata.sh script.

However, it is great that you are looking for to address this need.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Sep 14, 2020

Also, could you please update the title with the mojo: https://github.com/kubernetes-sigs/kubebuilder/blob/master/CONTRIBUTING.md#pr-process and add (v3+ only)? Also, please ensure that your commits are squashed.

@prafull01 prafull01 changed the title Added support for empty group in kubebuilder api creation #1404 ✨ Added support for empty group in kubebuilder api creation #1404 Sep 14, 2020
@prafull01 prafull01 changed the title ✨ Added support for empty group in kubebuilder api creation #1404 ✨ Added support for empty group in kubebuilder api creation with v3+ #1404 Sep 14, 2020
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 14, 2020
@@ -25,4 +25,6 @@ resources:
- group: foo.policy
kind: HealthCheckPolicy
version: v1
- kind: Lakers
version: v1
Copy link
Member

Choose a reason for hiding this comment

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

👍

@prafull01 prafull01 force-pushed the empty-group branch 2 times, most recently from c67b64f to 0766756 Compare September 14, 2020 15:32
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/approve

Great work 🥇

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, prafull01

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 17, 2020

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
Copy link
Member

Choose a reason for hiding this comment

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

👍

@camilamacedo86
Copy link
Member

/test pull-kubebuilder-e2e-k8s-1-17-0

@camilamacedo86
Copy link
Member

Hi @prafull01,

The coveralls check is not passing because it is missing cover the ValidateV2 with all same checks that is done for Validate + the group one. See: https://coveralls.io/builds/33545877/source?filename=pkg/model/resource/options.go#L88

@prafull01
Copy link
Contributor Author

Hi @prafull01,

The coveralls check is not passing because it is missing cover the ValidateV2 with all same checks that is done for Validate + the group one. See: https://coveralls.io/builds/33545877/source?filename=pkg/model/resource/options.go#L88

There are two ways I can handle it:

  1. Use the same test data to validate against Validate() and ValidateV2() and in the same test cases.
  2. Write the similar test case to test the ValidateV2(), however it will duplicate the lots of test cases.

How should we handle this?

@camilamacedo86
Copy link
Member

camilamacedo86 commented Sep 17, 2020

Write the similar test case to test the ValidateV2(), however it will duplicate the lots of test cases.

I think would be fine just duplicate as well. We can remove the tests when the V2 be removed.
If you face lint issues because of the duplication use //nolint:dupl to ignore the check and please just add a comment explaining that we are duplicating the cases for V2 but that would also be removed when v2 will no longer be supported.

Please, feel free to choose the way that you think that it would be better.

@prafull01
Copy link
Contributor Author

/test pull-kubebuilder-e2e-k8s-1-14-1

@prafull01
Copy link
Contributor Author

/assign @camilamacedo86

@prafull01
Copy link
Contributor Author

/assign @DirectXMan12

@DirectXMan12
Copy link
Contributor

minor nit: the commit message mentions the "core" directory, but that bit seems gone. Can you fix up the commit message. AIUI, with multigroup we'll end up with

pkgs/apis/v1/xyz_types.go # test.kubebuilder.io/v1
pkgs/apis/foo/v1/xyz_types.go # foo.test.kubebuilder.io/v1

Is that correct?

@DirectXMan12
Copy link
Contributor

(otherwise, I delegate to @camilamacedo86 for the lgtm ;-) )

@prafull01
Copy link
Contributor Author

minor nit: the commit message mentions the "core" directory, but that bit seems gone. Can you fix up the commit message. AIUI, with multigroup we'll end up with

pkgs/apis/v1/xyz_types.go # test.kubebuilder.io/v1
pkgs/apis/foo/v1/xyz_types.go # foo.test.kubebuilder.io/v1

Is that correct?

Fixed the commit message. Yes, the path you mentioned is correct for empty group and non empty group.

Copy link
Contributor

@gabbifish gabbifish left a comment

Choose a reason for hiding this comment

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

I had one nit about what looked like an unnecessary check, but otherwise this looks good to me!

@@ -137,6 +137,10 @@ func (p *createAPIPlugin) Validate() error {
return err
}

if p.resource.Group == "" && p.config.Domain == "" {
Copy link
Contributor

@gabbifish gabbifish Sep 22, 2020

Choose a reason for hiding this comment

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

I think this check is redundant, given that p.resource.Validate() (called above) never allows p.Config.Domain to be an empty string in the first place?

Copy link
Contributor Author

@prafull01 prafull01 Sep 22, 2020

Choose a reason for hiding this comment

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

@gabbifish IMO this is a necessary check, while initializing a project (kb init) you can provide a domain which can be empty.

Validate() function doesn't check the value of domain, it only checks the group, version, kind and related values which are provided in create api command. (kb create api). Domain is provided at the init level. Hence this check is necessary to know a user do not provide domain and group both as empty.

@prafull01
Copy link
Contributor Author

@camilamacedo86 Rebase done. make generate done, to have the finalizers markers in the multi-group with empty group api(lakers).

@prafull01
Copy link
Contributor Author

/test pull-kubebuilder-e2e-k8s-1-15-3

@camilamacedo86
Copy link
Member

camilamacedo86 commented Sep 25, 2020

It shows great for me. I could not find any issue with that.
Also, received the @DirectXMan12 and @gabbifish oks.

So, it shows fine for we move forward
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 25, 2020
@k8s-ci-robot k8s-ci-robot merged commit a2f2398 into kubernetes-sigs:master Sep 25, 2020
@prafull01 prafull01 deleted the empty-group branch November 3, 2020 20:41
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: support "empty" group for API resources, i.e. with group == domain
5 participants