Skip to content

Commit 20b8deb

Browse files
committed
Refactors InferencePool v1 Status
Signed-off-by: Daneyon Hansen <[email protected]>
1 parent 137a0b4 commit 20b8deb

File tree

9 files changed

+255
-130
lines changed

9 files changed

+255
-130
lines changed

api/v1/inferencepool_types.go

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ type InferencePool struct {
3838
// +required
3939
Spec InferencePoolSpec `json:"spec,omitzero"`
4040

41-
// Status defines the observed state of InferencePool.
41+
// Status defines the observed state of the InferencePool.
4242
//
43-
// +kubebuilder:default={parent: {{parentRef: {kind: "Status", name: "default"}, conditions: {{type: "Accepted", status: "Unknown", reason: "Pending", message: "Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}}}
4443
// +optional
4544
Status InferencePoolStatus `json:"status,omitzero"`
4645
}
@@ -145,57 +144,59 @@ const (
145144
FailClose ExtensionFailureMode = "FailClose"
146145
)
147146

148-
// InferencePoolStatus defines the observed state of InferencePool.
149-
// +kubebuilder:validation:MinProperties=1
147+
// InferencePoolStatus defines the observed state of the InferencePool.
150148
type InferencePoolStatus struct {
151-
// Parents is a list of parent resources (usually Gateways) that are
152-
// associated with the InferencePool, and the status of the InferencePool with respect to
153-
// each parent.
149+
// Parents is a list of parent resources, typically Gateways, that are associated with
150+
// the InferencePool, and the status of the InferencePool with respect to each parent.
154151
//
155-
// A maximum of 32 Gateways will be represented in this list. When the list contains
156-
// `kind: Status, name: default`, it indicates that the InferencePool is not
157-
// associated with any Gateway and a controller must perform the following:
152+
// A controller that manages the InferencePool, must add an entry for each parent it manages
153+
// and remove the parent entry when the controller no longer considers the InferencePool to
154+
// be associated with that parent.
158155
//
159-
// - Remove the parent when setting the "Accepted" condition.
160-
// - Add the parent when the controller will no longer manage the InferencePool
161-
// and no other parents exist.
156+
// A maximum of 32 parents will be represented in this list. When the list is empty,
157+
// it indicates that the InferencePool is not associated with any parents.
162158
//
163159
// +kubebuilder:validation:MaxItems=32
164160
// +optional
165161
// +listType=atomic
166162
Parents []PoolStatus `json:"parent,omitempty"`
167163
}
168164

169-
// PoolStatus defines the observed state of InferencePool from a Gateway.
165+
// PoolStatus defines the observed state of the InferencePool.
170166
type PoolStatus struct {
171-
// Conditions track the state of the InferencePool.
167+
// Conditions is a list of status conditions that provide information about the observed
168+
// state of the InferencePool. This field is required to be set by the controller that
169+
// manages the InferencePool.
172170
//
173171
// Known condition types are:
174172
//
175173
// * "Accepted"
176174
// * "ResolvedRefs"
177175
//
178-
// +optional
176+
// +required
179177
// +listType=map
180178
// +listMapKey=type
179+
// +kubebuilder:validation:MinItems=1
181180
// +kubebuilder:validation:MaxItems=8
182-
// +kubebuilder:default={{type: "Accepted", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
183-
Conditions []metav1.Condition `json:"conditions,omitempty"`
181+
Conditions []metav1.Condition `json:"conditions"`
184182

185-
// GatewayRef indicates the gateway that observed state of InferencePool.
183+
// ParentRef is used to identify the parent resource that this status
184+
// is associated with. It is used to match the InferencePool with the parent
185+
// resource, such as a Gateway.
186+
//
186187
// +required
187-
GatewayRef ParentGatewayReference `json:"parentRef,omitzero"`
188+
ParentRef ParentReference `json:"parentRef"`
188189
}
189190

190-
// InferencePoolConditionType is a type of condition for the InferencePool
191+
// InferencePoolConditionType is a type of status condition for the InferencePool.
191192
type InferencePoolConditionType string
192193

193-
// InferencePoolReason is the reason for a given InferencePoolConditionType
194+
// InferencePoolReason is the reason for a type of InferencePool status condition.
194195
type InferencePoolReason string
195196

196197
const (
197-
// This condition indicates whether the InferencePool has been accepted or rejected
198-
// by a Gateway, and why.
198+
// InferencePoolConditionAccepted is a type of condition that indicates whether
199+
// the InferencePool has been accepted or rejected by a Gateway, and why.
199200
//
200201
// Possible reasons for this condition to be True are:
201202
//
@@ -214,18 +215,19 @@ const (
214215
// prefer to use the reasons listed above to improve interoperability.
215216
InferencePoolConditionAccepted InferencePoolConditionType = "Accepted"
216217

217-
// This reason is used with the "Accepted" condition when the InferencePool has been
218-
// accepted by the Gateway.
218+
// InferencePoolReasonAccepted is a reason used with the "Accepted" condition
219+
// when the InferencePool has been accepted by the Gateway.
219220
InferencePoolReasonAccepted InferencePoolReason = "Accepted"
220221

221-
// This reason is used with the "Accepted" condition when the InferencePool
222-
// has not been accepted by a Gateway because the Gateway does not support
223-
// InferencePool as a backend.
222+
// InferencePoolReasonNotSupportedByGateway is a reason used with the "Accepted"
223+
// condition when the InferencePool has not been accepted by a Gateway because
224+
// the Gateway does not support InferencePool as a backend.
224225
InferencePoolReasonNotSupportedByGateway InferencePoolReason = "NotSupportedByGateway"
225226

226-
// This reason is used with the "Accepted" condition when the InferencePool is
227-
// referenced by an HTTPRoute that has been rejected by the Gateway. The user
228-
// should inspect the status of the referring HTTPRoute for the specific reason.
227+
// InferencePoolReasonHTTPRouteNotAccepted is a reason used with the "Accepted"
228+
// condition when the InferencePool is referenced by an HTTPRoute that has been
229+
// rejected by the Gateway. The user should inspect the status of the referring
230+
// HTTPRoute for the specific reason.
229231
InferencePoolReasonHTTPRouteNotAccepted InferencePoolReason = "HTTPRouteNotAccepted"
230232

231233
// This reason is used with the "Accepted" when a controller has not yet
@@ -234,8 +236,8 @@ const (
234236
)
235237

236238
const (
237-
// This condition indicates whether the controller was able to resolve all
238-
// the object references for the InferencePool.
239+
// InferencePoolConditionResolvedRefs is a type of condition that indicates whether
240+
// the controller was able to resolve all the object references for the InferencePool.
239241
//
240242
// Possible reasons for this condition to be True are:
241243
//
@@ -249,39 +251,42 @@ const (
249251
// prefer to use the reasons listed above to improve interoperability.
250252
InferencePoolConditionResolvedRefs InferencePoolConditionType = "ResolvedRefs"
251253

252-
// This reason is used with the "ResolvedRefs" condition when the condition
253-
// is true.
254+
// InferencePoolReasonResolvedRefs is a reason used with the "ResolvedRefs"
255+
// condition when the condition is true.
254256
InferencePoolReasonResolvedRefs InferencePoolReason = "ResolvedRefs"
255257

256-
// This reason is used with the "ResolvedRefs" condition when the
257-
// Extension is invalid in some way. This can include an unsupported kind
258-
// or API group, or a reference to a resource that can not be found.
258+
// InferencePoolReasonInvalidExtensionRef is a reason used with the "ResolvedRefs"
259+
// condition when the Extension is invalid in some way. This can include an
260+
// unsupported kind or API group, or a reference to a resource that cannot be found.
259261
InferencePoolReasonInvalidExtensionRef InferencePoolReason = "InvalidExtensionRef"
260262
)
261263

262-
// ParentGatewayReference identifies an API object including its namespace,
263-
// defaulting to Gateway.
264-
type ParentGatewayReference struct {
265-
// Group is the group of the referent.
264+
// ParentReference identifies an API object. It is used to associate the InferencePool with a
265+
// parent resource, such as a Gateway.
266+
type ParentReference struct {
267+
// Group is the group of the referent API object. When unspecified, the referent is assumed
268+
// to be in the "gateway.networking.k8s.io" API group.
266269
//
267270
// +optional
268271
// +kubebuilder:default="gateway.networking.k8s.io"
269272
Group *Group `json:"group,omitempty"`
270273

271-
// Kind is kind of the referent. For example "Gateway".
274+
// Kind is the kind of the referent API object. When unspecified, the referent is assumed
275+
// to be a "Gateway" kind.
272276
//
273277
// +optional
274278
// +kubebuilder:default=Gateway
275-
Kind Kind `json:"kind,omitempty"`
279+
Kind *Kind `json:"kind,omitempty"`
276280

277-
// Name is the name of the referent.
281+
// Name is the name of the referent API object.
282+
//
278283
// +required
279-
Name ObjectName `json:"name,omitempty"`
284+
Name ObjectName `json:"name"`
280285

281-
// Namespace is the namespace of the referent. If not present,
282-
// the namespace of the referent is assumed to be the same as
283-
// the namespace of the referring object.
286+
// Namespace is the namespace of the referent API object. When unspecified,
287+
// the namespace of the referent is assumed to be the same as the namespace
288+
// of the referring object.
284289
//
285290
// +optional
286-
Namespace Namespace `json:"namespace,omitempty"`
291+
Namespace *Namespace `json:"namespace,omitempty"`
287292
}

api/v1/zz_generated.deepcopy.go

Lines changed: 15 additions & 5 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: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package v1alpha2
1919
import (
2020
"errors"
2121
"fmt"
22+
"time"
2223

24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2325
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2426
runtime "k8s.io/apimachinery/pkg/runtime"
2527

@@ -39,11 +41,20 @@ func (src *InferencePool) ConvertTo(dst *v1.InferencePool) error {
3941
if err != nil {
4042
return err
4143
}
42-
dst.TypeMeta = src.TypeMeta
44+
45+
// v1 requires at least one condition per parent.
46+
ensureV1StatusConditionsMinimum(v1Status)
47+
48+
meta := metav1.TypeMeta{
49+
Kind: src.Kind,
50+
APIVersion: v1.GroupVersion.Version, // Ensure the API version is set correctly.
51+
}
52+
dst.TypeMeta = meta
4353
dst.ObjectMeta = src.ObjectMeta
4454
dst.Spec.TargetPorts = []v1.Port{{Number: v1.PortNumber(src.Spec.TargetPortNumber)}}
4555
dst.Spec.EndpointPickerRef = endpointPickRef
4656
dst.Status = *v1Status
57+
4758
if src.Spec.Selector != nil {
4859
dst.Spec.Selector.MatchLabels = make(map[v1.LabelKey]v1.LabelValue, len(src.Spec.Selector))
4960
for k, v := range src.Spec.Selector {
@@ -66,11 +77,17 @@ func (dst *InferencePool) ConvertFrom(src *v1.InferencePool) error {
6677
if err != nil {
6778
return err
6879
}
69-
dst.TypeMeta = src.TypeMeta
80+
81+
meta := metav1.TypeMeta{
82+
Kind: src.Kind,
83+
APIVersion: GroupVersion.Version, // Ensure the API version is set correctly.
84+
}
85+
dst.TypeMeta = meta
7086
dst.ObjectMeta = src.ObjectMeta
7187
dst.Spec.TargetPortNumber = int32(src.Spec.TargetPorts[0].Number)
7288
dst.Spec.ExtensionRef = extensionRef
7389
dst.Status = *status
90+
7491
if src.Spec.Selector.MatchLabels != nil {
7592
dst.Spec.Selector = make(map[LabelKey]LabelValue, len(src.Spec.Selector.MatchLabels))
7693
for k, v := range src.Spec.Selector.MatchLabels {
@@ -88,7 +105,11 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error
88105
if err != nil {
89106
return nil, err
90107
}
91-
return convert[v1.InferencePoolStatus](u)
108+
out, err := convert[v1.InferencePoolStatus](u)
109+
if err != nil {
110+
return nil, err
111+
}
112+
return out, nil
92113
}
93114

94115
func convertStatusFromV1(src *v1.InferencePoolStatus) (*InferencePoolStatus, error) {
@@ -166,3 +187,23 @@ func convert[T any](u *unstructured.Unstructured) (*T, error) {
166187
}
167188
return &res, nil
168189
}
190+
191+
// Ensure v1's PoolStatus.Conditions has at least one entry.
192+
func ensureV1StatusConditionsMinimum(s *v1.InferencePoolStatus) {
193+
if s == nil {
194+
return
195+
}
196+
epoch := metav1.NewTime(time.Unix(0, 0))
197+
for i := range s.Parents {
198+
ps := &s.Parents[i]
199+
if len(ps.Conditions) == 0 {
200+
ps.Conditions = []metav1.Condition{{
201+
Type: string(v1.InferencePoolConditionAccepted),
202+
Status: metav1.ConditionUnknown,
203+
Reason: string(v1.InferencePoolReasonPending),
204+
Message: "Waiting for controller",
205+
LastTransitionTime: epoch,
206+
}}
207+
}
208+
}
209+
}

0 commit comments

Comments
 (0)