-
Notifications
You must be signed in to change notification settings - Fork 196
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
Spawn gengo/v2 (KEP 4402) #259
Conversation
v2/args/args.go
Outdated
@@ -137,7 +137,7 @@ func (g *GeneratorArgs) NewBuilder() (*parser.Builder, error) { | |||
// Execute implements main(). | |||
// If you don't need any non-default behavior, use as: | |||
// args.Default().Execute(...) | |||
func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, pkgs func(*generator.Context, *GeneratorArgs) []generator.Package) error { | |||
func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, getTargets func(*generator.Context, *GeneratorArgs) []generator.Target) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the goal is to distinguish input and output packages, how about making that explicit in the type names? InputPackage
/ OutputPackage
, or InPackage
/ OutPackage
, or InputPkg
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unclear what you are proposing? Can you offer a diff or be more precise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was reviewing this in the context of da029b0 — the commit message says
Having two types names "Package" was super confusing to read. I don't love "Target" but at least it implies "this is the output" rather than the input.
Since the use of Package
is ambiguous, it seems to me that a possible solution would be to disambiguate both uses cases instead of using a not-great replacement for the output scenario; InputPackage
/ OutputPackage
for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. I was shooting for something shortish rather than renaming types.Package
at this time. In truth, I rather hate the way gengo has its own Package
type with (IMO) dangerous lazy-load semantics and how it interposes its own Type
and Kind
types with different semantics from Go. I'd like to see use eliminate all of that, but it wasn't necessary to this PR and I really want to get workspaces support into k/k (which is blocked on this :)
So - we could totally do a followup to rename things more :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s fine by me!
Fixed minor feedback (thanks!) |
} | ||
} | ||
return out | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexzielenski Just wanted you to be aware this is here. I don't know if we'll need to follow up later to somehow reconcile this with kubernetes/kube-openapi#446
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we will since a key difference between the two is the kube-openapi version does not allow implicit arrays by duplicating markers which I dont think would be backwards compatible if we merged the two (unless it was a parser optoin or something, but at that rate they could be kept separate I think)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have one convention that applied to all tools. FWIW I didn't change this logic, just copied it over. :)
@@ -0,0 +1,54 @@ | |||
#!/usr/bin/env bash | |||
|
|||
# hack/verify-examples.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking ahead for a moment..
We should tool our testing infra to run v2/hack/verify-examples.sh? We could run it from the root hack/verify-examples.sh
but that running it separately will probably result in clearer error reporting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Should we move this to github actions or keep the config in https://github.com/kubernetes/test-infra/tree/a446b9e441a3b25166a8084f32f5ae16ac76a208/config/jobs/kubernetes/gengo ?
} | ||
} | ||
return out | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we will since a key difference between the two is the kube-openapi version does not allow implicit arrays by duplicating markers which I dont think would be backwards compatible if we merged the two (unless it was a parser optoin or something, but at that rate they could be kept separate I think)
func (g *pointuhGenerator) Namers(*generator.Context) namer.NameSystems { | ||
return namer.NameSystems{ | ||
// This elides package names when the name is in "this" package. | ||
"localraw": namer.NewRawNamer(g.myPackage.Path, nil), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this pattern in a few examples. Is this something that could make a sensible default? I feel like the local-aware namer and per-target import trackers are something consumers of this library wouldnt mind being plumbed for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think we could simplify how namers work more - I didn't cover it in this PR because it was already too big.
pushed with some comments addressed |
OK. KEPs are done. I know this will take time, so I'm sending my first ping for review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I think we all agree on general approach of introducing gengo/v2. I can't find anything blocking on the few passes I've made. Since this is net-new change, with working prototypes and no comments for a while, should we merge this and fix any issues that come up as we use it?
// this is a relative dir, which will not work under gomodules. | ||
// join with the local package path, but warn | ||
klog.Warningf("relative path %s=%s will not work under gomodule mode; use full package path (as used by 'import') instead", inputTagName, inputPath) | ||
inputPath = filepath.Join(pkg.Path, inputTags[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is filepath correct if we're constructing a package path? should we be using path.Join since import paths always use /
?
edit: I see this got moved to k/k, will ask there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting distinction I didn't consider. It's become habit to always use filepath
. I'm not sure these tools run on Windows to know if this breaks or if path
is better.
if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok { | ||
for _, pkg := range customArgs.ExtraPeerDirs { | ||
if i := strings.Index(pkg, "/vendor/"); i != -1 { | ||
pkg = pkg[i+len("/vendor/"):] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means they're giving file paths, not import paths, right? should we warn about this now as well if it is no longer necessary?
edit: I see this got moved to k/k, will ask there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To hit this they would have to have said ./vendor/example.com/project
and I think that packages.Load
would still DTRT.
Why? - It's not a great "example". - It doesn't really need gengo at all (in fact, it is retooled in k/k PR to not use gengo) - k8s.io/code-generator has an alternate `main()` anyway
Support for tests in x/tools/go/packages is pretty hostile to gengo, and nobody uses it any more. This also allows us to delete the "incoming imports" logic.
Each tool has its own Args type, now - there are no "standard" arguments.
Now callers can just say `gengo.Execute`
It served its purpose and is now just noise.
Pushed with comments addressed (mostly new commits, but some fixed in-line). |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
It's easier for me to merge this and then fix any ripple into the k/k and openapi PRs |
First: This PR can be broken up!
See kubernetes/enhancements#4402
This clones gengo into gengo/v2 and overhauls it to use Go's
packages.Load()
instead of DIY. It includes a number of refactorings and simplifcations, too, which really warrant being "v2".The "examples" (which were actually prod tools) get moved to k/k and replaced with simpler examples.
The commits in this PR were adapted from kubernetes/kubernetes#122624
I have tried to make sure test coverage did not drop and that tests pass at every commit.