kubernetes / code-generator

Generators for kube-like API types
Apache License 2.0
1.72k stars 416 forks source link

kube::codegen::gen_helpers errors out with 'fatal: Invalid path' error #159

Closed HendrikLeier closed 8 months ago

HendrikLeier commented 1 year ago

When I run the following code:

source kube_codegen.sh

kube::codegen::gen_helpers \
    --input-pkg-root <repo_name>/pkg/apis \
    --output-base "<base_directory>" \
    --boilerplate "./examples/hack/boilerplate.go.txt"

I get the following error:

fatal: Invalid path '//pkg/apis/**': No such file or directory

I made sure that the directory exists and contains files that are annotated with // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

I tried crafting the git grep by hand. That worked, it might be something in the way of how you call git grep.

I tried varying the path but that didn't do anything.

I am running in a docker container on golang:1.20.4-buster git version is 2.20.1

Am I doing something wrong or is this a bug?

oleksii-donoha commented 1 year ago

I believe I've figured it out. It's all in the paths. You can use the sample controller as an example.

By digging around this part of the script you will realize that the path where the codegen will run depends on the parameters you set as --input-pkg-root, --output-base.

Long story short:

  1. Assuming you cloned into the home directory, your directory structure should be like this: ${HOME}/${GO_PACKAGE_NAME}. So if your package is github.com/foo/bar, then the path should be /home/${USER}/github.com/foo/bar
  2. The original script assumes that the package name has 2 parts divided by /, i.e. k8s.io/sample-controller. If your package (most likely) is called github.com/foo/bar, then the package name has 3 parts. This means you need to add one more .. to your output base: --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." -> "$(dirname "${BASH_SOURCE[0]}")/../../../.."

You can of course completely override the out base, but the path should still contain the github path.

k8s-triage-robot commented 9 months ago

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

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

You can:

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

/lifecycle stale

k8s-triage-robot commented 8 months ago

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

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

You can:

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

/lifecycle rotten

thockin commented 8 months ago

Most of the path weirdness is now fixed.

/close

k8s-ci-robot commented 8 months ago

@thockin: Closing this issue.

In response to [this](https://github.com/kubernetes/code-generator/issues/159#issuecomment-1992556783): >Most of the path weirdness is now fixed. > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.