-
Notifications
You must be signed in to change notification settings - Fork 21
Description
The kube-api-linter tool successfully lints a Kubernetes API definition even when the +kubebuilder:validation:MinProperties marker is incorrectly applied to a field that is not an object type (a struct). This leads to a subsequent failure when controller-gen is run, as it correctly enforces this constraint.
How to reproduce
-
Create a Kubernetes API definition with a
MinPropertiesmarker, like the following example:type FooSpec struct { // foo is a foo. // +optional // +kubebuilder:validation:MinProperties=1 Foo Foo `json:"foo,omitzero"` } type Foo struct { // bar is a bar. // +optional // +kubebuilder:validation:MinLength=1 // +kubebuilder:validation:MaxLength=10 Bar string `json:"bar,omitempty"` }
-
Run
kube-api-linteragainst this file.
The linter will complete successfully without any warnings or errors. -
Run
controller-genagainst this file.
controller-genwill fail with an error similar to:must apply minproperties to an object.
Proposed Solution
I believe a new linter rule should be added that specifically validates the correct usage of +kubebuilder:validation:MinProperties on object types, ensuring that its application does not contradict other API conventions or cause controller-gen to fail. This would make the linter a more effective tool for API development.