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

未关闭
#810 9 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
go
领域
tooling

调研方向

首先跟踪 issue 中显示的 conversion-gen 输出,以及转换机制所使用的 conversion.Scope 实现。然后检查 ConvertTo 和 ConvertFrom 实现应如何访问 Scope,同时检查 code-generator issue 94 中描述的限制。当确定了一种受支持的方式来使用需要 Scope 的生成转换,或记录不存在此类路径时,即可视为完成。

由索引模型根据 Issue 内容生成。

描述

help wanted lifecycle/frozen priority/awaiting-more-evidence

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 https://github.com/kubernetes/code-generator/issues/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?

主要语言
Go
星标
3k
派生
1.3k
平均合并
1 天 7 小时
30 天内合并 PR
48

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kubernetes-sigs/controller-runtime 的其他 Issue

查看 kubernetes-sigs/controller-runtime 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。