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 abbb781
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 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
28 changes: 21 additions & 7 deletions pkg/controller/podgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,25 @@ func Test_Run(t *testing.T) {
previousPhase: v1alpha1.PodGroupPending,
desiredGroupPhase: v1alpha1.PodGroupPreScheduling,
},
{
name: "Pod number scale down to 0",
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 All @@ -144,11 +158,11 @@ func Test_Run(t *testing.T) {

pgInformerFactory.Start(ctx.Done())
informerFactory.Start(ctx.Done())
// 0 means not set
if len(c.podNextPhase) != 0 {
ps := makePods(c.podNames, c.pgName, c.podNextPhase)
for _, p := range ps {
kubeClient.CoreV1().Pods(p.Namespace).UpdateStatus(ctx, p, metav1.UpdateOptions{})
// pod number scales down to 0
if c.previousPhase == v1alpha1.PodGroupRunning &&
c.desiredGroupPhase == v1alpha1.PodGroupPending {
for _, p := range c.podNames {
kubeClient.CoreV1().Pods("default").Delete(ctx, p, metav1.DeleteOptions{})
}
}
go ctrl.Run(1, ctx.Done())
Expand Down

0 comments on commit abbb781

Please sign in to comment.