Skip to content

Commit 2cea370

Browse files
bugfix: selective scale in both new and origin pods (#315)
* selective scale in both new and origin pods * improve e2e * minor * minor * minor
1 parent 55451ec commit 2cea370

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

pkg/controllers/collaset/synccontrol/scale.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func getPodsToDelete(filteredPods []*collasetutils.PodWrapper, replaceMapping ma
5959

6060
if replacePairPod, exist := replaceMapping[pod.Name]; exist && replacePairPod != nil {
6161
// don't selective scaleIn newPod (and its originPod) until replace finished
62-
if replacePairPod.ToDelete {
62+
if replacePairPod.ToDelete && !pod.ToDelete {
6363
continue
6464
}
6565
// when scaleIn origin Pod, newPod should be deleted if not service available

test/e2e/apps/collaset.go

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ var _ = SIGDescribe("CollaSet", func() {
18311831
}, 30*time.Second, 3*time.Second).Should(BeTrue())
18321832
})
18331833

1834-
framework.ConformanceIt("scaleIn new pod", func() {
1834+
framework.ConformanceIt("scaleIn origin and new pod", func() {
18351835
cls := tester.NewCollaSet("collaset-"+randStr, 1, appsv1alpha1.UpdateStrategy{})
18361836
// use bad image to mock new replace pod unavailable
18371837
cls.Spec.Template.Spec.Containers[0].Image = "nginx:non-exist"
@@ -1848,7 +1848,64 @@ var _ = SIGDescribe("CollaSet", func() {
18481848
pod.Labels[appsv1alpha1.PodReplaceIndicationLabelKey] = "true"
18491849
})).NotTo(HaveOccurred())
18501850

1851-
By("Wait for replace new pod created")
1851+
By("Wait for new pod created by OperationJob")
1852+
Eventually(func() error { return tester.ExpectedStatusReplicas(cls, 2, 0, 0, 2, 2) }, 30*time.Second, 3*time.Second).ShouldNot(HaveOccurred())
1853+
1854+
By("scaleIn the specified new pod")
1855+
pods, err = tester.ListPodsForCollaSet(cls)
1856+
Expect(err).NotTo(HaveOccurred())
1857+
var newPod *v1.Pod
1858+
for _, pod := range pods {
1859+
if pod.Name != podToReplace.Name {
1860+
newPod = pod
1861+
break
1862+
}
1863+
}
1864+
Expect(tester.UpdateCollaSet(cls, func(cls *appsv1alpha1.CollaSet) {
1865+
cls.Spec.Replicas = int32Pointer(0)
1866+
cls.Spec.ScaleStrategy = appsv1alpha1.ScaleStrategy{
1867+
PodToDelete: []string{newPod.Name, podToReplace.Name},
1868+
}
1869+
})).NotTo(HaveOccurred())
1870+
1871+
By("Wait for CollaSet reconciled")
1872+
Eventually(func() bool {
1873+
if err := tester.GetCollaSet(cls); err != nil {
1874+
return false
1875+
}
1876+
return cls.Generation == cls.Status.ObservedGeneration
1877+
}, 10*time.Second, 3*time.Second).Should(Equal(true))
1878+
1879+
By("Wait for pods deleted")
1880+
Eventually(func() error { return tester.ExpectedStatusReplicas(cls, 0, 0, 0, 0, 0) }, 30*time.Second, 3*time.Second).ShouldNot(HaveOccurred())
1881+
1882+
By("Check resourceContext")
1883+
var currResourceContexts []*appsv1alpha1.ResourceContext
1884+
Eventually(func() bool {
1885+
currResourceContexts, err = tester.ListResourceContextsForCollaSet(cls)
1886+
Expect(err).Should(BeNil())
1887+
return len(currResourceContexts) == 0
1888+
}, 30*time.Second, 3*time.Second).Should(BeTrue())
1889+
})
1890+
1891+
framework.ConformanceIt("scaleIn new pod only", func() {
1892+
cls := tester.NewCollaSet("collaset-"+randStr, 1, appsv1alpha1.UpdateStrategy{})
1893+
// use bad image to mock new replace pod unavailable
1894+
cls.Spec.Template.Spec.Containers[0].Image = "nginx:non-exist"
1895+
Expect(tester.CreateCollaSet(cls)).NotTo(HaveOccurred())
1896+
1897+
By("Wait for status replicas satisfied")
1898+
Eventually(func() error { return tester.ExpectedStatusReplicas(cls, 1, 0, 0, 1, 1) }, 30*time.Second, 3*time.Second).ShouldNot(HaveOccurred())
1899+
1900+
By("Replace pod by label")
1901+
pods, err := tester.ListPodsForCollaSet(cls)
1902+
Expect(err).NotTo(HaveOccurred())
1903+
podToReplace := pods[0]
1904+
Expect(tester.UpdatePod(podToReplace, func(pod *v1.Pod) {
1905+
pod.Labels[appsv1alpha1.PodReplaceIndicationLabelKey] = "true"
1906+
})).NotTo(HaveOccurred())
1907+
1908+
By("Wait for new pod created by OperationJob")
18521909
Eventually(func() error { return tester.ExpectedStatusReplicas(cls, 2, 0, 0, 2, 2) }, 30*time.Second, 3*time.Second).ShouldNot(HaveOccurred())
18531910

18541911
By("Selective scaleIn new pod")

0 commit comments

Comments
 (0)