Skip to content

Commit 3d0c947

Browse files
committed
Consistent validation for reference types
1 parent d2c6e7a commit 3d0c947

File tree

8 files changed

+119
-44
lines changed

8 files changed

+119
-44
lines changed

api/v1alpha2/inferencemodel_types.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,18 @@ type PoolObjectReference struct {
106106
//
107107
// +optional
108108
// +kubebuilder:default="inference.networking.x-k8s.io"
109-
// +kubebuilder:validation:MaxLength=253
110-
// +kubebuilder:validation:Pattern=`^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
111-
Group string `json:"group,omitempty"`
109+
Group Group `json:"group,omitempty"`
112110

113111
// Kind is kind of the referent. For example "InferencePool".
114112
//
115113
// +optional
116114
// +kubebuilder:default="InferencePool"
117-
// +kubebuilder:validation:MinLength=1
118-
// +kubebuilder:validation:MaxLength=63
119-
// +kubebuilder:validation:Pattern=`^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$`
120-
Kind string `json:"kind,omitempty"`
115+
Kind Kind `json:"kind,omitempty"`
121116

122117
// Name is the name of the referent.
123118
//
124-
// +kubebuilder:validation:MinLength=1
125-
// +kubebuilder:validation:MaxLength=253
126119
// +kubebuilder:validation:Required
127-
Name string `json:"name"`
120+
Name ObjectName `json:"name"`
128121
}
129122

130123
// Criticality defines how important it is to serve the model compared to other models.

api/v1alpha2/inferencepool_types.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ type Extension struct {
9090
// ExtensionReference is a reference to the extension deployment.
9191
type ExtensionReference struct {
9292
// Group is the group of the referent.
93-
// When unspecified or empty string, core API group is inferred.
93+
// The default value is "", representing the Core API group.
9494
//
9595
// +optional
9696
// +kubebuilder:default=""
97-
Group *string `json:"group,omitempty"`
97+
Group *Group `json:"group,omitempty"`
9898

9999
// Kind is the Kubernetes resource kind of the referent. For example
100100
// "Service".
@@ -109,20 +109,19 @@ type ExtensionReference struct {
109109
//
110110
// +optional
111111
// +kubebuilder:default=Service
112-
Kind *string `json:"kind,omitempty"`
112+
Kind *Kind `json:"kind,omitempty"`
113113

114114
// Name is the name of the referent.
115115
//
116116
// +kubebuilder:validation:Required
117-
Name string `json:"name"`
117+
Name ObjectName `json:"name"`
118118

119-
// The port number on the service running the extension. When unspecified, implementations SHOULD infer a
120-
// default value of 9002 when the Kind is Service.
119+
// The port number on the service running the extension. When unspecified,
120+
// implementations SHOULD infer a default value of 9002 when the Kind is
121+
// Service.
121122
//
122-
// +kubebuilder:validation:Minimum=1
123-
// +kubebuilder:validation:Maximum=65535
124123
// +optional
125-
PortNumber *int32 `json:"targetPortNumber,omitempty"`
124+
PortNumber *PortNumber `json:"portNumber,omitempty"`
126125
}
127126

128127
// ExtensionConnection encapsulates options that configures the connection to the extension.

api/v1alpha2/shared_types.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha2
18+
19+
// Group refers to a Kubernetes Group. It must either be an empty string or a
20+
// RFC 1123 subdomain.
21+
//
22+
// This validation is based off of the corresponding Kubernetes validation:
23+
// https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/util/validation/validation.go#L208
24+
//
25+
// Valid values include:
26+
//
27+
// * "" - empty string implies core Kubernetes API group
28+
// * "gateway.networking.k8s.io"
29+
// * "foo.example.com"
30+
//
31+
// Invalid values include:
32+
//
33+
// * "example.com/bar" - "/" is an invalid character
34+
//
35+
// +kubebuilder:validation:MaxLength=253
36+
// +kubebuilder:validation:Pattern=`^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
37+
type Group string
38+
39+
// Kind refers to a Kubernetes Kind.
40+
//
41+
// Valid values include:
42+
//
43+
// * "Service"
44+
// * "HTTPRoute"
45+
//
46+
// Invalid values include:
47+
//
48+
// * "invalid/kind" - "/" is an invalid character
49+
//
50+
// +kubebuilder:validation:MinLength=1
51+
// +kubebuilder:validation:MaxLength=63
52+
// +kubebuilder:validation:Pattern=`^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$`
53+
type Kind string
54+
55+
// ObjectName refers to the name of a Kubernetes object.
56+
// Object names can have a variety of forms, including RFC 1123 subdomains,
57+
// RFC 1123 labels, or RFC 1035 labels.
58+
//
59+
// +kubebuilder:validation:MinLength=1
60+
// +kubebuilder:validation:MaxLength=253
61+
type ObjectName string
62+
63+
// PortNumber defines a network port.
64+
//
65+
// +kubebuilder:validation:Minimum=1
66+
// +kubebuilder:validation:Maximum=65535
67+
type PortNumber int32

api/v1alpha2/zz_generated.deepcopy.go

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

client-go/applyconfiguration/api/v1alpha2/extension.go

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

client-go/applyconfiguration/api/v1alpha2/extensionreference.go

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

client-go/applyconfiguration/api/v1alpha2/poolobjectreference.go

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

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ spec:
5656
default: ""
5757
description: |-
5858
Group is the group of the referent.
59-
When unspecified or empty string, core API group is inferred.
59+
The default value is "", representing the Core API group.
60+
maxLength: 253
61+
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
6062
type: string
6163
kind:
6264
default: Service
@@ -71,14 +73,20 @@ spec:
7173
terms of conformance. They also may not be safe to forward to (see
7274
CVE-2021-25740 for more information). Implementations MUST NOT
7375
support ExternalName Services.
76+
maxLength: 63
77+
minLength: 1
78+
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
7479
type: string
7580
name:
7681
description: Name is the name of the referent.
82+
maxLength: 253
83+
minLength: 1
7784
type: string
78-
targetPortNumber:
85+
portNumber:
7986
description: |-
80-
The port number on the service running the extension. When unspecified, implementations SHOULD infer a
81-
default value of 9002 when the Kind is Service.
87+
The port number on the service running the extension. When unspecified,
88+
implementations SHOULD infer a default value of 9002 when the Kind is
89+
Service.
8290
format: int32
8391
maximum: 65535
8492
minimum: 1

0 commit comments

Comments
 (0)