Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathological CRD generation when struct names clash #1137

Open
Miles-Garnsey opened this issue Jan 29, 2025 · 1 comment
Open

Pathological CRD generation when struct names clash #1137

Miles-Garnsey opened this issue Jan 29, 2025 · 1 comment

Comments

@Miles-Garnsey
Copy link

We have two packages/groups defined in our APIs directory. There is a struct with the same name in each; one of which is intended to generate a CRD, and one of which is just a field within another CRD.

Example:

// in apis/ourapp/v1beta2/ourresource1_types.go

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:resource:path=missioncontrolclusters,shortName=mccluster;mcclusters

type Bar struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   BarSpec   `json:"spec,omitempty"`
	Status BarStatus `json:"status,omitempty"`
}

type BarSpec {
...
Foo *Foo `json:"foo,omitempty"`
...
}

type Foo struct {
...
}
// in apis/ourapp/v1alpha1/ourresource2_types.go

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +versionName=v1alpha1
// +kubebuilder:printcolumn:name="Error",type=string,JSONPath=".status.error",description="Latest reconcile error"

type Foo struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   FooSpec   `json:"spec,omitempty"`
	Status FooStatus `json:"status,omitempty"`
}

When the CRDs get generated, we're seeing both a v1alpha1 and v1beta2 resource version being created within the CRD.

This is incorrect and results in the spec of the Foo being deleted due to some sort of conversion webhook mechanics.

Is there a documented constraint that a struct with the same name as a kubebuilder object root cannot exist in another API version/package?

@sbueringer
Copy link
Member

Is there a documented constraint that a struct with the same name as a kubebuilder object root cannot exist in another API version/package?

Not that I'm aware of. Sounds like a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants