panic: interface conversion: `*types.Interface` is not `interface { Obj() *types.TypeName }`: missing method Obj
When attempting to generate a CRD for an object with a field of type any, a panic happens.
Example file to reproduce:
// +kubebuilder:object:generate=true
// +groupName=example.com
package v1beta2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +kubebuilder:object:root=true
type MyKind struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:",inline"`
Spec MyKindSpec `json:"spec"`
}
type MyKindSpec struct {
Foo any `json:"foo"`
}
Gives:
panic: interface conversion: *types.Interface is not interface { Obj() *types.TypeName }: missing method Obj
I'm expecting a soft error and not a crash. For example when defining a field with type map[string]any, an error is logged but a best-effort CRD is still generated:
/path/to/file.go:LINE:COL: not a supported map value type: *ast.InterfaceType
Which version of controller-gen are you using? We had multiple fixes for issues like this
controller-gen v0.18.0 (latest release).
(cc @cbandy, just in case you have some time to look into this :))
I'm not sure how contributing works, and if the maintainers have strong opinions about if this should/shouldn't be fixed, and if so how it should be fixed.
But I had a look into this. Thoughts on https://github.com/kubernetes-sigs/controller-tools/pull/1252 @sbueringer ?
Just opening a PR is fine. Someone just has to find time to look into it 😀. I'm always low on bandwidth unfortunately
@JoelSpeed Do you have an opinion on this? In general I agree that panics are never acceptable and we should at least produce an error instead
I generally lean to panics are for errors in the code of the program that should never be seen by end users, so given this is an issue with an input, erroring is definitely inline with what I'd expect here. I think this is probably just an oversight on our part
I updated PR https://github.com/kubernetes-sigs/controller-tools/pull/1252 to error as per this discussion.
Need a final review / approval please on https://github.com/kubernetes-sigs/controller-tools/pull/1252 @JoelSpeed
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale - Close this issue with
/close - Offer to help out with Issue Triage
Please 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.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle rotten - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
Waiting for rebase on the PR