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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Synchonized plural generation with api-machinery #3433

Closed
wants to merge 1 commit into from

Conversation

lauchokyip
Copy link
Contributor

Fixes #3402

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 May 27, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @lauchokyip. 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.

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.

/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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed 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 May 27, 2023
@camilamacedo86
Copy link
Member

@lauchokyip

Could you please squash the commits ?

@varshaprasad96 @everettraven wdyt about this one?
Could you please give a hand on the review?

Copy link

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

+1 for trying to keep apimachinery and kubebuilder synced.

Quick question: this will probably break existing projects that already benefited from gobuffalo/flect pluralize mechanism. Maybe we should allow users to pass a set of "override" plural names (via flag, env/var...?), so at least they can work around this change?

@lauchokyip
Copy link
Contributor Author

/hold

Definitely feel like a breaking change

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 30, 2023
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 @lauchokyip,

Could you please squash the commits?
Also, see that it is not passing in the lint you can run locally make lint locally to check it out.

By last, we need to provide a guidance for those that:

  • Scaffold the project with an previous version, create an api and then get a new kubebuilder version to create another API
    Could you please add the steps in the description of this PR? What guidance/steps should we provide in this case?

It seems for me that would not work at all and this one is a breaking change. For other hand it seems a valid / reasonable request. I am just trying to think if it could be addressed for v4 or if we should only perform this change for an future version like go/v5.

c/c @everettraven @varshaprasad96 @Kavinjsir wdyt about this one?

Copy link
Contributor

@Kavinjsir Kavinjsir left a comment

Choose a reason for hiding this comment

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

Thx for your contribution @lauchokyip ! Just give a first-round review and left a nit.

@camilamacedo86
I'm Okay to make it consistent with the upstream kb plural system, though I personally find it hacky. Basically, the upstream plural system looks far from 'perfect':

  1. The k8s plural implementation itself is kind of broken, like helmswomans and fishs. Also, the implementation looks tricky, where it maintains a hardcoded unpluralizedSuffixes.
  2. Like as you mentioned, if users are migrating their operator projects to the new kubebuilder with such an updated plural system. It may probably bring breaking change. (Though, it might not be a common scenario.)

Also in the future, we may probably change it once again, as such plural system might not be the 'ultimate' solution. (And then users might meet the similar scenario one more time.)

// unpluralizedSuffixes is a list of resource suffixes that are the same plural and singular
// This is only is only necessary because some bits of code are lazy and don't actually use the RESTMapper like they should.
// TODO eliminate this so that different callers can correctly map to resources. This probably means updating all
// callers to use the RESTMapper they mean.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just leave a reference as well, which could be enough.
(This should also resolve the lint error as well)

image

Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @lauchokyip ! I have a couple suggested changes:

Comment on lines 68 to 75
// unpluralizedSuffixes is a list of resource suffixes that are the same plural and singular
// This is only is only necessary because some bits of code are lazy and don't actually use the RESTMapper like they should.
// TODO eliminate this so that different callers can correctly map to resources. This probably means updating all
// callers to use the RESTMapper they mean.
var unpluralizedSuffixes = []string{
"endpoints",
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually need this? Endpoints is a core Kubernetes resource and we likely aren't going to have to differentiate this in kubebuilder.

Comment on lines 80 to 84
for _, skip := range unpluralizedSuffixes {
if strings.HasSuffix(singularName, skip) {
return singular
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably remove this as per my previous comment

Comment on lines 79 to 92
singularName := strings.ToLower(singular)
for _, skip := range unpluralizedSuffixes {
if strings.HasSuffix(singularName, skip) {
return singular
}
}

switch string(singularName[len(singularName)-1]) {
case "s":
return singularName + "es"
case "y":
return strings.TrimSuffix(singularName, "y") + "ies"
}
return singularName + "s"
Copy link
Contributor

Choose a reason for hiding this comment

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

Something I just realized, the restmapper.UnsafeGuessKindToResource that this logic is pulled from is an exported function and something that we could pull in as a dependency. Instead of fully copying this logic I would personally prefer using the exported function so we automatically benefit from any future improvements made to this function.

The main caveat here is that we would be responsible for converting the input string --> a schema.GroupVersionKind and the schema.GroupVersionResource returned by the restmapper.UnsafeGuessKindToResource function --> string

Comment on lines 86 to 90
switch string(singularName[len(singularName)-1]) {
case "s":
return singularName + "es"
case "y":
return strings.TrimSuffix(singularName, "y") + "ies"
Copy link
Member

Choose a reason for hiding this comment

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

There is a piece of code in k8s/code-generator, that deals with this and some of the edge cases explicitly: https://github.com/kubernetes/gengo/blob/ab3349d207d4/namer/plural_namer.go#L36. May not be an immediate action item, but it would be preferable to have a TODO added here, to be able to resuse that piece of code. (It currently is very opinionated to spit out plurals for core k8s resources).

@lauchokyip
Copy link
Contributor Author

lauchokyip commented Jun 2, 2023

Hi @lauchokyip,

Could you please squash the commits? Also, see that it is not passing in the lint you can run locally make lint locally to check it out.

By last, we need to provide a guidance for those that:

  • Scaffold the project with an previous version, create an api and then get a new kubebuilder version to create another API
    Could you please add the steps in the description of this PR? What guidance/steps should we provide in this case?

It seems for me that would not work at all and this one is a breaking change. For other hand it seems a valid / reasonable request. I am just trying to think if it could be addressed for v4 or if we should only perform this change for an future version like go/v5.

c/c @everettraven @varshaprasad96 @Kavinjsir wdyt about this one?

Hi @camilamacedo86 , do you mean providing the migration documents? Any guidance on how I could do that?

I don't know the code well enough to answer this question - if the user generate a CRD named Helmswoman and the plural is set to Helmswomen. Now, the user wants to generate another version for the same CRD for let's say v2, kind Helmswoman. When the new code is merged, would the plural be set to Helmswomans ? If the plural were to set to Helmswomans, will that break anything besides the generated file name?

I will be voting towards putting this into v5 but given the lack of knowledge and context of the source code, definitely need more inputs

Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

Code looks good to me, thanks @lauchokyip !

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 6, 2023
@camilamacedo86
Copy link
Member

Hi @everettraven @varshaprasad96 @Kavinjsir @lauchokyip,

We have encountered several deprecations, and it's essential that we deprecate the declarative plugin as soon as possible. You can find the details in this pull request: #3395

To ensure a cleaner and more maintainable codebase as we continue to grow, we plan to remove all deprecations at the beginning of next year, leading to a major bump for Kubebuilder 4.0.0.

However, since this change will have a significant impact on projects that are already scaffolded, I suggest we consider the following:

  • Let's carefully evaluate whether this change is necessary, taking into account the comments shared by @Kavinjsir in this pull request: 馃悰 Synchonized plural generation with api-machinery聽#3433 (review).
  • In the pull request, it would be helpful to document the manual steps required to update existing projects once this change is merged. @lauchokyip, could you please include these steps in the PR description? We need to provide guidance on how to modify projects built prior to this change, ensuring they won't be affected when a new version of Kubebuilder is released. Please specify the necessary file modifications and steps to be taken. (It is essential because it will help us properly document it in the release and migration guides)
  • @lauchokyip, please ensure that the new code is only used for go/v4 and doesn't impact go/v3, which is already deprecated. By doing so, when we eventually bump to 4.x, the condition will keep the code as the default.
  • Then, I think we might want to consider whether to keep this PR for future go/v5 changes. Once @lauchokyip implements the changes for impact only go/v4 as described above, we can modify the PR for go/v5 easily and merge it at the appropriate time.

Please share your thoughts on these suggestions.

@varshaprasad96
Copy link
Member

@lauchokyip We are interested in resolving this issue. Could you please rebase this so that we revisit it again. Thanks for taking the time for working on this.

@lauchokyip
Copy link
Contributor Author

@lauchokyip We are interested in resolving this issue. Could you please rebase this so that we revisit it again. Thanks for taking the time for working on this.

Let me get back to this in a bit

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 5, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: everettraven, lauchokyip
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@lauchokyip
Copy link
Contributor Author

lauchokyip commented Aug 5, 2023

HI @varshaprasad96 , make generate are failing, can you please check it? I even git clone a brand new repo and it still failed

TODO: update tutorial
ERRO[0009] error fixing cronjob_webhook.go: unable to find the content to be replaced 
exit status 1
make: *** [Makefile:76: generate-docs] Error 1

Does make generate work for you?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 9, 2023
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

@Kavinjsir
Copy link
Contributor

HI @varshaprasad96 , make generate are failing, can you please check it? I even git clone a brand new repo and it still failed

TODO: update tutorial
ERRO[0009] error fixing cronjob_webhook.go: unable to find the content to be replaced 
exit status 1
make: *** [Makefile:76: generate-docs] Error 1

Does make generate work for you?

@lauchokyip Would you rebase the branch based off the latest master branch? There might be an issue for make generate previously. The current master branch should have it fixed. Could you try and see if it works? Feel free to let me know if further questions rasied.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 21, 2024
@camilamacedo86 camilamacedo86 added this to the go/v5 milestone Jan 23, 2024
@camilamacedo86 camilamacedo86 removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 23, 2024
@k8s-ci-robot
Copy link
Contributor

@lauchokyip: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-25-3 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-25-3
pull-kubebuilder-e2e-k8s-1-27-1 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-27-1
pull-kubebuilder-e2e-k8s-1-27-10 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-27-10
pull-kubebuilder-e2e-k8s-1-28-6 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-28-6
pull-kubebuilder-e2e-k8s-1-27-3 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-27-3
pull-kubebuilder-e2e-k8s-1-26-6 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-26-6
pull-kubebuilder-e2e-k8s-1-28-0 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-28-0
pull-kubebuilder-e2e-k8s-1-29-0 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-29-0
pull-kubebuilder-e2e-k8s-1-27-11 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-27-11
pull-kubebuilder-e2e-k8s-1-28-7 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-28-7
pull-kubebuilder-e2e-k8s-1-29-2 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-29-2
pull-kubebuilder-e2e-k8s-1-30-0 b31f4cf link true /test pull-kubebuilder-e2e-k8s-1-30-0

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@camilamacedo86
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kubernetes and Kubebuilder use different mechanisms to generate plurals
8 participants