Skip to content

Commit 4d4437f

Browse files
Fix LabelSelector validation markers for map field (#1679) (#1717)
* Fix LabelSelector validation markers for map field Changed MinItems/MaxItems to MinProperties/MaxProperties for the MatchLabels field in LabelSelector, as it is a map type, not an array. This resolves controller-gen CRD generation errors. * Add CRD generation to make generate target Add controller-gen crd to the generate target to validate kubebuilder markers during development and CI runs. Previously, make generate only ran controller-gen object, which generates DeepCopy methods but does not validate CRD markers like MinItems, MaxItems, MinProperties, etc. This meant invalid markers could be merged without detection, only to cause failures in downstream projects that run full CRD generation. By adding CRD generation to the generate target: - Invalid kubebuilder markers are caught immediately during development - CI will fail if markers are incorrect or CRDs are out of sync - Prevents downstream projects from encountering CRD generation errors - Aligns with the target's existing documentation which states it generates CustomResourceDefinition objects This change would have caught the MinItems/MaxItems issue fixed in commit 40cecfd before it was merged. * Regenerate CRDs with updated validation markers This regenerates the CRDs to include the MinProperties/MaxProperties validation for the MatchLabels map field. The generated CRD now includes: - minProperties: 1 - maxProperties: 64 These properties correctly validate the map field, replacing the incorrect MinItems/MaxItems markers that were causing controller-gen failures. --------- Signed-off-by: Killian Golds <[email protected]> Co-authored-by: Killian Golds <[email protected]>
1 parent f1ffd36 commit 4d4437f

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ help: ## Display this help.
9999
.PHONY: generate
100100
generate: controller-gen code-generator ## Generate WebhookConfiguration, ClusterRole, CustomResourceDefinition objects, code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
101101
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate/boilerplate.generatego.txt" paths="./..."
102+
$(CONTROLLER_GEN) crd output:dir="./config/crd/bases" paths="./..."
102103
./hack/update-codegen.sh
103104

104105
# Use same code-generator version as k8s.io/api

api/v1/shared_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ type LabelSelector struct {
137137
// The matching logic is an AND operation on all entries.
138138
//
139139
// +required
140-
// +kubebuilder:validation:MinItems=1
141-
// +kubebuilder:validation:MaxItems=64
140+
// +kubebuilder:validation:MinProperties=1
141+
// +kubebuilder:validation:MaxProperties=64
142142
MatchLabels map[LabelKey]LabelValue `json:"matchLabels,omitempty"`
143143
}

config/crd/bases/inference.networking.k8s.io_inferencepools.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ spec:
147147
MatchLabels contains a set of required {key,value} pairs.
148148
An object must match every label in this map to be selected.
149149
The matching logic is an AND operation on all entries.
150+
maxProperties: 64
151+
minProperties: 1
150152
type: object
151153
required:
152154
- matchLabels

0 commit comments

Comments
 (0)