diff --git a/apis/v1alpha2/referencegrant_types.go b/apis/v1alpha2/referencegrant_types.go index 2c23455004..9869a8483d 100644 --- a/apis/v1alpha2/referencegrant_types.go +++ b/apis/v1alpha2/referencegrant_types.go @@ -25,7 +25,6 @@ import ( // +genclient // +kubebuilder:object:root=true // +kubebuilder:resource:categories=gateway-api,shortName=refgrant -// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` // +kubebuilder:skipversion // +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." diff --git a/apisx/v1alpha1/shared_types.go b/apisx/v1alpha1/shared_types.go index 94851df261..42d4bc19bc 100644 --- a/apisx/v1alpha1/shared_types.go +++ b/apisx/v1alpha1/shared_types.go @@ -27,7 +27,6 @@ type ( Hostname = v1.Hostname Kind = v1.Kind ObjectName = v1.ObjectName - PortNumber = v1.PortNumber ProtocolType = v1.ProtocolType RouteGroupKind = v1.RouteGroupKind SectionName = v1.SectionName @@ -38,6 +37,23 @@ type ( SessionPersistence = v1.SessionPersistence ) +// PortNumberWith0 defines a network port that allows 0 to indicate dynamic +// port assignment. This type should only be used in spec fields where port 0 +// has the special meaning of "auto-assign a port". In most cases, +// StatusPortNumber (which excludes 0) should be preferred. +// +// +kubebuilder:validation:Minimum=0 +// +kubebuilder:validation:Maximum=65535 +type PortNumberWith0 int32 + +// StatusPortNumber defines a network port in status fields. +// Unlike PortNumberWith0, this does not allow 0 since status fields +// reflect actual assigned ports. +// +// +kubebuilder:validation:Minimum=1 +// +kubebuilder:validation:Maximum=65535 +type StatusPortNumber int32 + // ParentGatewayReference identifies an API object including its namespace, // defaulting to Gateway. type ParentGatewayReference struct { diff --git a/apisx/v1alpha1/xlistenerset_types.go b/apisx/v1alpha1/xlistenerset_types.go index f8198c8659..fd9cb9d91a 100644 --- a/apisx/v1alpha1/xlistenerset_types.go +++ b/apisx/v1alpha1/xlistenerset_types.go @@ -167,9 +167,7 @@ type ListenerEntry struct { // +optional // // +kubebuilder:default=0 - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=65535 - Port PortNumber `json:"port,omitempty"` + Port PortNumberWith0 `json:"port,omitempty"` // Protocol specifies the network protocol this listener expects to receive. // +required @@ -253,11 +251,8 @@ type ListenerEntryStatus struct { // Port is the network port the listener is configured to listen on. // - // +kubebuilder:validation:Minimum=1 - // +kubebuilder:validation:Maximum=65535 - // // +required - Port PortNumber `json:"port"` + Port StatusPortNumber `json:"port"` // SupportedKinds is the list indicating the Kinds supported by this // listener. This MUST represent the kinds an implementation supports for diff --git a/applyconfiguration/apisx/v1alpha1/listenerentry.go b/applyconfiguration/apisx/v1alpha1/listenerentry.go index d9f4dc9a4e..535571daec 100644 --- a/applyconfiguration/apisx/v1alpha1/listenerentry.go +++ b/applyconfiguration/apisx/v1alpha1/listenerentry.go @@ -20,6 +20,7 @@ package v1alpha1 import ( v1 "sigs.k8s.io/gateway-api/apis/v1" + apisxv1alpha1 "sigs.k8s.io/gateway-api/apisx/v1alpha1" apisv1 "sigs.k8s.io/gateway-api/applyconfiguration/apis/v1" ) @@ -28,7 +29,7 @@ import ( type ListenerEntryApplyConfiguration struct { Name *v1.SectionName `json:"name,omitempty"` Hostname *v1.Hostname `json:"hostname,omitempty"` - Port *int32 `json:"port,omitempty"` + Port *apisxv1alpha1.PortNumberWith0 `json:"port,omitempty"` Protocol *v1.ProtocolType `json:"protocol,omitempty"` TLS *apisv1.ListenerTLSConfigApplyConfiguration `json:"tls,omitempty"` AllowedRoutes *apisv1.AllowedRoutesApplyConfiguration `json:"allowedRoutes,omitempty"` @@ -59,7 +60,7 @@ func (b *ListenerEntryApplyConfiguration) WithHostname(value v1.Hostname) *Liste // WithPort sets the Port field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Port field is set to the value of the last call. -func (b *ListenerEntryApplyConfiguration) WithPort(value int32) *ListenerEntryApplyConfiguration { +func (b *ListenerEntryApplyConfiguration) WithPort(value apisxv1alpha1.PortNumberWith0) *ListenerEntryApplyConfiguration { b.Port = &value return b } diff --git a/applyconfiguration/apisx/v1alpha1/listenerentrystatus.go b/applyconfiguration/apisx/v1alpha1/listenerentrystatus.go index 888f57d75d..4b389199e4 100644 --- a/applyconfiguration/apisx/v1alpha1/listenerentrystatus.go +++ b/applyconfiguration/apisx/v1alpha1/listenerentrystatus.go @@ -21,6 +21,7 @@ package v1alpha1 import ( metav1 "k8s.io/client-go/applyconfigurations/meta/v1" v1 "sigs.k8s.io/gateway-api/apis/v1" + apisxv1alpha1 "sigs.k8s.io/gateway-api/apisx/v1alpha1" apisv1 "sigs.k8s.io/gateway-api/applyconfiguration/apis/v1" ) @@ -28,7 +29,7 @@ import ( // with apply. type ListenerEntryStatusApplyConfiguration struct { Name *v1.SectionName `json:"name,omitempty"` - Port *int32 `json:"port,omitempty"` + Port *apisxv1alpha1.StatusPortNumber `json:"port,omitempty"` SupportedKinds []apisv1.RouteGroupKindApplyConfiguration `json:"supportedKinds,omitempty"` AttachedRoutes *int32 `json:"attachedRoutes,omitempty"` Conditions []metav1.ConditionApplyConfiguration `json:"conditions,omitempty"` @@ -51,7 +52,7 @@ func (b *ListenerEntryStatusApplyConfiguration) WithName(value v1.SectionName) * // WithPort sets the Port field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Port field is set to the value of the last call. -func (b *ListenerEntryStatusApplyConfiguration) WithPort(value int32) *ListenerEntryStatusApplyConfiguration { +func (b *ListenerEntryStatusApplyConfiguration) WithPort(value apisxv1alpha1.StatusPortNumber) *ListenerEntryStatusApplyConfiguration { b.Port = &value return b } diff --git a/hack/update-clientset.sh b/hack/update-clientset.sh index e9fda1f32d..212619c341 100755 --- a/hack/update-clientset.sh +++ b/hack/update-clientset.sh @@ -118,3 +118,10 @@ go run sigs.k8s.io/controller-tools/cmd/controller-gen \ object:headerFile=${SCRIPT_ROOT}/hack/boilerplate/boilerplate.generatego.txt \ paths="./apis/..." \ paths="./apisx/..." + +echo "Validating CRD markers" +go run sigs.k8s.io/controller-tools/cmd/controller-gen \ + crd \ + paths="./apis/..." \ + paths="./apisx/..." \ + output:none