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

Allow to use the code-gen in vendorless projects #163

Open
Tracked by #134
cardil opened this issue Sep 1, 2023 · 7 comments · May be fixed by kubernetes/kubernetes#122236
Open
Tracked by #134

Allow to use the code-gen in vendorless projects #163

cardil opened this issue Sep 1, 2023 · 7 comments · May be fixed by kubernetes/kubernetes#122236
Assignees

Comments

@cardil
Copy link

cardil commented Sep 1, 2023

Background

At Knative project, we would like to get rid of the vendor directory (see knative/infra#134 for details). One of the things that block that is the extensive use of the Kubernetes code-generator, to be exact, the generate-groups.sh shell script.

Recently, the shell code in the Kubernetes has been rewritten a bit in the right direction (kubernetes/kubernetes#117262).

However, it still depends on the non-go shell scripts as the entry points, thus still requiring the use of vendor in the code. The usage of shell scripts isn't cross-platform.

Expected behavior

The Kubernetes code-gen should allow projects to leverage the go run ... syntax. With it, projects could use the code-gen even without any connection to Kuberentes code:

$ go run k8s.io/code-generator@v0.28.1 deepcopy \
  knative.dev/pkg/client knative.dev/pkg/apis \
  'duck:v1alpha1,v1beta1,v1' \
  --go-header-file "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt"

Or by managing the code-gen version in the project's go.mod file:

module knative.dev/serving

go 1.20

require (
	k8s.io/code-generator v0.28.1
)

and then running withing that project (notice the lack of the package version):

$ go run k8s.io/code-generator deepcopy \
  knative.dev/pkg/client knative.dev/pkg/apis \
  'duck:v1alpha1,v1beta1,v1' \
  --go-header-file "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt"

Ideas

Refactor into an entry point binary.

The K8s code-gen already has multiple binaries in the cmd/ directory, but we could add the entry point code-gen binary there, that will directly support the same arguments as the current kube_codegen.sh script. This approach is cross-platform.

Embed the shell script in Go

An easier solution would be to use an approach similar to knative/hack#222, so embedding the shell scripts into Go code (with //go:embed feature), and extracting it into some tmp/ directory.

@cardil
Copy link
Author

cardil commented Nov 30, 2023

/assign

@dprotaso
Copy link

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 28, 2024
@cardil
Copy link
Author

cardil commented Mar 7, 2024

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 7, 2024
@thockin
Copy link
Member

thockin commented Mar 12, 2024

Now that Go workspaces has landed in k/k, two things are changed:

  1. you can run the individual k/code-generator/cmd/* tools with go run
  2. their CLIs are improved so we don't need weird arguments and path manipulation

I'd prefer we obviate kube_codegen.sh rather than rewrite it. There are a few things that the kube_codegen.sh does that you would need to change to run the tools yourself. It does questionable grep to find files and then nukes them. If you know exactly which files/directories are in play, you can do that yourself.

@dprotaso
Copy link

thanks @thockin awesome work

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 a pull request may close this issue.

5 participants