Skip to content

Fix conversion-gen handling of unexported fields and custom conversions of pointers #133325

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Jul 30, 2025

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Allows conversion-gen to successfully generate conversions for protoc-generated types with unexpected state fields.

Prereq of #133026, see discussion thread in #133026 (comment)

Which issue(s) this PR is related to:

#96564

Does this PR introduce a user-facing change?

NONE

/sig api-machinery
/cc @saschagrunert

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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. labels Jul 30, 2025
@liggitt liggitt force-pushed the conversion-gen-unexported-pointers branch from 276db88 to 66f7e30 Compare July 30, 2025 21:21
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/code-generation and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 30, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt

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 Jul 30, 2025
@liggitt liggitt added this to the v1.35 milestone Jul 30, 2025
@@ -130,6 +140,28 @@ func Convert_example_Conversion_To_v1_Conversion(in *example.Conversion, out *Co
return autoConvert_example_Conversion_To_v1_Conversion(in, out, s)
}

func autoConvert_v1_ConversionPrivate_To_example_ConversionPrivate(in *ConversionPrivate, out *example.ConversionPrivate, s conversion.Scope) error {
out.PublicField = in.PublicField
out.privateField = in.privateField
Copy link
Member Author

Choose a reason for hiding this comment

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

This is invalid and will fail to compile. The following commit fixes the generator to not produce this line.

@@ -142,26 +142,16 @@ func Convert_example_Conversion_To_v1_Conversion(in *example.Conversion, out *Co

func autoConvert_v1_ConversionPrivate_To_example_ConversionPrivate(in *ConversionPrivate, out *example.ConversionPrivate, s conversion.Scope) error {
out.PublicField = in.PublicField
out.privateField = in.privateField
// WARNING: out.privateField is not exported and cannot be set
Copy link
Member Author

Choose a reason for hiding this comment

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

This demonstrates the fixed generated conversion.

Comment on lines 191 to 192
// FIXME: Provide conversion function to convert *ConversionCustom to *example.ConversionCustom
compileErrorOnMissingConversion()
Copy link
Member Author

Choose a reason for hiding this comment

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

These demonstrate the inability of the generated conversion to find the existing custom conversion function it should call here. The following commit fixes this.

@seans3
Copy link
Contributor

seans3 commented Aug 5, 2025

/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 Aug 5, 2025
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/L Denotes a PR that changes 100-499 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.

3 participants