Skip to content

Commit 57511e4

Browse files
authored
fix(group): support zero-replica scaling for group readiness (#6401)
1 parent 411c0a4 commit 57511e4

File tree

2 files changed

+103
-7
lines changed

2 files changed

+103
-7
lines changed

pkg/controllers/common/task_status.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,10 @@ func TaskGroupConditionReady[
303303
var needUpdate bool
304304

305305
replicas, readyReplicas := calcReadyReplicas[IS](state.InstanceSlice())
306-
if readyReplicas == replicas && replicas != 0 {
307-
needUpdate = coreutil.SetStatusCondition[S](
308-
g,
309-
*coreutil.Ready(),
310-
) || needUpdate
306+
specReplicas := coreutil.Replicas[S](g)
307+
308+
if readyReplicas == replicas && replicas == specReplicas {
309+
needUpdate = coreutil.SetStatusCondition[S](g, *coreutil.Ready()) || needUpdate
311310
} else {
312311
// TODO(liubo02): more info when unready
313312
needUpdate = coreutil.SetStatusCondition[S](

pkg/controllers/common/task_status_test.go

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ func TestTaskGroupConditionReady(t *testing.T) {
935935
expectedObj *v1alpha1.PDGroup
936936
}{
937937
{
938-
desc: "no instances",
938+
desc: "no instances and spec replicas is 1 (default)",
939939
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
940940
return obj
941941
}),
@@ -949,6 +949,68 @@ func TestTaskGroupConditionReady(t *testing.T) {
949949
return obj
950950
}),
951951
},
952+
{
953+
desc: "no instances and spec replicas is 0 - should be ready",
954+
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
955+
obj.Spec.Replicas = ptr.To[int32](0)
956+
return obj
957+
}),
958+
959+
expectedStatusChanged: true,
960+
expectedStatus: task.SComplete,
961+
expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
962+
obj.Spec.Replicas = ptr.To[int32](0)
963+
obj.Status.Conditions = []metav1.Condition{
964+
*coreutil.Ready(),
965+
}
966+
return obj
967+
}),
968+
},
969+
{
970+
desc: "no instances and spec replicas is 0 - already ready, not changed",
971+
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
972+
obj.Spec.Replicas = ptr.To[int32](0)
973+
obj.Status.Conditions = []metav1.Condition{
974+
*coreutil.Ready(),
975+
}
976+
return obj
977+
}),
978+
979+
expectedStatusChanged: false,
980+
expectedStatus: task.SComplete,
981+
expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
982+
obj.Spec.Replicas = ptr.To[int32](0)
983+
obj.Status.Conditions = []metav1.Condition{
984+
*coreutil.Ready(),
985+
}
986+
return obj
987+
}),
988+
},
989+
{
990+
desc: "has 1 instance but spec replicas is 0 - should be unready",
991+
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
992+
obj.Spec.Replicas = ptr.To[int32](0)
993+
return obj
994+
}),
995+
instances: []*v1alpha1.PD{
996+
fake.FakeObj("aaa", func(obj *v1alpha1.PD) *v1alpha1.PD {
997+
obj.Status.Conditions = []metav1.Condition{
998+
*coreutil.Ready(),
999+
}
1000+
return obj
1001+
}),
1002+
},
1003+
1004+
expectedStatusChanged: true,
1005+
expectedStatus: task.SComplete,
1006+
expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
1007+
obj.Spec.Replicas = ptr.To[int32](0)
1008+
obj.Status.Conditions = []metav1.Condition{
1009+
*coreutil.Unready(v1alpha1.ReasonNotAllInstancesReady),
1010+
}
1011+
return obj
1012+
}),
1013+
},
9521014
{
9531015
desc: "no instances, not changed",
9541016
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
@@ -966,8 +1028,9 @@ func TestTaskGroupConditionReady(t *testing.T) {
9661028
}),
9671029
},
9681030
{
969-
desc: "all instances are ready",
1031+
desc: "all instances are ready and spec matches",
9701032
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
1033+
obj.Spec.Replicas = ptr.To[int32](2)
9711034
return obj
9721035
}),
9731036
instances: []*v1alpha1.PD{
@@ -988,6 +1051,7 @@ func TestTaskGroupConditionReady(t *testing.T) {
9881051
expectedStatusChanged: true,
9891052
expectedStatus: task.SComplete,
9901053
expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
1054+
obj.Spec.Replicas = ptr.To[int32](2)
9911055
obj.Status.Conditions = []metav1.Condition{
9921056
*coreutil.Ready(),
9931057
}
@@ -997,6 +1061,7 @@ func TestTaskGroupConditionReady(t *testing.T) {
9971061
{
9981062
desc: "one instance is not ready",
9991063
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
1064+
obj.Spec.Replicas = ptr.To[int32](2)
10001065
return obj
10011066
}),
10021067
instances: []*v1alpha1.PD{
@@ -1014,6 +1079,38 @@ func TestTaskGroupConditionReady(t *testing.T) {
10141079
expectedStatusChanged: true,
10151080
expectedStatus: task.SComplete,
10161081
expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
1082+
obj.Spec.Replicas = ptr.To[int32](2)
1083+
obj.Status.Conditions = []metav1.Condition{
1084+
*coreutil.Unready(v1alpha1.ReasonNotAllInstancesReady),
1085+
}
1086+
return obj
1087+
}),
1088+
},
1089+
{
1090+
desc: "all instances ready but count mismatch - expected 3 got 2",
1091+
obj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
1092+
obj.Spec.Replicas = ptr.To[int32](3)
1093+
return obj
1094+
}),
1095+
instances: []*v1alpha1.PD{
1096+
fake.FakeObj("aaa", func(obj *v1alpha1.PD) *v1alpha1.PD {
1097+
obj.Status.Conditions = []metav1.Condition{
1098+
*coreutil.Ready(),
1099+
}
1100+
return obj
1101+
}),
1102+
fake.FakeObj("bbb", func(obj *v1alpha1.PD) *v1alpha1.PD {
1103+
obj.Status.Conditions = []metav1.Condition{
1104+
*coreutil.Ready(),
1105+
}
1106+
return obj
1107+
}),
1108+
},
1109+
1110+
expectedStatusChanged: true,
1111+
expectedStatus: task.SComplete,
1112+
expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup {
1113+
obj.Spec.Replicas = ptr.To[int32](3)
10171114
obj.Status.Conditions = []metav1.Condition{
10181115
*coreutil.Unready(v1alpha1.ReasonNotAllInstancesReady),
10191116
}

0 commit comments

Comments
 (0)