Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 11 additions & 7 deletions apix/v1alpha2/inferencepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ 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)),
ParentRef: toV1ParentRef(p.GatewayRef),
}
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
// 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)
ps.Conditions[idx] = cc
}
out.Parents = append(out.Parents, ps)
}
Expand All @@ -133,16 +135,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
144 changes: 110 additions & 34 deletions apix/v1alpha2/inferencepool_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,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 nil status condition",
src: &InferencePool{
TypeMeta: metav1.TypeMeta{
Kind: "InferencePool",
Expand All @@ -147,14 +147,6 @@ func TestInferencePoolConvertTo(t *testing.T) {
Parents: []PoolStatus{
{
GatewayRef: ParentGatewayReference{Name: "my-gateway"},
Conditions: []metav1.Condition{
{
Type: string(InferencePoolConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(InferencePoolReasonAccepted),
LastTransitionTime: timestamp,
},
},
},
},
},
Expand All @@ -180,14 +172,60 @@ 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,
},
},
},
},
},
},
wantErr: false,
},
{
name: "conversion from v1alpha2 to v1 with empty extensionRef and empty status condition",
src: &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{},
},
},
},
},
want: &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{},
},
},
},
Expand Down Expand Up @@ -300,7 +338,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 +360,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 +383,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