-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
kube_codegen: smarter grepping of codegen tags #125051
Conversation
/assign @thockin |
++ |
Thanks for this patch Markus, I am dealing with this at kubernetes-sigs/node-feature-discovery#1487 |
/test pull-kubernetes-node-e2e-containerd |
( kube::codegen::internal::grep -l --null \ | ||
-e '+genclient' \ | ||
-e '//\s*+genclient' \ | ||
-r "${in_dir}${one_input_api}" \ | ||
--include '*.go' \ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
/triage accepted |
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.
2b6d124
to
fbb441c
Compare
PR updated, commit message adjusted. @thockin PTAL /retitle kube_codegen: smarter grepping of codegen tags |
/retest |
Looks sane to me. /lgtm |
LGTM label has been added. Git tree hash: d67d744ff82f1f315fa57f6a91e842da82f62bb1
|
[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 |
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:
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?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: