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 MinProperties marker, 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-linter against this file.
The linter will complete successfully without any warnings or errors.
-
Run controller-gen against this file.
controller-gen will 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.
The
kube-api-lintertool successfully lints a Kubernetes API definition even when the+kubebuilder:validation:MinPropertiesmarker is incorrectly applied to a field that is not anobjecttype (astruct). This leads to a subsequent failure whencontroller-genis run, as it correctly enforces this constraint.How to reproduce
Create a Kubernetes API definition with a
MinPropertiesmarker, like the following example: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.