Skip to content

Question: MinItems/MaxItems on map (LabelSelector.MatchLabels) causing CRD gen error. #1678

@KillianGolds

Description

@KillianGolds

What happened:

controller-gen crd fails with:

must apply minitems to an array
must apply maxitem to an array

I’m new to this area, so this might be me misunderstanding something. I noticed LabelSelector.MatchLabels is a map but has +kubebuilder:validation:MinItems/MaxItems markers:

// api/v1/shared_types.go
type LabelSelector struct {
    // ...
    // +kubebuilder:validation:MinItems=1
    // +kubebuilder:validation:MaxItems=64
    MatchLabels map[LabelKey]LabelValue `json:"matchLabels,omitempty"`
}

Refs:

What you expected to happen:
CRD generation succeeds. If cardinality on a map is intended, I believe MinProperties/MaxProperties would be the correct markers, or the map cardinality check could be omitted.

How to reproduce it (as minimally and precisely as possible):

  1. Use Gateway API Inference Extension v1.0.0 or v1.0.1.
  2. Run controller-gen crd over types including LabelSelector (or vendor the module and run with paths=./...).
  3. Observe the error above.

Anything else we need to know?:

  • controller-tools appears to enforce MinItems/MaxItems only on arrays: https://github.com/kubernetes-sigs/controller-tools/blob/main/pkg/crd/markers/validation.go
  • The generated CRD YAML in this repo models matchLabels as an object with additionalProperties constraints on values (which looks correct) and does not use MinItems/MaxItems on the map:
    • matchLabels:
      additionalProperties:
      description: |-
      LabelValue is the value of a label. This is used for validation
      of maps. This matches the Kubernetes label validation rules:
      * must be 63 characters or less (can be empty),
      * unless empty, must begin and end with an alphanumeric character ([a-z0-9A-Z]),
      * could contain dashes (-), underscores (_), dots (.), and alphanumerics between.
      Valid values include:
      * MyValue
      * my.name
      * 123-my-value
      maxLength: 63
      minLength: 0
      pattern: ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
      type: string
      description: |-
      MatchLabels contains a set of required {key,value} pairs.
      An object must match every label in this map to be selected.
      The matching logic is an AND operation on all entries.
      type: object
      required:
  • Questions: Is MinItems/MaxItems on a map field intentional here, or should it be MinProperties/MaxProperties? If unintended, I’m happy to open a PR adjusting the markers.

Environment:

  • Kubernetes version (use kubectl version): N/A
  • Inference extension version (use git describe --tags --dirty --always): v1.0.0 / v1.0.1
  • Cloud provider or hardware configuration: N/A
  • Install tools: controller-gen (version aligned with repo; issue still reproduces)
  • Others: none

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions