Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions apix/v1alpha2/inferencepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,35 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error
for _, p := range src.Parents {
ps := v1.ParentStatus{
ParentRef: toV1ParentRef(p.GatewayRef),
Conditions: make([]metav1.Condition, 0, len(p.Conditions)),
Conditions: make([]metav1.Condition, 0),
}
for _, c := range p.Conditions {
cc := c
if isV1Alpha2DefaultConditon(c) {
continue
}
// v1alpha2: "Accepted" -> v1: "SupportedByParent"
if cc.Type == string(v1.InferencePoolConditionAccepted) &&
cc.Reason == string(InferencePoolReasonAccepted) {
cc.Reason = string(v1.InferencePoolReasonAccepted)
}
ps.Conditions = append(ps.Conditions, cc)
}
if len(ps.Conditions) == 0 && len(src.Parents) == 1 {
// Reset the conditions to nil since v1 version does not have default condition.
// Default is only configured when length of src.Parents is 1.
ps.Conditions = nil
}
out.Parents = append(out.Parents, ps)
}
return out, nil
}

func isV1Alpha2DefaultConditon(c metav1.Condition) bool {
return InferencePoolConditionType(c.Type) == InferencePoolConditionAccepted &&
c.Status == metav1.ConditionUnknown && InferencePoolReason(c.Reason) == InferencePoolReasonPending
}

func convertStatusFromV1(src *v1.InferencePoolStatus) (*InferencePoolStatus, error) {
if src == nil {
return nil, errors.New("src cannot be nil")
Expand All @@ -133,16 +146,18 @@ func convertStatusFromV1(src *v1.InferencePoolStatus) (*InferencePoolStatus, err
for _, p := range src.Parents {
ps := PoolStatus{
GatewayRef: fromV1ParentRef(p.ParentRef),
Conditions: make([]metav1.Condition, 0, len(p.Conditions)),
}
for _, c := range p.Conditions {
if p.Conditions != nil {
ps.Conditions = make([]metav1.Condition, len(p.Conditions))
}
for idx, c := range p.Conditions {
cc := c
// v1: "SupportedByParent" -> v1alpha2: "Accepted"
if cc.Type == string(v1.InferencePoolConditionAccepted) &&
cc.Reason == string(v1.InferencePoolReasonAccepted) {
cc.Reason = string(InferencePoolReasonAccepted)
}
ps.Conditions = append(ps.Conditions, cc)
ps.Conditions[idx] = cc
}
out.Parents = append(out.Parents, ps)
}
Expand Down
94 changes: 65 additions & 29 deletions apix/v1alpha2/inferencepool_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func TestInferencePoolConvertTo(t *testing.T) {
{
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
Conditions: []metav1.Condition{
{ // v1alpha2 default condition is skipped from conversion.
Type: string(v1.InferencePoolConditionAccepted),
Status: metav1.ConditionUnknown,
Reason: string(InferencePoolReasonPending),
LastTransitionTime: timestamp,
},
{
Type: string(InferencePoolConditionAccepted),
Status: metav1.ConditionTrue,
Expand Down Expand Up @@ -127,7 +133,7 @@ func TestInferencePoolConvertTo(t *testing.T) {
wantErr: false,
},
{
name: "conversion from v1alpha2 to v1 with empty extensionRef",
name: "conversion from v1alpha2 to v1 with empty extensionRef and default v1alpha2 status condition",
src: &InferencePool{
TypeMeta: metav1.TypeMeta{
Kind: "InferencePool",
Expand All @@ -149,9 +155,9 @@ func TestInferencePoolConvertTo(t *testing.T) {
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
Conditions: []metav1.Condition{
{
Type: string(InferencePoolConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(InferencePoolReasonAccepted),
Type: string(v1.InferencePoolConditionAccepted),
Status: metav1.ConditionUnknown,
Reason: string(InferencePoolReasonPending),
LastTransitionTime: timestamp,
},
},
Expand Down Expand Up @@ -180,14 +186,6 @@ func TestInferencePoolConvertTo(t *testing.T) {
Parents: []v1.ParentStatus{
{
ParentRef: v1.ParentReference{Name: "my-gateway"},
Conditions: []metav1.Condition{
{
Type: string(v1.InferencePoolConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(v1.InferencePoolReasonAccepted),
LastTransitionTime: timestamp,
},
},
},
},
},
Expand Down Expand Up @@ -300,7 +298,7 @@ func TestInferencePoolConvertFrom(t *testing.T) {
wantErr: false,
},
{
name: "conversion from v1 to v1alpha2 with empty extensionRef",
name: "conversion from v1 to v1alpha2 with empty extensionRef and nil status condition",
src: &v1.InferencePool{
TypeMeta: metav1.TypeMeta{
Kind: "InferencePool",
Expand All @@ -322,14 +320,6 @@ func TestInferencePoolConvertFrom(t *testing.T) {
Parents: []v1.ParentStatus{
{
ParentRef: v1.ParentReference{Name: "my-gateway"},
Conditions: []metav1.Condition{
{
Type: string(v1.InferencePoolConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(v1.InferencePoolReasonAccepted),
LastTransitionTime: timestamp,
},
},
},
},
},
Expand All @@ -353,14 +343,60 @@ func TestInferencePoolConvertFrom(t *testing.T) {
Parents: []PoolStatus{
{
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
Conditions: []metav1.Condition{
{
Type: string(InferencePoolConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(InferencePoolReasonAccepted),
LastTransitionTime: timestamp,
},
},
},
},
},
},
wantErr: false,
},
{
name: "conversion from v1 to v1alpha2 with empty extensionRef and empty status condition",
src: &v1.InferencePool{
TypeMeta: metav1.TypeMeta{
Kind: "InferencePool",
APIVersion: v1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-pool",
Namespace: "test-ns",
},
Spec: v1.InferencePoolSpec{
Selector: v1.LabelSelector{
MatchLabels: map[v1.LabelKey]v1.LabelValue{
"app": "my-model-server",
},
},
TargetPorts: []v1.Port{{Number: v1.PortNumber(int32(8080))}},
},
Status: v1.InferencePoolStatus{
Parents: []v1.ParentStatus{
{
ParentRef: v1.ParentReference{Name: "my-gateway"},
Conditions: []metav1.Condition{},
},
},
},
},
want: &InferencePool{
TypeMeta: metav1.TypeMeta{
Kind: "InferencePool",
APIVersion: GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-pool",
Namespace: "test-ns",
},
Spec: InferencePoolSpec{
Selector: map[LabelKey]LabelValue{
"app": "my-model-server",
},
TargetPortNumber: 8080,
},
Status: InferencePoolStatus{
Parents: []PoolStatus{
{
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
Conditions: []metav1.Condition{},
},
},
},
Expand Down