Reputation: 127
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.
Upvotes: 7
Views: 3454
Reputation: 69
Tips for rookies: The --group
and --version
values must be exactly the same as "the --group
and --version
values when you used to create your api".
Upvotes: 2
Reputation: 481
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.
Upvotes: 6