Skip to content

[kubebuilder] sh: controller-gen: command not found #645

@katt-999

Description

@katt-999

Hello,

While using kubebuilder extension, I've encountered that issue :

local: which kubebuilder
 → /opt/homebrew/bin/kubebuilder
kubebuilder is present: /opt/homebrew/bin/kubebuilder

local: controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases;controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./...";
 → sh: controller-gen: command not found
 → sh: controller-gen: command not found
Traceback (most recent call last):
  /Users/<anon-data>/development/kubernetes/<anon-data>/test-operator/Tiltfile:91:12: in <toplevel>
  /Users/<anon-data>/Library/Application Support/tilt-dev/tilt_modules/github.com/tilt-dev/tilt-extensions/kubebuilder/Tiltfile:55:10: in kubebuilder
Error in local: command "controller-gen rbac:roleName=manager-role crd webhook paths=\"./...\" output:crd:artifacts:config=config/crd/bases;controller-gen object:headerFile=\"hack/boilerplate.go.txt\" paths=\"./...\";" failed.
error: exit status 127

On my side, the problem come from the controller-gen binary is in current_path/bin :

On kubebuilder tiltfile, we can see controller-gen is invoked directly.

    def manifests():
        return 'controller-gen ' + CONTROLLERGEN

    def generate():
        return 'controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./...";'

I tried this and it worked :

    def manifests():
        return 'bin/controller-gen ' + CONTROLLERGEN

    def generate():
        return 'bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./...";'

I don't know if that behaviour is specific to my environment, but maybe it can be great to if needed to specify the controller-gen binary path like :

def kubebuilder(DOMAIN, GROUP, VERSION, KIND, IMG='controller:latest', CONTROLLERGEN='rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases;', DISABLE_SECURITY_CONTEXT=True, BIN_PATH=""):
...
    def manifests():
        return os.path.join(BIN_PATH, 'controller-gen ') + CONTROLLERGEN

    def generate():
        return os.path.join(BIN_PATH, 'controller-gen ') + 'object:headerFile="hack/boilerplate.go.txt" paths="./...";'
...   

So we can invoked kubebuilder like this and work like a charm 💫 :

kubebuilder('netbox.airnity.io', 'extras', 'v1alpha1', 'CustomField', BIN_PATH="bin/") 

Also, I don't work with kubebuilder directly, but with operator-sdk, maybe that plugin can also have a compability by using 'operator-sdk' commands instead of 'kubebuilder' (args seems the same)

Cheers,
Guillaume

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions