generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 176
Open
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.Indicates an issue or PR lacks a `triage/foo` label and requires one.
Description
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:
// +kubebuilder:validation:MinItems=1 - https://github.com/kubernetes-sigs/gateway-api-inference-extension/blob/bfd979d7576acf3f121efeae01920cb09d09cbe8/api/v1/shared_types.go#L136-L145
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):
- Use Gateway API Inference Extension v1.0.0 or v1.0.1.
- Run controller-gen crd over types including LabelSelector (or vendor the module and run with paths=./...).
- 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:
gateway-api-inference-extension/config/crd/bases/inference.networking.k8s.io_inferencepools.yaml
Lines 128 to 151 in bfd979d
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
KillianGolds
Metadata
Metadata
Assignees
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.Indicates an issue or PR lacks a `triage/foo` label and requires one.