Skip to content

Unable to conversion-gen conversions that require a conversion.Scope #810

Open
@ncdc

Description

@ncdc

Some functions autogenerated by conversion-gen produce code that looks like this:

func autoConvert_v1alpha1_Something_To_v1alpha2_Something(in *Something, out *v1alpha2.Something, s conversion.Scope) error {
  // normal convertible fields
  out.X = in.X
  // TODO: Inefficient conversion - can we improve it?
  if err := s.Convert(&in.SomeField, &out.SomeField, 0); err != nil {
    return err
  }
  return nil
}

The "inefficient conversion" can happen in a few different situations; in this case, it's because SomeField is a struct that lives in a package outside of the one where I'm generating conversions. Due to kubernetes/code-generator#94 (assuming there isn't a workaround), even if there were conversion functions for SomeField, conversion-gen isn't able to see & use them.

We presumably need access to a conversion.Scope in our ConvertTo/ConvertFrom implementations, but these are member functions on the types, and I haven't yet found any way to get access to a Scope (this appears to have a single, unexported implementation that is used internally by the conversion machinery code).

Anyone know of a way to use generated conversion functions that need a Scope?

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.priority/awaiting-more-evidenceLowest priority. Possibly useful, but not yet enough support to actually get it done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions