Skip to content

New Linter: markerscope | KAL fails to detect minproperties validation. #148

@nayuta723

Description

@nayuta723

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

  1. 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"`
    }
  2. Run kube-api-linter against this file.
    The linter will complete successfully without any warnings or errors.

  3. 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.

Metadata

Metadata

Assignees

Labels

help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/featureCategorizes issue or PR as related to a new feature.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions