Skip to content

Commit

Permalink
Fix controller reconcile PodGroup status
Browse files Browse the repository at this point in the history
Signed-off-by: lianghao208 <302824716@qq.com>
  • Loading branch information
lianghao208 committed Dec 10, 2021
1 parent 6b3642f commit da8c3d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/controller/podgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ func (ctrl *PodGroupController) syncHandler(key string) error {
pgCopy.Status.Succeeded = succeeded
pgCopy.Status.Running = running

if len(pods) == 0 {
pgCopy.Status.Phase = schedv1alpha1.PodGroupPending
break
}

if pgCopy.Status.Scheduled >= pgCopy.Spec.MinMember && pgCopy.Status.Phase == schedv1alpha1.PodGroupScheduling {
pgCopy.Status.Phase = schedv1alpha1.PodGroupScheduled
}
Expand Down
22 changes: 18 additions & 4 deletions pkg/controller/podgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Test_Run(t *testing.T) {
podNextPhase: v1.PodSucceeded,
},
{
name: "Group group should not enqueue, created too long",
name: "Group should not enqueue, created too long",
pgName: "pg8",
minMember: 2,
podNames: []string{"pod1", "pod2"},
Expand All @@ -120,19 +120,33 @@ func Test_Run(t *testing.T) {
podGroupCreateTime: &createTime,
},
{
name: "Group group min member more than Pod number",
name: "Group min member more than Pod number",
pgName: "pg9",
minMember: 3,
podNames: []string{"pod91", "pod92"},
podPhase: v1.PodPending,
previousPhase: v1alpha1.PodGroupPending,
desiredGroupPhase: v1alpha1.PodGroupPreScheduling,
},
{
name: "Group status convert from running to pending",
pgName: "pg10",
minMember: 2,
podNames: []string{},
podPhase: v1.PodPending,
previousPhase: v1alpha1.PodGroupRunning,
desiredGroupPhase: v1alpha1.PodGroupPending,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
ps := makePods(c.podNames, c.pgName, c.podPhase)
kubeClient := fake.NewSimpleClientset(ps[0], ps[1])
var kubeClient *fake.Clientset
if len(c.podNames) == 0 {
kubeClient = fake.NewSimpleClientset()
} else {
ps := makePods(c.podNames, c.pgName, c.podPhase)
kubeClient = fake.NewSimpleClientset(ps[0], ps[1])
}
pg := makePG(c.pgName, 2, c.previousPhase, c.podGroupCreateTime)
pgClient := pgfake.NewSimpleClientset(pg)

Expand Down

0 comments on commit da8c3d1

Please sign in to comment.