-
Notifications
You must be signed in to change notification settings - Fork 432
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
controller-gen
Does Not Respect GOFLAGS
(-tags
) During Build
#1158
Comments
Which build? :) |
Hi @sbueringer The issue arises when working with Go Build Cache Optimization (GCO) enabled, where the For example, when running:
This issue occurs because To resolve this, I need to pass a specific build tag ( golangci-lint run --build-tags $(GO_BUILD_TAGS) Expected Behavior:
Let me know if any additional clarification is needed! |
Thx for the context. If someone has an idea on how to fix it, feel free to open a PR |
@sbueringer I think the way to fix it would be to pass configuration to LoadRootsWithConfig by modifying
Alternatives might be to consider GOFLAGS or take input from some env var like GO_BUILD_TAGS. But these options might have a large blast radius or sudden onset of unexpected behavior in some projects. |
I think at this point of the project it would make sense that folks have to explicitly opt-in. Regarding the exact way to do that, would be good in general to be consistent with how similar tools are doing that. @JoelSpeed opinions from your side? |
Agreed
As far as I can tell, you'd have exactly the same issue with any Gengo based generator. The Parser loads with build tags passed into it based on this configuration. But if you check the way this is done in, for example, deepcopy-gen they just pass the standard We may want to raise the issue with the gengo folks and get their opinion as well I could see us following a |
Hi @JoelSpeed That should occur with all. :(
In our case, we found two possible workarounds to overcome this issue:
What about we just ensure that controller-gen supports GOFLAGS? Or if we do not use the GOFLAGS, allow the user to explicitly say it for controller-gen via a specific ENV VAR like This would allow users to dynamically pass build tags like // Default build tags
buildTags := []string{"ignore_autogenerated"}
// Read GOFLAGS for additional tags
if goFlags := os.Getenv("GOFLAGS"); goFlags != "" {
for _, flag := range strings.Fields(goFlags) {
if strings.HasPrefix(flag, "-tags=") {
// Extract and append custom tags
tags := strings.TrimPrefix(flag, "-tags=")
buildTags = append(buildTags, strings.Split(tags, ",")...)
}
}
}
// Add "-tags" argument to BuildFlags
l.cfg.BuildFlags = append(l.cfg.BuildFlags, "-tags", strings.Join(buildTags, ",")) |
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.33.1 to 5.34.0. - [Release notes](https://github.com/containers/image/releases) - [Commits](containers/[email protected]) --- updated-dependencies: - dependency-name: github.com/containers/image/v5 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> And downgrade : replace github.com/proglottis/gpgme => github.com/proglottis/gpgme v0.1.3 Due: kubernetes-sigs/controller-tools#1158 Upgrade with Signed-off-by: Joe Lanford <[email protected]>
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.33.1 to 5.34.0. - [Release notes](https://github.com/containers/image/releases) - [Commits](containers/[email protected]) --- updated-dependencies: - dependency-name: github.com/containers/image/v5 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> And downgrade : replace github.com/proglottis/gpgme => github.com/proglottis/gpgme v0.1.3 Due: kubernetes-sigs/controller-tools#1158 Upgrade with Signed-off-by: Joe Lanford <[email protected]>
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.33.1 to 5.34.0. - [Release notes](https://github.com/containers/image/releases) - [Commits](containers/[email protected]) --- updated-dependencies: - dependency-name: github.com/containers/image/v5 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> And downgrade : replace github.com/proglottis/gpgme => github.com/proglottis/gpgme v0.1.3 Due: kubernetes-sigs/controller-tools#1158 Upgrade with Signed-off-by: Joe Lanford <[email protected]>
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.33.1 to 5.34.0. - [Release notes](https://github.com/containers/image/releases) - [Commits](containers/[email protected]) --- updated-dependencies: - dependency-name: github.com/containers/image/v5 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> And downgrade : replace github.com/proglottis/gpgme => github.com/proglottis/gpgme v0.1.3 Due: kubernetes-sigs/controller-tools#1158 Co-Author: Joe Lanford <[email protected]>
My first instinct if we want to preserve existing functionality would be to add a Would we want it to be a global setting, or something passed individually to each generator? My feeling there is to make it a global setting only, which seems like it would cover basically all of the uses cases of this, especially given that controller-gen has been around for years with no one running into build tags issues before. And if it turns out that we are asked to support per-generator build tags, that's always something that could be considered later. |
@tmshort and I put each put together PRs that add support in two different ways.
Opinions? |
I'm leaning towards a flagged approach. Using a marker has the issue that the marker could itself, be excluded from the build process by virtue of being within a file that has a particular build tag, right? IIUC, we have to parse the environment first to find the files marked, and then re-parse to load the correct build tags? Does the default parse include all files, or only those without build tags? If we were generating multiple different versions (which is the common use of build tags right?), I'm not sure how I would be able to say "generate this version and then generate this version" when the input is a file within the code being generated, where I could easily see how to vary the flag inputs |
@JoelSpeed I might be misunderstanding Todd's PR, but I think So with my PR, one would invoke this way:
And Todd's PR, one would invoke something like this (@tmshort, correct me if I got the syntax wrong):
|
@joelanford's invocation is correct, although there can be multiple buildTags supported:
Yes, code refers to these things as "markers", and are registered (code-wise) in the same way, AFAICT. But it's probably best to think of it as a generic option closer to the |
controller-gen
currently does not respect/support Go build tags (-tags
) passed via theGOFLAGS
environment variable. This creates issues when working with code that relies on build constraints.When trying to build using:
For example, the tags provided are not passed to the build.
Therefore, failures might occur for projects that rely on C-based packages.
Expected Behavior
controller-gen
should respect theGOFLAGS
environment variable.Also, it seems related to: #871
The text was updated successfully, but these errors were encountered: