-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
conversion-gen is broken in 1.20 and 1.21 release #101567
Comments
/sig api-machinery |
cc @wojtek-t likely related to #90018 in 1.19, which intentionally removed the fallback to reflect-based conversion, because it is not known to be correct and masks conversion bugs based on what was generated previously, is it possible you weren't actually picking up the generated conversions before and were using the reflective conversion path? |
Yes. It was using reflective conversions. As you can see here with k8s 1.18.9 |
/cc @sttts since we assigned the PR to Stefan. Thanks! |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closing this issue. In response to this:
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/test-infra repository. |
/reopen |
@sozercan: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
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/test-infra repository. |
What happened:
conversion-gen tool is broken in 1.20 and 1.21 release. This is blocking us and projects like cert-manager from migrating to the latest k8s tool chain.
As for context, everything was ok in k8s 1.18. In k8s 1.18.9, the auto generated code will look like the following:
In k8s 1.20 and 1.21, the auto generated code look like the following:
This is obviously incorrect, since the k8s.io/apiextensions-apiserver package does have an auto generated conversion for these types:
Now, digging into the code of
conversion-gen
I see that the only wayconversion-gen
tool can know about the existence of this method will be that it can be found in themanual_conversions
map.ref: https://github.com/kubernetes/code-generator/blob/v0.21.0/cmd/conversion-gen/generators/conversion.go#L1053-L1078
First I thought that I needed to pass the
--extra-dirs k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
flag toconversion-gen
tool so that those files are parsed for conversion methods. But that did not fix it.Now, further digging I found that the reason the auto-generated
https://github.com/kubernetes/apiextensions-apiserver/blob/master/pkg/apis/apiextensions/v1/zz_generated.conversion.go
file is not parsed by the GoBuilder
inconversion-gen
tool because the auto generated file has the build tag// +build !ignore_autogenerated
and the Go source parser is configured withignore_autogenerated
build tag.ref: https://github.com/kubernetes/gengo/blob/master/args/args.go#L132-L138
As a result, the auto generated (files with zz_ prefix) are never parsed and we get that
compileErrorOnMissingConversion()
error.Proposed Solution:
In my view, the main problem here is that the same variable
g.GeneratedBuildTag
variable is used to add the build tag to the generated zz_conversion.go file and to parse existing auto generated conversion files. So, I was able to get this fixed using the following approach:(1) Use separate flags for adding build tag to the generated conversion file and for importing/parsing existing generated conversion files. Here is my pr: kubernetes/gengo#200
I initialize them to the same default value so that the behavior of the code generators other than
conversion-gen
remains unchanged. But I also added a new--import-tag
flag for the newImportBuildTag
.(2) Now, in the
conversion-gen
code, I set theImportBuildTag
to empty string so that by default it parses all the generated conversion functions from the--extra-dirs
and--peer-dirs
.pr: #101568
If users need old behavior for some reason, they can set the
--import-tag=ignore_autogenerated
to avoid parsing the existing generated conversion files.Testing Fix
If you want to test the fix, you need to use my forked
conversion-gen
binary.What you expected to happen:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
Environment:
kubectl version
):cat /etc/os-release
):uname -a
):The text was updated successfully, but these errors were encountered: