nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: spidernet-io/spiderpool
Pull request #1668 (2023-04-14 08:36:30)

title:	add kubernetes StatefulSet Start ordinal support
robot cherry pick pr <https://github.com/spidernet-io/spiderpool/pull/1667> to branch release-v0.4,  action <https://github.com/spidernet-io/spiderpool/actions/runs/4697966148>  , commits 47d5925ec60638042ca93189edfcae16e60cbed4  


Patch:
diff --git a/pkg/statefulsetmanager/sts_manager.go b/pkg/statefulsetmanager/sts_manager.go
index b1b872d4c..da854dfe6 100644
--- a/pkg/statefulsetmanager/sts_manager.go
+++ b/pkg/statefulsetmanager/sts_manager.go
@@ -85,6 +85,16 @@ func (sm *statefulSetManager) IsValidStatefulSetPod(ctx context.Context, namespa
 		return false, client.IgnoreNotFound(err)
 	}
 
+	// Ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#start-ordinal
+	if sts.Spec.Ordinals != nil {
+		startIndex := int(sts.Spec.Ordinals.Start)
+		endIndex := startIndex + int(*sts.Spec.Replicas) - 1
+		if startIndex <= replicas && replicas <= endIndex {
+			return true, nil
+		}
+		return false, nil
+	}
+
 	// The Pod controlled by StatefulSet is created or re-created.
 	if replicas <= int(*sts.Spec.Replicas)-1 {
 		return true, nil


Test patch:
diff --git a/pkg/statefulsetmanager/sts_manager_test.go b/pkg/statefulsetmanager/sts_manager_test.go
index 5b12fb1f0..ed0a89c74 100644
--- a/pkg/statefulsetmanager/sts_manager_test.go
+++ b/pkg/statefulsetmanager/sts_manager_test.go
@@ -278,6 +278,30 @@ var _ = Describe("StatefulSetManager", Label("sts_manager_test"), func() {
 				Expect(err).NotTo(HaveOccurred())
 				Expect(valid).To(BeTrue())
 			})
+
+			It("invalid pod mismatches the StatefulSet start ordinal", func() {
+				stsT.Spec.Replicas = pointer.Int32(1)
+				stsT.Spec.Ordinals = &appsv1.StatefulSetOrdinals{Start: 2}
+
+				err := tracker.Add(stsT)
+				Expect(err).NotTo(HaveOccurred())
+
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 0), constant.KindStatefulSet)
+				Expect(err).NotTo(HaveOccurred())
+				Expect(valid).To(BeFalse())
+			})
+
+			It("a valid pod matches the StatefulSet start ordinal", func() {
+				stsT.Spec.Replicas = pointer.Int32(1)
+				stsT.Spec.Ordinals = &appsv1.StatefulSetOrdinals{Start: 2}
+
+				err := tracker.Add(stsT)
+				Expect(err).NotTo(HaveOccurred())
+
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 2), constant.KindStatefulSet)
+				Expect(err).NotTo(HaveOccurred())
+				Expect(valid).To(BeTrue())
+			})
 		})
 	})
 })