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

kube_codegen: smarter grepping of codegen tags #125051

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

marquiz
Copy link
Contributor

@marquiz marquiz commented May 22, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

Be smarter about finding the input packages for genclient et al. The
previous grep patterns were too generic. This caused code-generator, for
example, to pick up it's own auto-generated packages. In this particular
case having a status field in the type adds a comment to the
autogenerated code like:

// Add a +genclient:noStatus comment above the type...

This, in turn causes problems in some scenarios where the input (api)
and the target package for the auto-generated code reside in separate go
modules

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 22, 2024
@marquiz
Copy link
Contributor Author

marquiz commented May 22, 2024

/assign @thockin

@k8s-ci-robot k8s-ci-robot added area/code-generation sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 22, 2024
@k8s-ci-robot k8s-ci-robot requested review from deads2k and wojtek-t May 22, 2024 12:29
@ArangoGutierrez
Copy link
Contributor

++

@ArangoGutierrez
Copy link
Contributor

Thanks for this patch Markus, I am dealing with this at kubernetes-sigs/node-feature-discovery#1487

@ArangoGutierrez
Copy link
Contributor

/test pull-kubernetes-node-e2e-containerd

Comment on lines 570 to 573
( kube::codegen::internal::grep -l --null \
-e '+genclient' \
-e '//\s*+genclient' \
-r "${in_dir}${one_input_api}" \
--include '*.go' \
Copy link
Member

Choose a reason for hiding this comment

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

This is OK, but still feels dirty. Maybe we should take the output of the first grep and pipe it to xargs grep -v '^// Code generated by .* DO NOT EDIT.$ (exept not literlly xargs because xargs is dumb WRT maybe-empty input on some OSes)?

Or is that overkill?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the quick review @thockin. I was also thinking something along those lines you suggested but decided to suggest the simplest thing, to avoid breaking anything and not to complicate the shell script wizardry more 😅

If xargs is not an option would adding one more while-read be a possible solution?

        ( kube::codegen::internal::grep -l --null \
            -e '//\s*+genclient' \
            -r "${in_dir}${one_input_api}" \
            --include '*.go' \
            || true \
        ) | while read -r f; do grep -L -e  '^// Code generated by .* DO NOT EDIT.$' $f; done \
        | while read -r -d $'\0' F; do dirname "${F}"; done

Copy link
Member

Choose a reason for hiding this comment

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

We don't need both. Simply matching on \s* seems sufficient. In fact, maybe we should grep for ^\s*//\s*+genclient to really anchor it.

In fact, we should probably do the same in all the other places we use internal::grep, even though they are not a problem (yet). What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should grep for ^\s*//\s*+genclient to really anchor it.

Better 👍

In fact, we should probably do the same in all the other places we use internal::grep, even though they are not a problem (yet). What do you think?

Makes sense to me. I'll make the change and update the PR

@cici37
Copy link
Contributor

cici37 commented May 28, 2024

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 28, 2024
Be smarter about finding the input packages for genclient et al.  The
previous grep patterns were too generic. This caused code-generator, for
example, to pick up it's own auto-generated packages. In this particular
case having a status field in the type adds a comment to the
autogenerated code like:

  // Add a +genclient:noStatus comment above the type...

This, in turn causes problems in some scenarios where the input (api)
and the target package for the auto-generated code reside in separate go
modules.
@marquiz marquiz force-pushed the devel/codegen-fix-grep branch from 2b6d124 to fbb441c Compare May 31, 2024 07:51
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 31, 2024
@marquiz
Copy link
Contributor Author

marquiz commented May 31, 2024

PR updated, commit message adjusted. @thockin PTAL

/retitle kube_codegen: smarter grepping of codegen tags

@k8s-ci-robot k8s-ci-robot changed the title kube_codegen: smarter grepping of +genclient directive kube_codegen: smarter grepping of codegen tags May 31, 2024
@thockin
Copy link
Member

thockin commented Jun 19, 2024

/retest

@thockin
Copy link
Member

thockin commented Jun 19, 2024

Looks sane to me.

/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 Jun 19, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: d67d744ff82f1f315fa57f6a91e842da82f62bb1

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: marquiz, thockin

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 Jun 19, 2024
@k8s-ci-robot k8s-ci-robot merged commit 01c9d26 into kubernetes:master Jun 19, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Jun 19, 2024
@marquiz marquiz deleted the devel/codegen-fix-grep branch July 9, 2024 06:32
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. area/code-generation cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants