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

Cleanup manual conversions #123736

Merged
merged 4 commits into from
Apr 18, 2024

Conversation

thockin
Copy link
Member

@thockin thockin commented Mar 5, 2024

These might have been needed in the past, but no longer. The ones that are left are a bad situation.

When we do codegen we: a) remove generated files; b) set a build tag to ignore generated files. Then conversion-gen tool searches for specially-named conversion functions. When there is a cross-API dependency, it can't find the functions (because (a) and (b) above) so they generate a compile error. We should do better. For now, docs++.

/kind cleanup

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. sig/apps Categorizes an issue or PR as relevant to SIG Apps. labels Mar 5, 2024
@k8s-ci-robot k8s-ci-robot added sig/auth Categorizes an issue or PR as relevant to SIG Auth. 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. 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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 5, 2024
Explain why seemingly-useless manual conversions are needed.  This is
deeply unfortunate, but better to document it than not.
@thockin thockin force-pushed the cleanup_manual_conversions branch from 9cfffab to ca0d2e2 Compare March 6, 2024 05:46
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 6, 2024
@thockin
Copy link
Member Author

thockin commented Mar 6, 2024

/retest

@alexzielenski
Copy link
Contributor

alexzielenski commented Mar 6, 2024

When there is a cross-API dependency, it can't find the functions (because (a) and (b) above) so they generate a compile error.

I haven't looked deeply into conversion-gen, so here are some assumptions I'm making (forgive me if its an oversimplification):

  1. Generates a list of all GVKs (and their runtime type)
  2. Pair all GVKs with all other GVKs of the same GroupKind (to find the list of necessary conversions)
  3. Generate autoConvert_* and registration for all GVK pairs
  4. Find all manually implemented conversion functions
  5. Filter out all manually implemented conversions functions from the list of GVK pairs
  6. Generate Convert_* for remaining GVK pairs

IIUC the issue is that to determine # 4 the codebase needs to be compilable. This fails due to missing symbol references after removing generated code and enabling a build tag.

I'm surprised that we need a valid full build for this. I would expect it to be possible to perform a best-effort typecheck (where type check/symbol errors are repalced with an Error AST node, or similar).
Is that not possible in gengo

Copy link
Contributor

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

/lgtm

can confirm PR is a no-op: removes manually written top level conversions functions to replace them with autogenerated ones with identical content.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 9b50a1beae8bae297b935201a03dcf9be5824355

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

@thockin
Copy link
Member Author

thockin commented Mar 7, 2024

IIUC the issue is that to determine # 4 the codebase needs to be compilable. This fails due to missing symbol references after removing generated code and enabling a build tag.

More than that, we always exclude generated code when generating code. Fundamentally, it's (IMO) sloppy and horrible that we just search for functions with the right name and fingerprint. I think it would be better to do something like:

  • Types which have manual conversions say so with a tag.
  • Conversion-gen doesn't need the function to exist in order to "find it" - it just emits calls to the manual function or the named-by-convention function.

Edit: a few notes

Consider the case of generating for (e.g.) storage.VolumeAttachmentSource, which contains a reference to core.PersistentVolumeSpec. genConversion.GenerateType() calls generateConversion(t, peerType) and generateConversion(peerType, t). At that point in time we know which package we are generating into (storage) and which packages the types in question come from (core and core/v1). We do not actually know which of those two names is the "internal" name, except by pattern-matching (gross).

We can't keep a lookaside to know which types have already been generated to track which are internal, because we can't (I think) be sure that the dep will already have been handled - the sort is alphabetic, not topological.

So, in the absence of extra information, this is harder than I made it sound.

@ritazh
Copy link
Member

ritazh commented Mar 18, 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 Mar 18, 2024
@thockin thockin added this to the v1.31 milestone Apr 15, 2024
@k8s-ci-robot k8s-ci-robot merged commit c43b733 into kubernetes:master Apr 18, 2024
14 checks passed
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants