Skip to content

Commit d5b9ee3

Browse files
committed
special conversion for default.
1 parent c41ffbe commit d5b9ee3

File tree

2 files changed

+32
-61
lines changed

2 files changed

+32
-61
lines changed

apix/v1alpha2/inferencepool_conversion.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,36 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error
103103
}
104104
for _, p := range src.Parents {
105105
ps := v1.ParentStatus{
106-
ParentRef: toV1ParentRef(p.GatewayRef),
106+
ParentRef: toV1ParentRef(p.GatewayRef),
107+
Conditions: make([]metav1.Condition, 0),
107108
}
108-
if p.Conditions != nil {
109-
ps.Conditions = make([]metav1.Condition, len(p.Conditions))
110-
}
111-
for idx, c := range p.Conditions {
109+
for _, c := range p.Conditions {
112110
cc := c
111+
if isV1Alpha2DefaultConditon(c) {
112+
continue
113+
}
113114
// v1alpha2: "Accepted" -> v1: "SupportedByParent"
114115
if cc.Type == string(v1.InferencePoolConditionAccepted) &&
115116
cc.Reason == string(InferencePoolReasonAccepted) {
116117
cc.Reason = string(v1.InferencePoolReasonAccepted)
117118
}
118-
ps.Conditions[idx] = cc
119+
ps.Conditions = append(ps.Conditions, cc)
120+
}
121+
if len(ps.Conditions) == 0 && len(src.Parents) == 1 {
122+
// Reset the conditions to nil since v1 version does not have default condition.
123+
// Default is only configured when length of src.Parents is 1.
124+
ps.Conditions = nil
119125
}
120126
out.Parents = append(out.Parents, ps)
121127
}
122128
return out, nil
123129
}
124130

131+
func isV1Alpha2DefaultConditon(c metav1.Condition) bool {
132+
return InferencePoolConditionType(c.Type) == InferencePoolConditionAccepted &&
133+
c.Status == metav1.ConditionUnknown && InferencePoolReason(c.Reason) == InferencePoolReasonPending
134+
}
135+
125136
func convertStatusFromV1(src *v1.InferencePoolStatus) (*InferencePoolStatus, error) {
126137
if src == nil {
127138
return nil, errors.New("src cannot be nil")

apix/v1alpha2/inferencepool_conversion_test.go

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ func TestInferencePoolConvertTo(t *testing.T) {
7373
{
7474
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
7575
Conditions: []metav1.Condition{
76+
{ // v1alpha2 default condition is skipped from conversion.
77+
Type: string(v1.InferencePoolConditionAccepted),
78+
Status: metav1.ConditionUnknown,
79+
Reason: string(InferencePoolReasonPending),
80+
LastTransitionTime: timestamp,
81+
},
7682
{
7783
Type: string(InferencePoolConditionAccepted),
7884
Status: metav1.ConditionTrue,
@@ -127,7 +133,7 @@ func TestInferencePoolConvertTo(t *testing.T) {
127133
wantErr: false,
128134
},
129135
{
130-
name: "conversion from v1alpha2 to v1 with empty extensionRef and nil status condition",
136+
name: "conversion from v1alpha2 to v1 with empty extensionRef and default v1alpha2 status condition",
131137
src: &InferencePool{
132138
TypeMeta: metav1.TypeMeta{
133139
Kind: "InferencePool",
@@ -147,6 +153,14 @@ func TestInferencePoolConvertTo(t *testing.T) {
147153
Parents: []PoolStatus{
148154
{
149155
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
156+
Conditions: []metav1.Condition{
157+
{
158+
Type: string(v1.InferencePoolConditionAccepted),
159+
Status: metav1.ConditionUnknown,
160+
Reason: string(InferencePoolReasonPending),
161+
LastTransitionTime: timestamp,
162+
},
163+
},
150164
},
151165
},
152166
},
@@ -178,60 +192,6 @@ func TestInferencePoolConvertTo(t *testing.T) {
178192
},
179193
wantErr: false,
180194
},
181-
{
182-
name: "conversion from v1alpha2 to v1 with empty extensionRef and empty status condition",
183-
src: &InferencePool{
184-
TypeMeta: metav1.TypeMeta{
185-
Kind: "InferencePool",
186-
APIVersion: GroupVersion.String(),
187-
},
188-
ObjectMeta: metav1.ObjectMeta{
189-
Name: "test-pool",
190-
Namespace: "test-ns",
191-
},
192-
Spec: InferencePoolSpec{
193-
Selector: map[LabelKey]LabelValue{
194-
"app": "my-model-server",
195-
},
196-
TargetPortNumber: 8080,
197-
},
198-
Status: InferencePoolStatus{
199-
Parents: []PoolStatus{
200-
{
201-
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
202-
Conditions: []metav1.Condition{},
203-
},
204-
},
205-
},
206-
},
207-
want: &v1.InferencePool{
208-
TypeMeta: metav1.TypeMeta{
209-
Kind: "InferencePool",
210-
APIVersion: v1.GroupVersion.String(),
211-
},
212-
ObjectMeta: metav1.ObjectMeta{
213-
Name: "test-pool",
214-
Namespace: "test-ns",
215-
},
216-
Spec: v1.InferencePoolSpec{
217-
Selector: v1.LabelSelector{
218-
MatchLabels: map[v1.LabelKey]v1.LabelValue{
219-
"app": "my-model-server",
220-
},
221-
},
222-
TargetPorts: []v1.Port{{Number: v1.PortNumber(int32(8080))}},
223-
},
224-
Status: v1.InferencePoolStatus{
225-
Parents: []v1.ParentStatus{
226-
{
227-
ParentRef: v1.ParentReference{Name: "my-gateway"},
228-
Conditions: []metav1.Condition{},
229-
},
230-
},
231-
},
232-
},
233-
wantErr: false,
234-
},
235195
}
236196

237197
for _, tt := range tests {

0 commit comments

Comments
 (0)