controller-tools icon indicating copy to clipboard operation
controller-tools copied to clipboard

panic: interface conversion: `*types.Interface` is not `interface { Obj() *types.TypeName }`: missing method Obj

Open brekelj1 opened this issue 5 months ago • 10 comments

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

brekelj1 avatar Aug 04 '25 05:08 brekelj1

Which version of controller-gen are you using? We had multiple fixes for issues like this

sbueringer avatar Aug 04 '25 05:08 sbueringer

controller-gen v0.18.0 (latest release).

brekelj1 avatar Aug 04 '25 08:08 brekelj1

(cc @cbandy, just in case you have some time to look into this :))

sbueringer avatar Aug 04 '25 08:08 sbueringer

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 ?

brekelj1 avatar Aug 05 '25 01:08 brekelj1

Just opening a PR is fine. Someone just has to find time to look into it 😀. I'm always low on bandwidth unfortunately

sbueringer avatar Aug 05 '25 05:08 sbueringer

@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

sbueringer avatar Aug 05 '25 05:08 sbueringer

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

JoelSpeed avatar Aug 05 '25 09:08 JoelSpeed

I updated PR https://github.com/kubernetes-sigs/controller-tools/pull/1252 to error as per this discussion.

brekelj1 avatar Aug 07 '25 01:08 brekelj1

Need a final review / approval please on https://github.com/kubernetes-sigs/controller-tools/pull/1252 @JoelSpeed

brekelj1 avatar Sep 16 '25 01:09 brekelj1

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/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 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

k8s-triage-robot avatar Dec 15 '25 01:12 k8s-triage-robot

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/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 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

k8s-triage-robot avatar Jan 14 '26 02:01 k8s-triage-robot

Waiting for rebase on the PR

sbueringer avatar Jan 14 '26 06:01 sbueringer