Skip to content
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

Merged
merged 60 commits into from
Feb 25, 2024
Merged

Spawn gengo/v2 (KEP 4402) #259

merged 60 commits into from
Feb 25, 2024

Conversation

thockin
Copy link
Member

@thockin thockin commented Jan 28, 2024

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.

v2/generator/execute.go Outdated Show resolved Hide resolved
v2/generator/execute.go Outdated Show resolved Hide resolved
v2/parser/parse.go Outdated Show resolved Hide resolved
v2/parser/parse.go Outdated Show resolved Hide resolved
v2/generator/execute.go Outdated Show resolved Hide resolved
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 {
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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 :)

Copy link
Member

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!

@thockin
Copy link
Member Author

thockin commented Jan 29, 2024

Fixed minor feedback (thanks!)

}
}
return out
}
Copy link
Contributor

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

Copy link
Contributor

@alexzielenski alexzielenski Jan 31, 2024

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)

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

@thockin thockin Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2/README.md Show resolved Hide resolved
v2/README.md Show resolved Hide resolved
v2/generator/simple_package.go Outdated Show resolved Hide resolved
}
}
return out
}
Copy link
Contributor

@alexzielenski alexzielenski Jan 31, 2024

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)

v2/README.md Show resolved Hide resolved
v2/generator/import_tracker.go Show resolved Hide resolved
v2/examples/kilroy/main.go Show resolved Hide resolved
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),
Copy link
Contributor

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?

Copy link
Member Author

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.

@thockin
Copy link
Member Author

thockin commented Jan 31, 2024

pushed with some comments addressed

@thockin
Copy link
Member Author

thockin commented Feb 16, 2024

OK. KEPs are done. I know this will take time, so I'm sending my first ping for review :)

Copy link
Contributor

@alexzielenski alexzielenski left a 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?

v2/examples/deepcopy-gen/generators/deepcopy.go Outdated Show resolved Hide resolved
v2/examples/deepcopy-gen/generators/deepcopy.go Outdated Show resolved Hide resolved
v2/hack/verify-examples.sh Show resolved Hide resolved
// 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])
Copy link
Member

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

Copy link
Member Author

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/"):]
Copy link
Member

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

Copy link
Member Author

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.

README.md Outdated Show resolved Hide resolved
v2/examples/pointuh/main.go Outdated Show resolved Hide resolved
v2/args/args.go Outdated Show resolved Hide resolved
v2/examples/deepcopy-gen/generators/deepcopy.go Outdated Show resolved Hide resolved
v2/parser/parse.go Outdated Show resolved Hide resolved
v2/generator/simple_target.go Show resolved Hide resolved
@thockin
Copy link
Member Author

thockin commented Feb 24, 2024

Pushed with comments addressed (mostly new commits, but some fixed in-line).

https://github.com/kubernetes/gengo/compare/071b86b8ca2508407c999f2a488d017915f2c707..e7d5fc5e02f813189a58e771fa753b85f21b3de9

@liggitt
Copy link
Member

liggitt commented Feb 24, 2024

/lgtm
/hold until this is pulled into the k/k PR and we're happy with the two generators moved there on top of this latest content

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Feb 24, 2024
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@thockin
Copy link
Member Author

thockin commented Feb 25, 2024

It's easier for me to merge this and then fix any ripple into the k/k and openapi PRs

@thockin thockin removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 25, 2024
@k8s-ci-robot k8s-ci-robot merged commit 471f57d into kubernetes:master Feb 25, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants