diff --git a/apix/v1alpha2/inferencepool_conversion.go b/apix/v1alpha2/inferencepool_conversion.go index c470e6281..6f6bc0fbb 100644 --- a/apix/v1alpha2/inferencepool_conversion.go +++ b/apix/v1alpha2/inferencepool_conversion.go @@ -104,10 +104,13 @@ 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) { @@ -115,11 +118,21 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error } 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") @@ -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) } diff --git a/apix/v1alpha2/inferencepool_conversion_test.go b/apix/v1alpha2/inferencepool_conversion_test.go index 5a828dc37..4191e21ea 100644 --- a/apix/v1alpha2/inferencepool_conversion_test.go +++ b/apix/v1alpha2/inferencepool_conversion_test.go @@ -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, @@ -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", @@ -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, }, }, @@ -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, - }, - }, }, }, }, @@ -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", @@ -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, - }, - }, }, }, }, @@ -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{}, }, }, },