Skip to content

Commit

Permalink
revert partition (#218)
Browse files Browse the repository at this point in the history
* revert partition

* do not scale in updated pods first

* poddecoration partition

* poddecoration partition2
  • Loading branch information
ColdsteelRail committed Jun 11, 2024
1 parent 5352192 commit fd4de2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions pkg/controllers/collaset/collaset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ var _ = Describe("collaset controller", func() {
Expect(expectedStatusReplicas(c, cs, 0, 0, 0, 4, 4, 0, 0, 0)).Should(BeNil())

// test update ByPartition
for _, partition := range []int32{0, 1, 2, 3, 4} {
for _, partition := range []int32{4, 3, 2, 1, 0} {
observedGeneration := cs.Status.ObservedGeneration

// update CollaSet image and partition
Expand Down Expand Up @@ -288,7 +288,7 @@ var _ = Describe("collaset controller", func() {
}
// check updated pod replicas by CollaSet status
Eventually(func() error {
return expectedStatusReplicas(c, cs, 0, 0, 0, 4, partition, partition, 0, 0)
return expectedStatusReplicas(c, cs, 0, 0, 0, 4, 4-partition, 4-partition, 0, 0)
}, 5*time.Second, 1*time.Second).Should(BeNil())

// double check updated pod replicas
Expand All @@ -306,7 +306,7 @@ var _ = Describe("collaset controller", func() {
Expect(podStatus.ContainerStates["foo"].LatestImage).Should(BeEquivalentTo("nginx:v2"))
}
}
Expect(updatedReplicas).Should(BeEquivalentTo(partition))
Expect(updatedReplicas).Should(BeEquivalentTo(4 - partition))
}

// mock Pods updated by kubelet
Expand Down Expand Up @@ -669,7 +669,7 @@ var _ = Describe("collaset controller", func() {
Expect(expectedStatusReplicas(c, cs, 0, 0, 0, 4, 4, 0, 0, 0)).Should(BeNil())

// test update ByPartition
for _, partition := range []int32{0, 1, 2, 3, 4} {
for _, partition := range []int32{4, 3, 2, 1, 0} {
observedGeneration := cs.Status.ObservedGeneration

// update CollaSet image and partition
Expand All @@ -690,7 +690,7 @@ var _ = Describe("collaset controller", func() {

// check updated pod replicas by CollaSet status
Eventually(func() error {
return expectedStatusReplicas(c, cs, 0, 0, 0, 4+partition, partition, 0, 0, 0)
return expectedStatusReplicas(c, cs, 0, 0, 0, 8-partition, 4-partition, 0, 0, 0)
}, 30*time.Second, 1*time.Second).Should(BeNil())

// double check updated pod replicas
Expand All @@ -703,7 +703,7 @@ var _ = Describe("collaset controller", func() {
Expect(pod.Labels[appsv1.ControllerRevisionHashLabelKey]).Should(BeEquivalentTo(cs.Status.UpdatedRevision))
}
}
Expect(updatedReplicas).Should(BeEquivalentTo(partition))
Expect(updatedReplicas).Should(BeEquivalentTo(4 - partition))
}

// mock Pods updated by kubelet
Expand Down Expand Up @@ -1630,7 +1630,7 @@ var _ = Describe("collaset controller", func() {
}, 5*time.Second, 1*time.Second).Should(BeTrue())
Expect(c.Get(context.TODO(), types.NamespacedName{Namespace: cs.Namespace, Name: cs.Name}, cs)).Should(BeNil())
Expect(expectedStatusReplicas(c, cs, 0, 0, 0, 3, 3, 0, 0, 0)).Should(BeNil())
for _, partition := range []int32{0, 1, 2, 3} {
for _, partition := range []int32{3, 2, 1, 0} {
Expect(c.Get(context.TODO(), types.NamespacedName{Namespace: cs.Namespace, Name: cs.Name}, cs)).Should(BeNil())
Expect(updateCollaSetWithRetry(c, cs.Namespace, cs.Name, func(cls *appsv1alpha1.CollaSet) bool {
cls.Spec.UpdateStrategy.RollingUpdate = &appsv1alpha1.RollingUpdateCollaSetStrategy{
Expand All @@ -1647,7 +1647,7 @@ var _ = Describe("collaset controller", func() {
Eventually(func() int32 {
Expect(c.Get(context.TODO(), types.NamespacedName{Namespace: cs.Namespace, Name: cs.Name}, cs)).Should(BeNil())
return cs.Status.UpdatedReplicas
}, time.Second*10, time.Second).Should(BeEquivalentTo(partition))
}, time.Second*10, time.Second).Should(BeEquivalentTo(3 - partition))
// allow Pod to do replace
podList := &corev1.PodList{}
Expect(c.List(context.TODO(), podList, client.InNamespace(cs.Namespace))).Should(BeNil())
Expand Down
9 changes: 5 additions & 4 deletions pkg/controllers/collaset/synccontrol/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,16 @@ func decidePodToUpdateByPartition(cls *appsv1alpha1.CollaSet, podInfos []*PodUpd
cls.Spec.UpdateStrategy.RollingUpdate.ByPartition.Partition == nil {
return filteredPodInfos
}
podsNum := len(filteredPodInfos)
ordered := orderByDefault(filteredPodInfos)
sort.Sort(ordered)

partition := int(*cls.Spec.UpdateStrategy.RollingUpdate.ByPartition.Partition)
if partition >= len(filteredPodInfos) {
return filteredPodInfos
if partition >= podsNum {
return podToUpdate
}
podToUpdate = filteredPodInfos[:partition]
for i := partition; i < len(filteredPodInfos); i++ {
podToUpdate = ordered[:podsNum-partition]
for i := podsNum - partition; i < podsNum; i++ {
if podInfos[i].PodDecorationChanged {
podToUpdate = append(podToUpdate, podInfos[i])
}
Expand Down

0 comments on commit fd4de2e

Please sign in to comment.