Skip to content

K8s 1.30 #425

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

Merged
merged 8 commits into from
May 1, 2024
Merged

K8s 1.30 #425

merged 8 commits into from
May 1, 2024

Conversation

tomleb
Copy link
Contributor

@tomleb tomleb commented Apr 30, 2024

Issue rancher/rancher#45324

Wrangler relies on k8s.io/code-generator for some of its generators. Starting with k8s 1.30, these generators have been migrated, in a backward incompatible way, from k8s.io/gengo to k8s.io/gengo/v2. We must adapt the code with the new major version of gengo.

Changes in gengo/v2

GeneratorArgs

One major change in the API is that before, you had to create a GeneratorArgs. It contained information such as: InputDirs to point to directories that need codegen, OutputBase to specify a directory tree to write file to, CustomArgs for generator-specific information.

This struct is no longer used in gengo/v2, and instead is replaced in the following way:

  • InputDirs: This is now provided in a new argument to the Execute function.

  • OutputBase: Generators would compute "output file = <output base>/<package>/..." to know which directory the generated file needs to be in. By convention, generators now expects an absolute path to the destination directory. For example:

-	args.OutputPackagePath = filepath.Join(customArgs.Package, "clientset")
+	clientSetArgs.OutputDir = filepath.Join(customArgs.OutputBase, customArgs.Package, "clientset")
  • CustomArgs: Custom args aren't part of the API anymore. If the Target/Generator needs custom arguments, you must find another way of passing it to it. By convention it's done by having a GetTarget function that accepts such an argument, and wrapping it by a function that doesn't accept it. Here's an example:
-	if err := genericArgs.Execute(
-		clientgenerators.NameSystems(nil),
-		clientgenerators.DefaultNameSystem(),
-		clientGen.Packages,
+	getTargets := func(context *generator.Context) []generator.Target {
+		return clientGen.Packages(context, customArgs)
+	}

DefaultGen

generator.DefaultGen is replaced by generator.GoGenerator. The impact is that we must specify .go suffix to all filenames ourselves. This changes the generator name to have this .go suffix, which itself changes some comments in the generated output.

DefaultPackage

generator.DefaultPackage is replaced by generator.SimpleTarget.

Commits

To make it easier to review, I have split the changes in multiple commits. Not every commit is self-contained (so don't try to go build them individually).

1. go-imports

Cherry-picked from #416.

2. Upgrade k8s to v1.30

Bumps the following:

  • k8s.io to v1.30
  • gengo to the same commit used by this kubernetes release.
  • Go to 1.22 (same Go as kubernetes 1.30)
  • Lasso to a version that supports kubernetes 1.30

3. DeepCopy generator

Not much changed here. We're now referencing gengo directly instead of k8s.io/code-generator's newtype We were already using the generator from gengo/v1, which is still available to us.

4. ClientSet generator

Migrates the clientset generator to gengo/v2.

5. Listers generator

Migrates the listers generator to gengo/v2.

6. Informers generator

Migrates the informers generator to gengo/v2.

7. setGenClient middleware

I haven't change the logic of this function. It acts as some kind of middleware. It used to passthrough the arguments to the next function. Since that's no longer part of the gengo/v2 api, we're no longer doing this.

8. Migrate custom generators

As mentioned in the "Changes in gengo/v2" section, generators now embed a generator.GoGenerator instead. Anything referencing Package should now be named Target. For example, I renamed the function Package to Target and it now returns a SimpleTarget.

The boilerplate information is read only once as opposed to be read for every generator. The goal wasn't to optimize, but to avoid passing the GeneratorArgs from gengo/v1.

@tomleb tomleb force-pushed the k8s-1.30 branch 2 times, most recently from 6c5fa27 to 16e53c8 Compare April 30, 2024 17:06
Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

There's one other place that we should update the go version of:

SETUP_GO_VERSION: '^1.21'
. Would be good to give that a look as well.

@tomleb tomleb force-pushed the k8s-1.30 branch 3 times, most recently from 9a06fb0 to 4c6d7f0 Compare May 1, 2024 12:09
@tomleb
Copy link
Contributor Author

tomleb commented May 1, 2024

Recent changes:

  • Rebased from latest wrangler master
  • Pulled in latest lasso with k8s 1.30 support
  • Renamed Boilerplate to BoilerplateContent
  • Updated the Go version in the linting script

@tomleb tomleb requested a review from MbolotSuse May 1, 2024 12:15
@tomleb tomleb marked this pull request as ready for review May 1, 2024 12:25
@tomleb tomleb requested a review from a team as a code owner May 1, 2024 12:25
@tomleb tomleb requested a review from galal-hussein May 1, 2024 12:51
Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

Two comments on how we are structuring the package path.

Copy link
Contributor

@galal-hussein galal-hussein left a comment

Choose a reason for hiding this comment

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

LGTM

@tomleb tomleb merged commit 8886c26 into rancher:master May 1, 2024
1 check passed
@tomleb tomleb deleted the k8s-1.30 branch May 1, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants