Skip to content

Commit

Permalink
getPodsToDelete(): delete the pods in ScaleInOpsLifecycleAdapter first (
Browse files Browse the repository at this point in the history
#158)

* filter pods not in OPS when scaleIn

* scale in unit test

* enhance scale in unit test
  • Loading branch information
ColdsteelRail committed Mar 1, 2024
1 parent dbbb7e3 commit d146ad4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion pkg/controllers/collaset/collaset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ var _ = Describe("collaset controller", func() {

// scale in pods with delay seconds
Expect(updateCollaSetWithRetry(c, cs.Namespace, cs.Name, func(cls *appsv1alpha1.CollaSet) bool {
cls.Spec.Replicas = int32Pointer(0)
cls.Spec.Replicas = int32Pointer(1)
cls.Spec.ScaleStrategy.OperationDelaySeconds = int32Pointer(1)
return true
})).Should(BeNil())
Expand All @@ -168,6 +168,23 @@ var _ = Describe("collaset controller", func() {
})).Should(BeNil())
}

Eventually(func() error {
Expect(c.List(context.TODO(), podList, client.InNamespace(cs.Namespace))).Should(BeNil())
if len(podList.Items) != 1 {
return fmt.Errorf("expected 1 pods, got %d", len(podList.Items))
}

Expect(c.Get(context.TODO(), types.NamespacedName{Namespace: cs.Namespace, Name: cs.Name}, cs)).Should(BeNil())
return expectedStatusReplicas(c, cs, 0, 0, 0, 1, 1, 0, 0, 0)
}, 5*time.Second, 1*time.Second).Should(BeNil())

// scale in pods with delay seconds
Expect(updateCollaSetWithRetry(c, cs.Namespace, cs.Name, func(cls *appsv1alpha1.CollaSet) bool {
cls.Spec.Replicas = int32Pointer(0)
cls.Spec.ScaleStrategy.OperationDelaySeconds = int32Pointer(1)
return true
}))

Eventually(func() error {
Expect(c.List(context.TODO(), podList, client.InNamespace(cs.Namespace))).Should(BeNil())
if len(podList.Items) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/collaset/synccontrol/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (s ActivePodsForDeletion) Less(i, j int) bool {
rDuringScaleIn := podopslifecycle.IsDuringOps(collasetutils.ScaleInOpsLifecycleAdapter, r)

if lDuringScaleIn && !rDuringScaleIn {
return true
return false
}

if !lDuringScaleIn && rDuringScaleIn {
return false
return true
}

return collasetutils.ComparePod(l.Pod, r.Pod)
Expand Down

0 comments on commit d146ad4

Please sign in to comment.