Skip to content

Commit 7b02094

Browse files
feat: decide revision for scale out replicas (#351)
* feat: scaleOut using currentRevision by default * use xset main * enhance ut * enhance ut * fix updater * fix diff * revert
1 parent 09137fd commit 7b02094

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
2525
kusionstack.io/kube-api v0.7.4-0.20250909095208-496f60eea9b5
2626
kusionstack.io/kube-utils v0.2.1-0.20251120063041-6043805ee00d
27-
kusionstack.io/kube-xset v0.0.0-20251111060928-069410a15229
27+
kusionstack.io/kube-xset v0.0.2-0.20251127122852-ae98b507b2cc
2828
kusionstack.io/resourceconsist v0.0.1
2929
sigs.k8s.io/controller-runtime v0.17.3
3030
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,8 @@ kusionstack.io/kube-api v0.7.4-0.20250909095208-496f60eea9b5 h1:/jbKYMeXiYnuxyJQ
10811081
kusionstack.io/kube-api v0.7.4-0.20250909095208-496f60eea9b5/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
10821082
kusionstack.io/kube-utils v0.2.1-0.20251120063041-6043805ee00d h1:iQtnK03ia/MN4K/6O75EMI91ep7jpcIG0pWyeREBqtg=
10831083
kusionstack.io/kube-utils v0.2.1-0.20251120063041-6043805ee00d/go.mod h1:KEHTfo1Y8SWMODnckF6daO2cSIW0FJ8fkk8PBA5O2GU=
1084-
kusionstack.io/kube-xset v0.0.0-20251111060928-069410a15229 h1:fTXG+HNxgM982pU/SnETY1fTRIcrrovs0Apn6h//zIo=
1085-
kusionstack.io/kube-xset v0.0.0-20251111060928-069410a15229/go.mod h1:FceKgqapMHhwiyIqCziTQRW27fsSXpPS611AApnyiYI=
1084+
kusionstack.io/kube-xset v0.0.2-0.20251127122852-ae98b507b2cc h1:wOqqe15yj1EeXKzAtVMRNRa4Iw2N59hLOgnu3u0p5SI=
1085+
kusionstack.io/kube-xset v0.0.2-0.20251127122852-ae98b507b2cc/go.mod h1:FceKgqapMHhwiyIqCziTQRW27fsSXpPS611AApnyiYI=
10861086
kusionstack.io/resourceconsist v0.0.1 h1:+k/jriq5Ld7fQUYfWSMGynz/FesHtl3Rk2fmQPjBe0g=
10871087
kusionstack.io/resourceconsist v0.0.1/go.mod h1:816xS/fY6EOUbPFjXIWW/TGs8/YE46qP4ElKeIiwFdU=
10881088
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=

pkg/controllers/collaset/collaset_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242

4343
func Add(mgr manager.Manager) error {
4444
xSetController := &CollaSetController{}
45-
synccontrols.RegisterInPlaceIfPossibleUpdater(&inPlaceIfPossibleUpdater{})
45+
synccontrols.RegisterInPlaceIfPossibleUpdater(NewInPlaceIfPossibleUpdater)
4646
return kubexset.SetUpWithManager(mgr, xSetController)
4747
}
4848

pkg/controllers/collaset/collaset_controller_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,23 @@ var _ = Describe("collaset controller", func() {
13081308
Eventually(func() error {
13091309
return expectedStatusReplicas(c, cs, 0, 0, 0, 3, 2, 0, 0, 0)
13101310
}, 10*time.Second, 1*time.Second).Should(BeNil())
1311+
1312+
// scale out partition and replicas parallel
1313+
Expect(updateCollaSetWithRetry(c, cs.Namespace, cs.Name, func(cls *appsv1alpha1.CollaSet) bool {
1314+
cls.Spec.Replicas = int32Pointer(10)
1315+
cls.Spec.UpdateStrategy.RollingUpdate = &appsv1alpha1.RollingUpdateCollaSetStrategy{
1316+
ByPartition: &appsv1alpha1.ByPartition{
1317+
Partition: int32Pointer(8),
1318+
},
1319+
}
1320+
cls.Spec.Template.Spec.Containers[0].Image = "nginx:v2"
1321+
return true
1322+
})).Should(BeNil())
1323+
1324+
// scale out 7 replicas with current revision
1325+
Eventually(func() error {
1326+
return expectedStatusReplicas(c, cs, 0, 0, 0, 10, 2, 0, 0, 0)
1327+
}, 10*time.Second, 1*time.Second).Should(BeNil())
13111328
})
13121329

13131330
It("scale failed and update parallel", func() {
@@ -4259,7 +4276,7 @@ var _ = Describe("collaset controller", func() {
42594276
// wait for replace completed
42604277
Eventually(func() error {
42614278
return expectedStatusReplicas(c, cs, 0, 0, 0, 1, 1, 0, 0, 0)
4262-
}, 5*time.Second, 1*time.Second).Should(BeNil())
4279+
}, 10*time.Second, 1*time.Second).Should(BeNil())
42634280

42644281
// origin pod is deleted
42654282
Expect(c.List(context.TODO(), podList, client.InNamespace(cs.Namespace))).Should(BeNil())

pkg/controllers/collaset/pod_updater.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import (
3737

3838
var _ synccontrols.TargetUpdater = &inPlaceIfPossibleUpdater{}
3939

40+
func NewInPlaceIfPossibleUpdater() synccontrols.TargetUpdater {
41+
return &inPlaceIfPossibleUpdater{}
42+
}
43+
4044
type inPlaceIfPossibleUpdater struct {
4145
synccontrols.GenericTargetUpdater
4246
}

pkg/controllers/poddecoration/poddecoration_controller_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package poddecoration
1919
import (
2020
"context"
2121
"fmt"
22+
"net/url"
2223
"os"
2324
"path/filepath"
2425
"strings"
@@ -59,7 +60,7 @@ var (
5960
)
6061

6162
const (
62-
timeoutInterval = 5 * time.Second
63+
timeoutInterval = 10 * time.Second
6364
pollInterval = 500 * time.Millisecond
6465
)
6566

@@ -900,6 +901,13 @@ var _ = BeforeSuite(func() {
900901

901902
env = &envtest.Environment{
902903
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
904+
ControlPlane: envtest.ControlPlane{
905+
APIServer: &envtest.APIServer{
906+
URL: &url.URL{
907+
Host: "127.0.0.1:64431",
908+
},
909+
},
910+
},
903911
}
904912

905913
config, err := env.Start()

0 commit comments

Comments
 (0)