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

🐛 Fix the kubebuilder api creation when resource creation is set to false #1770

Merged
merged 1 commit into from
Nov 3, 2020

Conversation

prafull01
Copy link
Contributor

Description
Fix the kb create api command when the create resource is set to false.
Added tests in the generate_testdata.sh so that such issue doesn't occur again.

Motivation*
Fixes: #1767

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 2, 2020
@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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 2, 2020
@prafull01
Copy link
Contributor Author

/cc @camilamacedo86

generate_testdata.sh Outdated Show resolved Hide resolved
@camilamacedo86
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 Nov 2, 2020
Copy link
Contributor

@Adirio Adirio left a comment

Choose a reason for hiding this comment

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

Code seems correct, but I haven't checked if the scaffolded files work properly.

I remember talking about a related topic with @DirectXMan12 some months ago. Having the WireResource field set to false is not enough to know if the CRD is an external one. For example, imagine the following sequence:

kubebuilder init
kubebuilder create api --group ship --version v1beta1 --kind Frigate --resource=true --controller=false
kubebuilder create api --group ship --version v1beta1 --kind Frigate --resource=false --controller=true

This case should be supported, maybe at the start we don't think we need a controller or we just want to do it in tweo steps.

@prafull01
Copy link
Contributor Author

@camilamacedo86 IMO, we should add the new attribute to the PROJECT file for v3+, but we should be fixing this in v2 as well with this current approach. Currently, For v2 it will completely break in the scaffolding if user provides resources=false.

@Adirio The case you have mentioned is supported, the only thing which will be missing is: api import and and For() in the controllers file, because controllers file will not be re written. For V2, user has to either manually do it later or he has to run --resources --controller as true again..

WDYT?

@Adirio
Copy link
Contributor

Adirio commented Nov 2, 2020

You meak using this as a hot-fix for v2 and properly designing v3 to have a better solution? I think I'm ok with that.

In that case, wherever a input is required from the user, at least a comment should be placed. For example in the For() call you mention early, we should probably tell the user that he needs to write that part.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Nov 2, 2020

Hi @prafull01 and @Adirio,

I removed my latest commend and I will try to do centralize all in just one.

I tested locally the scenario added by @Adirio

$kubebuilder init
$kubebuilder create api --group ship --version v1beta1 --kind Frigate --resource=false --controller=true
$kubebuilder create api --group ship --version v1beta1 --kind Frigate --resource=true --controller=false

And it worked with changes added here. Also, see that it was added in the tests as well.

IMO we could have the values of the flags info --resource and --controller stored in the PROJECT file because then, we could easily achieve the goal, for example, to re-create the project from the scratch via the config. In my understanding, the PROJECT file ought to reflect all inputs used. however, could not be done for v2+.

Regards this solution I am OK with it. Really thank you for the collab @prafull01, it is

/approve

for me 👍

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 2, 2020
@prafull01 prafull01 requested a review from Adirio November 3, 2020 05:50
@Adirio
Copy link
Contributor

Adirio commented Nov 3, 2020

P.S.: the scenario I mentioned and Camila tested does get scaffolded, but some lines are not written to the file as if we didn't have the CRD inside the project when we do.

Copy link
Contributor

@Adirio Adirio left a comment

Choose a reason for hiding this comment

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

The four suggested changes need to be applied also to the v3 equivalent file.

@prafull01
Copy link
Contributor Author

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

Copy link
Contributor

@Adirio Adirio left a comment

Choose a reason for hiding this comment

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

Still some changes needed

Copy link
Contributor Author

@prafull01 prafull01 left a comment

Choose a reason for hiding this comment

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

Still some changes needed
My bad, apparently doing changes fastly so missed those. Fixed it. Thanks 👍

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Adirio, 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

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.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 3, 2020
@k8s-ci-robot k8s-ci-robot merged commit ec50740 into kubernetes-sigs:master Nov 3, 2020
@prafull01 prafull01 deleted the kb-noapi branch November 3, 2020 20:20
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.

Make manifests is not working when only the controller is scaffolded by the create api
4 participants