Skip to content

kubebuilder alpha generate calls kubebuilder cmd from path instead of it's own #4900

@bavarianbidi

Description

@bavarianbidi

What broke? What's expected?

When running kubebuilder alpha generate, the generate-subcommand is directly invoking the kubebuilder binary in the current working directory.

This might lead to a failed execution in two different ways:

  • your kubebuilder binary is not in PATH and you want to run the binary from somewhere else
$ /tmp/kubebuilder alpha generate
Error: kubebuilder not found in the path: exec: "kubebuilder": executable file not found in $PATH
Usage:
  kubebuilder alpha generate [flags]

Flags:
  -h, --help                help for generate
      --input-dir string    Specifies the full path to a Kubebuilder project file. If not provided, the current working directory is used.
      --output-dir string   Specifies the full path where the scaffolded files will be output. Defaults to a directory within the current working directory.

Global Flags:
      --plugins strings   plugin keys to be used for this subcommand execution

FATA error executing command: kubebuilder not found in the path: exec: "kubebuilder": executable file not found in $PATH 
  • the version of kubebuilder in PATH is an older one where kubebuilder alpha generate is getting called (where e.g. not all plugins already exist - e.g. the newly introduced helm plugin)

Within alpha generate there is a check to verify if kubebuilder is in PATH:
exec.LookPath func from

_, err = exec.LookPath("kubebuilder")

and than kubebuilder is getting called via RunCmd("kubebuilder:
https://github.com/search?q=repo%3Akubernetes-sigs%2Fkubebuilder+util.RunCmd%28%22kubebuilder+path%3Apkg%2Fcli%2Falpha%2Finternal%2F*&type=code

additional notes:
at least for Linux it could get solved by using the value of the _ environment variable (e.g.: os.Getenv("_") )

Reproducing this issue

  1. ensure kubebuilder is not in your PATH
  2. move kubebuilder binary to e.g. /tmp
  3. change your working dir to an existing kubebuilder generated directory
  4. run /tmp/kubebuilder alpha generate

KubeBuilder (CLI) Version

4.6.0

PROJECT version

3

Plugin versions

Other versions

No response

Extra Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions