简体   繁体   English

kubebuilder create webhook 需要先前创建的 API

[英]kubebuilder create webhook requires a previously created API

I'm trying to create a validating webhook我正在尝试创建一个验证 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.而且我不确定要在 kubebuilder 命令中添加什么。 Any help is appreciated.任何帮助表示赞赏。

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.我刚遇到同样的问题,似乎 kubebuilder 查看PROJECT根目录下名为PROJECT的文件以验证 API 是否已创建。 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所以在你创建默认的 webhook 之前,确保你在创建 webhook 之前已经创建了 API,我很难解释这一点,但我认为一些例子会说清楚

so at root of your project, if you run $ cat PROJECT it will look someting like this所以在你的项目的根目录,如果你运行$ cat PROJECT它看起来像这样

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现在,如果您还没有创建 API,请使用

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现在,如果您注意到项目目录的根目录中有一个名为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"

now that we have created the api, we can run your command现在我们已经创建了 api,我们可以运行你的命令

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

voila, it works now瞧,现在可以用了

and the PROJECT file will become something like并且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"

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.话虽如此,我不确定 kubebuilder 是如何在后台工作的,但据我所知,无论何时发生create命令,它都会检查是否从该PROJECT创建了某些内容。 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.因此,我的建议是检查您的PROJECT文件,确保 API 已创建,如果已创建,请确保在kubebuilder create weboook命令中放置正确的参数以匹配 thta PROJECT文件的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM