kubebuilder
kubebuilder copied to clipboard
`create webhook`: return error when used with a core type
When I run kubebuilder create webhook
on a core type, ex. v1.Pod
, the command attempts to define methods on a non-existent locally-defined type. Instead, the command should return an error explaining that core types are not supported by this command.
$ go version
go version go1.15.2 linux/amd64
$ kubebuilder version
Version: main.version{KubeBuilderVersion:"v3.0.0-alpha.0-195-g37485126", KubernetesVendor:"unknown", GitCommit:"37485126f95ceb2e92a86497c31f400c8b89f957", BuildDate:"2021-04-12T18:30:56Z", GoOs:"linux", GoArch:"amd64"}
$ cat go.mod | grep controller-runtime
sigs.k8s.io/controller-runtime v0.7.2
/kind bug
IHMO, we ought to not create this message and instead of that, we can spend the effort to implementing the RFE: https://github.com/kubernetes-sigs/kubebuilder/issues/1999. (see my comments there )
We can change here: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v3/webhook.go#L107 for:
- If is core type then update the PROJECT file accordingly and scaffold the webhook
- if is external-type (we need a new flag for that) then, do the same.
This solution is more of a holdover until something like what is suggested here is implemented and kustomize-able resources are generated correctly for core/external types.
Alternatively the holdover can be skipped entirely if the Handler
implementation can be completed without an EP, which I think it can.
@kopiczko if you'd like to work on either this and/or implement core/external type support in create webhook
, feel free to assign yourself!
Cool, thanks, I'll look into this and check what I can do in the following days. Possibly starting wit the error message is a good warmup for me.
Hi @estroz,
I was trying to think what would be the good way to fix this and found that doesn't only apply to the core types.
In general:
$ kubebuilder create api --group "mygroup" --version "v1" --kind "MyKind" --controller=true --resource=false
Writing scaffold for you to edit...
controllers/mykind_controller.go
Update dependencies:
$ go mod tidy
$ kubebuilder create webhook --group "mygroup" --version "v1" --kind "MyKind" --defaulting
Writing scaffold for you to edit...
api/v1/mykind_webhook.go
$ tree api
api
└── v1
├── mykind_webhook.go
└── webhook_suite_test.go
1 directory, 2 files
Setting --controller=false
gives the same output. You can replace --group "mygroup"
with --group ""
and the output will be the same.
So I'd say the issue is that webhook methods are generated on non-existent resource in general?
More than an issue, they are a unsupported feature. We only support webhooks for types we have scaffolded ourselves.
Shouldn't generating scaffolding for the resource also be forbidden in kubebuilder create api
?
Theoretically create api
can create a controller for a core type. When I run kubebuilder create api --controller
, I get a controller for no resource, so technically it does work right now. I propose better handling of this situation by accepting some import path that can then be used in a controller in #1999. The --resource
flag should generate an error though.
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Mark this issue or PR as fresh with
/remove-lifecycle rotten
- Close this issue or PR with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Reopen this issue or PR with
/reopen
- Mark this issue or PR as fresh with
/remove-lifecycle rotten
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close
@k8s-triage-robot: Closing this issue.
In response to this:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied- After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied- After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closedYou can:
- Reopen this issue or PR with
/reopen
- Mark this issue or PR as fresh with
/remove-lifecycle rotten
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
/reopen
@kebyn: You can't reopen an issue/PR unless you authored it or you are a collaborator.
In response to this:
/reopen
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
/reopen /lifecycle frozen
@estroz: Reopened this issue.
In response to this:
/reopen /lifecycle frozen
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
This issue has not been updated in over 1 year, and should be re-triaged.
You can:
- Confirm that this issue is still relevant with
/triage accepted
(org members only) - Close this issue with
/close
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/
/remove-triage accepted
Hello, do you plan to add scaffolding webhooks for core resources?