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 8, 2021
1 parent 6b3642f commit 397a7f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/controller/podgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func (ctrl *PodGroupController) syncHandler(key string) error {
failed++
}
}
} else {
pgCopy.Status.Failed = 0
pgCopy.Status.Succeeded = 0
pgCopy.Status.Running = 0
pgCopy.Status.Phase = schedv1alpha1.PodGroupPending
break
}
pgCopy.Status.Failed = failed
pgCopy.Status.Succeeded = succeeded
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 397a7f2

Please sign in to comment.