Skip to content

Commit 11212e6

Browse files
authored
Fix CRD markers (#4178)
* Fix incorrect Kubebuilder validation markers This commit corrects several invalid Kubebuilder validation markers that caused controller-gen validation errors. Changes: Removed +listType=atomic from non-array fields: gateway_types.go: Namespaces *RouteNamespaces (line 806) backendtlspolicy_types.go: WellKnownCACertificates (line 192) Replaced MaxLength with MaxItems for array fields: httproute_types.go: AllowedRequestHeaders []string (lines 1674, 1722) httproute_types.go: AllowedResponseHeaders []string (line 1733) Removed Minimum/Maximum from non-primitive fields: xlistenerset_types.go: Port PortNumber (lines 170, 255) Added CRD marker validation to hack/update-clientset.sh to detect invalid markers during development and CI. These fixes ensure validation markers are applied only to compatible field types. Signed-off-by: Killian Golds <kgolds@redhat.com> * Restore port validation by defining PortNumber types in v1alpha1 Addresses reviewers feedback by moving validation to the type level. Creates StatusPortNumber for status fields requiring valid ports (1-65535). Signed-off-by: Killian Golds <kgolds@redhat.com> * Removed invalid printcolumn marker from v1alpha2 ReferenceGrant The v1alpha2 ReferenceGrant type is marked with +kubebuilder:skipversion, meaning no CRD is generated for this version (it’s just an alias to v1beta1). The +kubebuilder:printcolumn marker cannot be applied to a skipped version. This issue was uncovered by the CRD marker validation added in the previous commit. The printcolumn is already correctly defined in v1beta1 and does not need to be duplicated here. Signed-off-by: Killian Golds <kgolds@redhat.com> * Rename PortNumber to PortNumberWith0 to prevent misuse The rename makes it explicit that this type permits 0, helping prevent accidental use where StatusPortNumber (1–65535) should be preferred. Signed-off-by: Killian Golds <kgolds@redhat.com> * Use output:none for CRD marker validation Simplifies the validation step to avoid generating files or requiring boilerplate headers. The validation still catches invalid markers but does not write any CRDs to disk. * clean duplicated echo statement Signed-off-by: Killian Golds <kgolds@redhat.com> --------- Signed-off-by: Killian Golds <kgolds@redhat.com>
1 parent 7477dba commit 11212e6

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

apis/v1alpha2/referencegrant_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
// +genclient
2626
// +kubebuilder:object:root=true
2727
// +kubebuilder:resource:categories=gateway-api,shortName=refgrant
28-
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
2928
// +kubebuilder:skipversion
3029
// +kubebuilder:deprecatedversion:warning="The v1alpha2 version of ReferenceGrant has been deprecated and will be removed in a future release of the API. Please upgrade to v1beta1."
3130

apisx/v1alpha1/shared_types.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type (
2727
Hostname = v1.Hostname
2828
Kind = v1.Kind
2929
ObjectName = v1.ObjectName
30-
PortNumber = v1.PortNumber
3130
ProtocolType = v1.ProtocolType
3231
RouteGroupKind = v1.RouteGroupKind
3332
SectionName = v1.SectionName
@@ -38,6 +37,23 @@ type (
3837
SessionPersistence = v1.SessionPersistence
3938
)
4039

40+
// PortNumberWith0 defines a network port that allows 0 to indicate dynamic
41+
// port assignment. This type should only be used in spec fields where port 0
42+
// has the special meaning of "auto-assign a port". In most cases,
43+
// StatusPortNumber (which excludes 0) should be preferred.
44+
//
45+
// +kubebuilder:validation:Minimum=0
46+
// +kubebuilder:validation:Maximum=65535
47+
type PortNumberWith0 int32
48+
49+
// StatusPortNumber defines a network port in status fields.
50+
// Unlike PortNumberWith0, this does not allow 0 since status fields
51+
// reflect actual assigned ports.
52+
//
53+
// +kubebuilder:validation:Minimum=1
54+
// +kubebuilder:validation:Maximum=65535
55+
type StatusPortNumber int32
56+
4157
// ParentGatewayReference identifies an API object including its namespace,
4258
// defaulting to Gateway.
4359
type ParentGatewayReference struct {

apisx/v1alpha1/xlistenerset_types.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ type ListenerEntry struct {
167167
// +optional
168168
//
169169
// +kubebuilder:default=0
170-
// +kubebuilder:validation:Minimum=0
171-
// +kubebuilder:validation:Maximum=65535
172-
Port PortNumber `json:"port,omitempty"`
170+
Port PortNumberWith0 `json:"port,omitempty"`
173171

174172
// Protocol specifies the network protocol this listener expects to receive.
175173
// +required
@@ -253,11 +251,8 @@ type ListenerEntryStatus struct {
253251

254252
// Port is the network port the listener is configured to listen on.
255253
//
256-
// +kubebuilder:validation:Minimum=1
257-
// +kubebuilder:validation:Maximum=65535
258-
//
259254
// +required
260-
Port PortNumber `json:"port"`
255+
Port StatusPortNumber `json:"port"`
261256

262257
// SupportedKinds is the list indicating the Kinds supported by this
263258
// listener. This MUST represent the kinds an implementation supports for

applyconfiguration/apisx/v1alpha1/listenerentry.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applyconfiguration/apisx/v1alpha1/listenerentrystatus.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/update-clientset.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,10 @@ go run sigs.k8s.io/controller-tools/cmd/controller-gen \
118118
object:headerFile=${SCRIPT_ROOT}/hack/boilerplate/boilerplate.generatego.txt \
119119
paths="./apis/..." \
120120
paths="./apisx/..."
121+
122+
echo "Validating CRD markers"
123+
go run sigs.k8s.io/controller-tools/cmd/controller-gen \
124+
crd \
125+
paths="./apis/..." \
126+
paths="./apisx/..." \
127+
output:none

0 commit comments

Comments
 (0)