Skip to content

Commit c377456

Browse files
committed
Renames Pool v1 FailMode Types
Signed-off-by: Daneyon Hansen <[email protected]>
1 parent 6bf0bc4 commit c377456

File tree

7 files changed

+115
-77
lines changed

7 files changed

+115
-77
lines changed

api/v1/inferencepool_types.go

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ type InferencePool struct {
3535
// +optional
3636
metav1.ObjectMeta `json:"metadata,omitempty"`
3737

38+
// Spec defines the desired state of the InferencePool.
39+
//
3840
// +required
39-
Spec InferencePoolSpec `json:"spec,omitzero"`
41+
Spec InferencePoolSpec `json:"spec"`
4042

4143
// Status defines the observed state of the InferencePool.
4244
//
@@ -45,7 +47,7 @@ type InferencePool struct {
4547
Status InferencePoolStatus `json:"status,omitempty"`
4648
}
4749

48-
// InferencePoolList contains a list of InferencePool.
50+
// InferencePoolList contains a list InferencePools.
4951
//
5052
// +kubebuilder:object:root=true
5153
type InferencePoolList struct {
@@ -54,7 +56,7 @@ type InferencePoolList struct {
5456
Items []InferencePool `json:"items"`
5557
}
5658

57-
// InferencePoolSpec defines the desired state of InferencePool
59+
// InferencePoolSpec defines the desired state of the InferencePool.
5860
type InferencePoolSpec struct {
5961
// Selector determines which Pods are members of this inference pool.
6062
// It matches Pods by their labels only within the same namespace; cross-namespace
@@ -65,19 +67,22 @@ type InferencePoolSpec struct {
6567
// this configuration into a Service resource.
6668
//
6769
// +required
68-
Selector LabelSelector `json:"selector,omitempty,omitzero"`
70+
Selector LabelSelector `json:"selector"`
6971

7072
// TargetPorts defines a list of ports that are exposed by this InferencePool.
7173
// Currently, the list may only include a single port definition.
74+
//
7275
// +kubebuilder:validation:MinItems=1
7376
// +kubebuilder:validation:MaxItems=1
7477
// +listType=atomic
7578
// +required
76-
TargetPorts []Port `json:"targetPorts,omitempty"`
79+
TargetPorts []Port `json:"targetPorts"`
7780

78-
// EndpointPickerRef configures an endpoint picker as an extension service.
81+
// EndpointPickerRef is a reference to the Endpoint Picker extension and its
82+
// associated configuration.
83+
//
7984
// +required
80-
EndpointPickerRef EndpointPickerRef `json:"endpointPickerRef,omitempty,omitzero"`
85+
EndpointPickerRef EndpointPickerRef `json:"endpointPickerRef"`
8186
}
8287

8388
// Port defines the network port that will be exposed by this InferencePool.
@@ -86,21 +91,22 @@ type Port struct {
8691
// The number must be in the range 1 to 65535.
8792
//
8893
// +required
89-
Number PortNumber `json:"number,omitempty"`
94+
Number PortNumber `json:"number"`
9095
}
9196

92-
// Extension specifies how to configure an extension that runs the endpoint picker.
97+
// EndpointPickerRef specifies a reference to an Endpoint Picker extension and its
98+
// associated configuration.
9399
type EndpointPickerRef struct {
94-
// Group is the group of the referent.
95-
// The default value is "", representing the Core API group.
100+
// Group is the group of the referent API object. When unspecified, the default value
101+
// is "", representing the Core API group.
96102
//
97103
// +optional
98104
// +kubebuilder:default=""
99105
Group *Group `json:"group,omitempty"`
100106

101107
// Kind is the Kubernetes resource kind of the referent.
102108
//
103-
// Required if the referent is ambiguous(e.g. service with one port is unambiguous).
109+
// Required if the referent is ambiguous, e.g. service with multiple ports.
104110
//
105111
// Defaults to "Service" when not specified.
106112
//
@@ -112,40 +118,42 @@ type EndpointPickerRef struct {
112118
//
113119
// +optional
114120
// +kubebuilder:default=Service
115-
Kind Kind `json:"kind,omitempty"`
121+
Kind *Kind `json:"kind,omitempty"`
116122

117-
// Name is the name of the referent.
123+
// Name is the name of the referent API object.
118124
//
119125
// +required
120-
Name ObjectName `json:"name,omitempty"`
126+
Name ObjectName `json:"name"`
121127

122-
// The port number on the service running the extension. When unspecified,
123-
// implementations SHOULD infer a default value of 9002 when the Kind is
124-
// Service.
128+
// PortNumber is the port number of the Endpoint Picker extension service. When unspecified,
129+
// implementations SHOULD infer a default value of 9002 when the kind field is "Service" or
130+
// unspecified (defaults to "Service").
125131
//
126132
// +optional
127133
//nolint:kubeapilinter // ignore kubeapilinter here as we want to use pointer here as 0 usually means all ports.
128134
PortNumber *PortNumber `json:"portNumber,omitempty"`
129135

130-
// Configures how the parent handles the case when the extension is not responsive.
131-
// Defaults to failClose.
136+
// FailureMode configures how the parent handles the case when the Endpoint Picker extension
137+
// is non-responsive. When unspecified, defaults to "FailClose".
132138
//
133139
// +optional
134140
// +kubebuilder:default="FailClose"
135-
FailureMode ExtensionFailureMode `json:"failureMode,omitempty"`
141+
FailureMode *EndpointPickerFailureMode `json:"failureMode,omitempty"`
136142
}
137143

138-
// ExtensionFailureMode defines the options for how the parent handles the case when the extension is not
139-
// responsive.
144+
// EndpointPickerFailureMode defines the options for how the parent handles the case when the
145+
// Endpoint Picker extension is non-responsive.
146+
//
140147
// +kubebuilder:validation:Enum=FailOpen;FailClose
141-
type ExtensionFailureMode string
148+
type EndpointPickerFailureMode string
142149

143150
const (
144-
// FailOpen specifies that the proxy should forward the request to an endpoint of its picking when
145-
// the Endpoint Picker fails.
146-
FailOpen ExtensionFailureMode = "FailOpen"
147-
// FailClose specifies that the proxy should drop the request when the Endpoint Picker fails.
148-
FailClose ExtensionFailureMode = "FailClose"
151+
// EndpointPickerFailOpen specifies that the parent should forward the request to an endpoint
152+
// of its picking when the Endpoint Picker extension fails.
153+
EndpointPickerFailOpen EndpointPickerFailureMode = "FailOpen"
154+
// EndpointPickerFailClose specifies that the parent should drop the request when the Endpoint
155+
// Picker extension fails.
156+
EndpointPickerFailClose EndpointPickerFailureMode = "FailClose"
149157
)
150158

151159
// InferencePoolStatus defines the observed state of the InferencePool.
@@ -190,7 +198,7 @@ type ParentStatus struct {
190198
// resource, such as a Gateway.
191199
//
192200
// +required
193-
ParentRef ParentReference `json:"parentRef,omitzero"`
201+
ParentRef ParentReference `json:"parentRef"`
194202
}
195203

196204
// InferencePoolConditionType is a type of status condition for the InferencePool.
@@ -205,7 +213,7 @@ const (
205213
//
206214
// Possible reasons for this condition to be True are:
207215
//
208-
// * "Accepted"
216+
// * "SupportedByParent"
209217
//
210218
// Possible reasons for this condition to be False are:
211219
//
@@ -221,8 +229,9 @@ const (
221229
InferencePoolConditionAccepted InferencePoolConditionType = "Accepted"
222230

223231
// InferencePoolReasonAccepted is a reason used with the "Accepted" condition
224-
// when the InferencePool has been accepted by the Parent.
225-
InferencePoolReasonAccepted InferencePoolReason = "Accepted"
232+
// when the InferencePool is accepted by a Parent because the Parent supports
233+
// InferencePool as a backend.
234+
InferencePoolReasonAccepted InferencePoolReason = "SupportedByParent"
226235

227236
// InferencePoolReasonNotSupportedByParent is a reason used with the "Accepted"
228237
// condition when the InferencePool has not been accepted by a Parent because

api/v1/shared_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ type LabelValue string
132132
// LabelSelector defines a query for resources based on their labels.
133133
// This simplified version uses only the matchLabels field.
134134
type LabelSelector struct {
135-
// matchLabels contains a set of required {key,value} pairs.
135+
// MatchLabels contains a set of required {key,value} pairs.
136136
// An object must match every label in this map to be selected.
137137
// The matching logic is an AND operation on all entries.
138138
//
139139
// +required
140+
// +kubebuilder:validation:MinItems=1
140141
// +kubebuilder:validation:MaxItems=64
141-
MatchLabels map[LabelKey]LabelValue `json:"matchLabels,omitempty" protobuf:"bytes,1,rep,name=matchLabels"`
142+
MatchLabels map[LabelKey]LabelValue `json:"matchLabels"`
142143
}

api/v1/zz_generated.deepcopy.go

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

apix/v1alpha2/inferencepool_conversion.go

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2626
runtime "k8s.io/apimachinery/pkg/runtime"
27+
"k8s.io/utils/ptr"
2728

2829
v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
2930
)
@@ -106,7 +107,7 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error
106107
return nil, err
107108
}
108109

109-
// v1alpha2 uses json:"parent" (singular), v1 uses json:"parents"
110+
// v1alpha2 used json:"parent" (singular) v1 uses json:"parents"
110111
if v, ok := u.Object["parent"]; ok {
111112
u.Object["parents"] = v
112113
delete(u.Object, "parent")
@@ -116,6 +117,17 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error
116117
if err != nil {
117118
return nil, err
118119
}
120+
121+
// Map condition reason string: "Accepted" (v1alpha2) -> "SupportedByParent" (v1)
122+
for i := range out.Parents {
123+
for j := range out.Parents[i].Conditions {
124+
c := &out.Parents[i].Conditions[j]
125+
if c.Type == string(v1.InferencePoolConditionAccepted) &&
126+
c.Reason == string(InferencePoolReasonAccepted) {
127+
c.Reason = string(v1.InferencePoolReasonAccepted)
128+
}
129+
}
130+
}
119131
return out, nil
120132
}
121133

@@ -128,7 +140,7 @@ func convertStatusFromV1(src *v1.InferencePoolStatus) (*InferencePoolStatus, err
128140
return nil, err
129141
}
130142

131-
// v1 uses json:"parents", v1alpha2 uses json:"parent" (singular)
143+
// v1 uses json:"parents"; v1alpha2 used json:"parent" (singular)
132144
if v, ok := u.Object["parents"]; ok {
133145
u.Object["parent"] = v
134146
delete(u.Object, "parents")
@@ -138,6 +150,17 @@ func convertStatusFromV1(src *v1.InferencePoolStatus) (*InferencePoolStatus, err
138150
if err != nil {
139151
return nil, err
140152
}
153+
154+
// Map condition reason string: "SupportedByParent" (v1) -> "Accepted" (v1alpha2)
155+
for i := range out.Parents {
156+
for j := range out.Parents[i].Conditions {
157+
c := &out.Parents[i].Conditions[j]
158+
if c.Type == string(v1.InferencePoolConditionAccepted) &&
159+
c.Reason == string(v1.InferencePoolReasonAccepted) {
160+
c.Reason = string(InferencePoolReasonAccepted)
161+
}
162+
}
163+
}
141164
return out, nil
142165
}
143166

@@ -147,19 +170,17 @@ func convertExtensionRefToV1(src *Extension) (v1.EndpointPickerRef, error) {
147170
return endpointPickerRef, errors.New("src cannot be nil")
148171
}
149172
if src.Group != nil {
150-
v1Group := v1.Group(*src.Group)
151-
endpointPickerRef.Group = &v1Group
173+
endpointPickerRef.Group = ptr.To(v1.Group(*src.Group))
152174
}
153175
if src.Kind != nil {
154-
endpointPickerRef.Kind = v1.Kind(*src.Kind)
176+
endpointPickerRef.Kind = ptr.To(v1.Kind(*src.Kind))
155177
}
156178
endpointPickerRef.Name = v1.ObjectName(src.Name)
157179
if src.PortNumber != nil {
158-
v1PortNumber := v1.PortNumber(*src.PortNumber)
159-
endpointPickerRef.PortNumber = &v1PortNumber
180+
endpointPickerRef.PortNumber = ptr.To(v1.PortNumber(*src.PortNumber))
160181
}
161182
if src.FailureMode != nil {
162-
endpointPickerRef.FailureMode = v1.ExtensionFailureMode(*src.FailureMode)
183+
endpointPickerRef.FailureMode = ptr.To(v1.EndpointPickerFailureMode(*src.FailureMode))
163184
}
164185

165186
return endpointPickerRef, nil
@@ -171,21 +192,17 @@ func convertEndpointPickerRefFromV1(src *v1.EndpointPickerRef) (Extension, error
171192
return extension, errors.New("src cannot be nil")
172193
}
173194
if src.Group != nil {
174-
group := Group(*src.Group)
175-
extension.Group = &group
195+
extension.Group = ptr.To(Group(*src.Group))
176196
}
177-
if src.Kind != "" {
178-
kind := Kind(src.Kind)
179-
extension.Kind = &kind
197+
if src.Kind != nil {
198+
extension.Kind = ptr.To(Kind(*src.Kind))
180199
}
181200
extension.Name = ObjectName(src.Name)
182201
if src.PortNumber != nil {
183-
portNumber := PortNumber(*src.PortNumber)
184-
extension.PortNumber = &portNumber
202+
extension.PortNumber = ptr.To(PortNumber(*src.PortNumber))
185203
}
186-
if src.FailureMode != "" {
187-
extensionFailureMode := ExtensionFailureMode(src.FailureMode)
188-
extension.FailureMode = &extensionFailureMode
204+
if src.FailureMode != nil {
205+
extension.FailureMode = ptr.To(ExtensionFailureMode(*src.FailureMode))
189206
}
190207
return extension, nil
191208
}

apix/v1alpha2/inferencepool_conversion_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333

3434
v1Group = v1.Group("my-group")
3535
v1Kind = v1.Kind("MyKind")
36-
v1FailureMode = v1.ExtensionFailureMode("Deny")
36+
v1FailureMode = v1.EndpointPickerFailureMode("Deny")
3737
v1PortNumber = v1.PortNumber(9000)
3838
)
3939

@@ -102,10 +102,10 @@ func TestInferencePoolConvertTo(t *testing.T) {
102102
TargetPorts: []v1.Port{{Number: v1.PortNumber(int32(8080))}},
103103
EndpointPickerRef: v1.EndpointPickerRef{
104104
Group: &v1Group,
105-
Kind: v1Kind,
105+
Kind: &v1Kind,
106106
Name: "my-epp-service",
107107
PortNumber: &v1PortNumber,
108-
FailureMode: v1FailureMode,
108+
FailureMode: &v1FailureMode,
109109
},
110110
},
111111
Status: v1.InferencePoolStatus{
@@ -311,10 +311,10 @@ func TestInferencePoolConvertFrom(t *testing.T) {
311311
TargetPorts: []v1.Port{{Number: v1.PortNumber(int32(8080))}},
312312
EndpointPickerRef: v1.EndpointPickerRef{
313313
Group: &v1Group,
314-
Kind: v1Kind,
314+
Kind: &v1Kind,
315315
Name: "my-epp-service",
316316
PortNumber: &v1PortNumber,
317-
FailureMode: v1FailureMode,
317+
FailureMode: &v1FailureMode,
318318
},
319319
},
320320
Status: v1.InferencePoolStatus{

client-go/applyconfiguration/api/v1/endpointpickerref.go

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

0 commit comments

Comments
 (0)