英文:
kubebuilder create webhook requires a previously created API
问题
我正在尝试创建一个验证的 webhook。
kubebuilder create webhook batch \
--version v1 \
--kind Webhook \
--defaulting \
--programmatic-validation
但是它总是给我一个错误。
failed to create webhook: unable to inject the resource to.
"base.go.kubebuilder.io/v3": kubebuilder create webhook requires.
a previously created API
我不确定在 kubebuilder 命令中需要添加什么额外的内容。任何帮助都将不胜感激。
英文:
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.
答案1
得分: 5
我刚遇到了同样的问题,似乎kubebuilder会查看项目根目录下的一个名为PROJECT
的文件来验证API是否已创建。因此,在创建默认webhook之前,请确保已创建API。我很难解释清楚,但我认为一些示例会更清楚。
所以,在你的项目根目录下运行以下命令:
$ cat PROJECT
它会显示如下内容:
domain: example.org
layout:
- go.kubebuilder.io/v3
projectName: khello
repo: example.com/khello
version: "3"
现在,如果我们运行你的命令:
kubebuilder create webhook batch \
--version v1 \
--kind Webhook \
--defaulting \
--programmatic-validation
它会报错并显示类似以下内容:
....
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
好的,现在我们处于相同的状态,接下来怎么办?
现在,如果你还没有创建API,请使用以下命令创建一个:
kubebuilder create api --version v1 --kind Webhook
现在,如果你注意到项目目录下有一个名为PROJECT
的文件,它会显示类似以下内容:
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"
现在我们已经创建了API,可以运行你的命令了:
kubebuilder create webhook batch \
--version v1 \
--kind Webhook \
--defaulting \
--programmatic-validation
太棒了,现在它可以正常工作了。
PROJECT
文件将变成以下内容:
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"
话虽如此,我不确定kubebuilder在内部是如何工作的,但据我了解,每当发生create
命令时,它会检查PROJECT
中是否已创建了某些内容。因此,我的建议是检查你的PROJECT
文件,确保已创建API,并确保在kubebuilder create webhook
命令中使用正确的参数以匹配PROJECT
文件的内容。
英文:
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.
答案2
得分: 0
新手提示:--group
和 --version
的值必须与“创建 API 时使用的 --group
和 --version
的值完全相同”。
英文:
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".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论