Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubebuilder create webhook requires a previously created API

I'm trying to create a validating webhook

kubebuilder create webhook batch \
            --version v1 \
            --kind Webhook \
            --defaulting \
            --programmatic-validation

but it always gives me an error.

failed to create webhook: unable to inject the resource to. 
"base.go.kubebuilder.io/v3": kubebuilder create webhook requires. 
a previously created API

and i'm not sure what to add extra in the kubebuilder command. Any help is appreciated.

like image 332
alok verma Avatar asked Jul 31 '26 00:07

alok verma


1 Answers

I just got the same problem, seems like kubebuilder look at a file called PROJECT at the root of your project to validate whether the API has been created or not. So before you create the defaulting webhook, make sure you have created the API before you create the webhook, I'm having a hard time explaining this but I think some example will make it clear

so at root of your project, if you run $ cat PROJECT it will look someting like this

domain: example.org
layout:
- go.kubebuilder.io/v3
projectName: khello
repo: example.com/khello
version: "3"

now if we run your command

kubebuilder create webhook batch \
            --version v1 \
            --kind Webhook \
            --defaulting \
            --programmatic-validation

it will complains and says something like

....
2021/11/17 13:15:03 failed to create webhook: unable to inject the resource to "base.go.kubebuilder.io/v3": kubebuilder create webhook requires a previously created API

ok cool, now we're at the same state, now what?

now, if you haven't create the API, do one make one with

kubebuilder create api  --version v1 --kind Webhook

now if you notice a file with the name PROJECT at the root of your project dir, it will says something like

domain: example.org
layout:
- go.kubebuilder.io/v3
projectName: khello
repo: example.com/khello
resources:
- api:
    crdVersion: v1
    namespaced: true
  controller: true
  domain: example.org
  kind: Webhook
  path: example.com/khello/api/v1
  version: v1
version: "3"

now that we have created the api, we can run your command

kubebuilder create webhook batch \
            --version v1 \
            --kind Webhook \
            --defaulting \
            --programmatic-validation

voila, it works now

and the PROJECT file will become something like

domain: example.org
layout:
- go.kubebuilder.io/v3
projectName: khello
repo: example.com/khello
resources:
- api:
    crdVersion: v1
    namespaced: true
  controller: true
  domain: example.org
  kind: Webhook
  path: example.com/khello/api/v1
  version: v1
  webhooks:
    defaulting: true
    validation: true
    webhookVersion: v1
version: "3"

with that being said, I'm not sure how kubebuilder works under the hood, but from what I understand it check whether something is created from that PROJECT whenever the create command happens. So, my suggestion would be check your PROJECT file, make sure the API is created and if it does, make sure you put the right parameter in your kubebuilder create weboook command to match the contents of thta PROJECT file.

like image 121
ThatBuffDude Avatar answered Aug 02 '26 17:08

ThatBuffDude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!