From 3ea69da9979323eb63f398b9386ca6baae740240 Mon Sep 17 00:00:00 2001 From: Bob Tian Date: Mon, 25 Aug 2025 15:50:13 +0000 Subject: [PATCH 1/3] remove empty condition list when doing conversion. --- apix/v1alpha2/inferencepool_conversion.go | 4 +-- .../v1alpha2/inferencepool_conversion_test.go | 36 ++----------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/apix/v1alpha2/inferencepool_conversion.go b/apix/v1alpha2/inferencepool_conversion.go index c470e6281..49f946c3d 100644 --- a/apix/v1alpha2/inferencepool_conversion.go +++ b/apix/v1alpha2/inferencepool_conversion.go @@ -103,8 +103,7 @@ 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 { cc := c @@ -133,7 +132,6 @@ 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 { cc := c diff --git a/apix/v1alpha2/inferencepool_conversion_test.go b/apix/v1alpha2/inferencepool_conversion_test.go index 5a828dc37..019528af6 100644 --- a/apix/v1alpha2/inferencepool_conversion_test.go +++ b/apix/v1alpha2/inferencepool_conversion_test.go @@ -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 empty status condition", src: &InferencePool{ TypeMeta: metav1.TypeMeta{ Kind: "InferencePool", @@ -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, - }, - }, }, }, }, @@ -180,14 +172,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 +284,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 empty status condition", src: &v1.InferencePool{ TypeMeta: metav1.TypeMeta{ Kind: "InferencePool", @@ -322,14 +306,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 +329,6 @@ 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, - }, - }, }, }, }, From c41ffbee57fbc9c88d229c928ddad23106722944 Mon Sep 17 00:00:00 2001 From: Bob Tian Date: Mon, 25 Aug 2025 17:11:46 +0000 Subject: [PATCH 2/3] empty to empty and nil to nil. --- apix/v1alpha2/inferencepool_conversion.go | 14 ++- .../v1alpha2/inferencepool_conversion_test.go | 112 +++++++++++++++++- 2 files changed, 120 insertions(+), 6 deletions(-) diff --git a/apix/v1alpha2/inferencepool_conversion.go b/apix/v1alpha2/inferencepool_conversion.go index 49f946c3d..bbee5923b 100644 --- a/apix/v1alpha2/inferencepool_conversion.go +++ b/apix/v1alpha2/inferencepool_conversion.go @@ -105,14 +105,17 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error ps := v1.ParentStatus{ 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) } @@ -133,14 +136,17 @@ func convertStatusFromV1(src *v1.InferencePoolStatus) (*InferencePoolStatus, err ps := PoolStatus{ GatewayRef: fromV1ParentRef(p.ParentRef), } - 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 019528af6..5d499f5da 100644 --- a/apix/v1alpha2/inferencepool_conversion_test.go +++ b/apix/v1alpha2/inferencepool_conversion_test.go @@ -127,7 +127,7 @@ func TestInferencePoolConvertTo(t *testing.T) { wantErr: false, }, { - name: "conversion from v1alpha2 to v1 with empty extensionRef and empty status condition", + name: "conversion from v1alpha2 to v1 with empty extensionRef and nil status condition", src: &InferencePool{ TypeMeta: metav1.TypeMeta{ Kind: "InferencePool", @@ -178,6 +178,60 @@ func TestInferencePoolConvertTo(t *testing.T) { }, 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{}, + }, + }, + }, + }, + wantErr: false, + }, } for _, tt := range tests { @@ -284,7 +338,7 @@ func TestInferencePoolConvertFrom(t *testing.T) { wantErr: false, }, { - name: "conversion from v1 to v1alpha2 with empty extensionRef and empty status condition", + name: "conversion from v1 to v1alpha2 with empty extensionRef and nil status condition", src: &v1.InferencePool{ TypeMeta: metav1.TypeMeta{ Kind: "InferencePool", @@ -335,6 +389,60 @@ func TestInferencePoolConvertFrom(t *testing.T) { }, 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{}, + }, + }, + }, + }, + wantErr: false, + }, { name: "nil source", src: nil, From d5b9ee374156a7a39259786598b68ce392a21bb3 Mon Sep 17 00:00:00 2001 From: Bob Tian Date: Mon, 25 Aug 2025 20:32:18 +0000 Subject: [PATCH 3/3] special conversion for default. --- apix/v1alpha2/inferencepool_conversion.go | 23 ++++-- .../v1alpha2/inferencepool_conversion_test.go | 70 ++++--------------- 2 files changed, 32 insertions(+), 61 deletions(-) diff --git a/apix/v1alpha2/inferencepool_conversion.go b/apix/v1alpha2/inferencepool_conversion.go index bbee5923b..6f6bc0fbb 100644 --- a/apix/v1alpha2/inferencepool_conversion.go +++ b/apix/v1alpha2/inferencepool_conversion.go @@ -103,25 +103,36 @@ func convertStatusToV1(src *InferencePoolStatus) (*v1.InferencePoolStatus, error } for _, p := range src.Parents { ps := v1.ParentStatus{ - ParentRef: toV1ParentRef(p.GatewayRef), + ParentRef: toV1ParentRef(p.GatewayRef), + Conditions: make([]metav1.Condition, 0), } - if p.Conditions != nil { - ps.Conditions = make([]metav1.Condition, len(p.Conditions)) - } - for idx, c := range p.Conditions { + 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[idx] = cc + 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") diff --git a/apix/v1alpha2/inferencepool_conversion_test.go b/apix/v1alpha2/inferencepool_conversion_test.go index 5d499f5da..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 and nil status condition", + name: "conversion from v1alpha2 to v1 with empty extensionRef and default v1alpha2 status condition", src: &InferencePool{ TypeMeta: metav1.TypeMeta{ Kind: "InferencePool", @@ -147,6 +153,14 @@ func TestInferencePoolConvertTo(t *testing.T) { Parents: []PoolStatus{ { GatewayRef: ParentGatewayReference{Name: "my-gateway"}, + Conditions: []metav1.Condition{ + { + Type: string(v1.InferencePoolConditionAccepted), + Status: metav1.ConditionUnknown, + Reason: string(InferencePoolReasonPending), + LastTransitionTime: timestamp, + }, + }, }, }, }, @@ -178,60 +192,6 @@ func TestInferencePoolConvertTo(t *testing.T) { }, 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{}, - }, - }, - }, - }, - wantErr: false, - }, } for _, tt := range tests {