Skip to content

Make conversion-gen automatically pick up autogenerated conversion functions of types across packages #142345

Description

@luxas

What happened?

Right now, if you have a cross-package type reference, e.g. the authorization.k8s.io type AuthorizationConditionsRequest refers to AdmissionRequest in admission.k8s.io, conversion-gen fails with

	if in.AdmissionRequest != nil {
		in, out := &in.AdmissionRequest, &out.AdmissionRequest
		*out = new(admission.AdmissionRequest)
		// FIXME: Provide conversion function to convert admissionv1.AdmissionRequest to admission.AdmissionRequest
		compileErrorOnMissingConversion()
	} else {
		out.AdmissionRequest = nil
	}

in the generated code on the authorization.k8s.io side. This is because conversion-gen doesn't "see" any ready-made conversion for AdmissionRequest between its internal and external versions. However, conversion-gen is in fact responsible for generating that conversion too, hence it doesn't exist up front.

This can be worked around by adding the following to pkg/apis/admission/v1/conversion.go:

// Convert_v1_AdmissionRequest_To_admission_AdmissionRequest just calls the covering autogenerated function, but is defined and thus
// "exported" in conversion.go, such that it is usable by other API groups that embed AdmissionRequest.
func Convert_v1_AdmissionRequest_To_admission_AdmissionRequest(in *admissionv1.AdmissionRequest, out *admission.AdmissionRequest, s conversion.Scope) error {
	return autoConvert_v1_AdmissionRequest_To_admission_AdmissionRequest(in, out, s)
}

// Convert_admission_AdmissionRequest_To_v1_AdmissionRequest just calls the covering autogenerated function, but is defined and thus
// "exported" in conversion.go, such that it is usable by other API groups that embed AdmissionRequest.
func Convert_admission_AdmissionRequest_To_v1_AdmissionRequest(in *admission.AdmissionRequest, out *admissionv1.AdmissionRequest, s conversion.Scope) error {
	return autoConvert_admission_AdmissionRequest_To_v1_AdmissionRequest(in, out, s)
}

What did you expect to happen?

I want conversion-gen to understand what Convert_X_Z_To_Y_Z functions it will generate, and call those automatically when creating the conversions.

How can we reproduce it (as minimally and precisely as possible)?

Consider the type structure e.g. in #137633
Make a cross-API-package type reference in core Kubernetes, and try to generate a conversion.

Anything else we need to know?

No response

Kubernetes version

Details

Latest main

Cloud provider

Details N/A

OS version

Details
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Details

Container runtime (CRI) and version (if applicable)

Details

Related plugins (CNI, CSI, ...) and versions (if applicable)

Details

Activity

  1. added
    kind/bugCategorizes issue or PR as related to a bug.
    on Sep 23, 2026
  2. added
    needs-sigIndicates an issue or PR lacks a `sig/foo` label and requires one.
    needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.
    on Sep 23, 2026
  3. kubernetes-prow commented on Sep 23, 2026

    @kubernetes-prow
    Contributor

    This issue is currently awaiting triage.

    If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

    The triage/accepted label can be added by org members by writing /triage accepted in a comment.

    Details

    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.

  4. luxas commented on Sep 23, 2026

    @luxas
    MemberAuthor

    /sig api-machinery

  5. added
    sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.
    and removed
    needs-sigIndicates an issue or PR lacks a `sig/foo` label and requires one.
    on Sep 23, 2026
  6. sarooshmehboob commented on Sep 23, 2026

    @sarooshmehboob

    /assign

  7. luxas commented on Oct 9, 2026

    @luxas
    MemberAuthor

    Thanks for taking this on @sarooshmehboob! 🎉

    When this is fixed, revert this part of #137633

    diff --git a/pkg/api/testing/conversion_test.go b/pkg/api/testing/conversion_test.go
    index 9edc44c64e1..9c5d698b027 100644
    --- a/pkg/api/testing/conversion_test.go
    +++ b/pkg/api/testing/conversion_test.go
    @@ -242,6 +242,16 @@ func TestMemoryIdenticalConversion(t *testing.T) {
     		"Scale.apps",
     		"Scale.extensions",
     
    +		// These types are not considered memory-identical right now by conversion-gen, although they are,
    +		// as we need to define Convert_v1_ConditionsAwareDecision_To_authorization_ConditionsAwareDecision (and vice versa)
    +		// function to make ConditionsAwareDecision possible to vendor.
    +		// TODO: Remove this when https://github.com/kubernetes/kubernetes/issues/142345 is fixed
    +		"SubjectAccessReview.authorization.k8s.io",
    +		"SelfSubjectAccessReview.authorization.k8s.io",
    +		"LocalSubjectAccessReview.authorization.k8s.io",
  8. sarooshmehboob commented on Oct 21, 2026

    @sarooshmehboob

    /unassign

  9. liggitt commented on Oct 21, 2026

    @liggitt
    Member

    cc @jpbetz @yongruilin for visibility ... this is making conversion take expensive paths instead of cheap cast paths for things which are actually memory equivalent

  10. yashaggarwal85d commented on Oct 24, 2026

    @yashaggarwal85d

    /assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/bugCategorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions