Skip to content

Commit 462baf8

Browse files
authored
Merge pull request #554 from czybjtu/cleanup_postbind
Cleanup PostBind in coscheduling
2 parents 2ea5a97 + d640256 commit 462baf8

File tree

6 files changed

+6
-124
lines changed

6 files changed

+6
-124
lines changed

cmd/scheduler/main_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,6 @@ profiles:
507507
Enabled: append(defaults.ExpandedPluginsV1.Reserve.Enabled, config.Plugin{Name: coscheduling.Name}),
508508
},
509509
PreBind: defaults.ExpandedPluginsV1.PreBind,
510-
PostBind: config.PluginSet{
511-
Enabled: append(defaults.ExpandedPluginsV1.PostBind.Enabled, config.Plugin{Name: coscheduling.Name}),
512-
},
513510
},
514511
},
515512
},

pkg/controllers/podgroup_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,13 @@ func Test_Run(t *testing.T) {
109109
podNextPhase: v1.PodSucceeded,
110110
},
111111
{
112-
name: "Group status convert from scheduling to succeed",
112+
name: "Group status convert from pending to scheduling",
113113
pgName: "pg6",
114-
minMember: 2,
114+
minMember: 3,
115115
podNames: []string{"pod1", "pod2"},
116-
podPhase: v1.PodPending,
117-
previousPhase: v1alpha1.PodGroupScheduling,
118-
desiredGroupPhase: v1alpha1.PodGroupFinished,
119-
podNextPhase: v1.PodSucceeded,
116+
podPhase: v1.PodRunning,
117+
previousPhase: v1alpha1.PodGroupPending,
118+
desiredGroupPhase: v1alpha1.PodGroupScheduling,
120119
},
121120
{
122121
name: "Group status convert from pending to prescheduling",

pkg/coscheduling/core/core.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const (
5656
type Manager interface {
5757
PreFilter(context.Context, *corev1.Pod) error
5858
Permit(context.Context, *corev1.Pod) Status
59-
PostBind(context.Context, *corev1.Pod, string)
6059
GetPodGroup(*corev1.Pod) (string, *v1alpha1.PodGroup)
6160
GetCreationTimestamp(*corev1.Pod, time.Time) time.Time
6261
DeletePermittedPodGroup(string)
@@ -204,42 +203,6 @@ func (pgMgr *PodGroupManager) Permit(ctx context.Context, pod *corev1.Pod) Statu
204203
return Wait
205204
}
206205

207-
// PostBind updates a PodGroup's status.
208-
// TODO: move this logic to PodGroup's controller.
209-
func (pgMgr *PodGroupManager) PostBind(ctx context.Context, pod *corev1.Pod, nodeName string) {
210-
pgFullName, pg := pgMgr.GetPodGroup(pod)
211-
if pgFullName == "" || pg == nil {
212-
return
213-
}
214-
pgCopy := pg.DeepCopy()
215-
pgCopy.Status.Scheduled++
216-
217-
if pgCopy.Status.Scheduled >= pgCopy.Spec.MinMember {
218-
pgCopy.Status.Phase = v1alpha1.PodGroupScheduled
219-
} else {
220-
pgCopy.Status.Phase = v1alpha1.PodGroupScheduling
221-
if pgCopy.Status.ScheduleStartTime.IsZero() {
222-
pgCopy.Status.ScheduleStartTime = metav1.Time{Time: time.Now()}
223-
}
224-
}
225-
if pgCopy.Status.Phase != pg.Status.Phase {
226-
pg, err := pgMgr.pgLister.PodGroups(pgCopy.Namespace).Get(pgCopy.Name)
227-
if err != nil {
228-
klog.ErrorS(err, "Failed to get PodGroup", "podGroup", klog.KObj(pgCopy))
229-
return
230-
}
231-
patch, err := util.CreateMergePatch(pg, pgCopy)
232-
if err != nil {
233-
klog.ErrorS(err, "Failed to create merge patch", "podGroup", klog.KObj(pg), "podGroup", klog.KObj(pgCopy))
234-
return
235-
}
236-
if err := pgMgr.PatchPodGroup(pg.Name, pg.Namespace, patch); err != nil {
237-
klog.ErrorS(err, "Failed to patch", "podGroup", klog.KObj(pg))
238-
return
239-
}
240-
}
241-
}
242-
243206
// GetCreationTimestamp returns the creation time of a podGroup or a pod.
244207
func (pgMgr *PodGroupManager) GetCreationTimestamp(pod *corev1.Pod, ts time.Time) time.Time {
245208
pgName := util.GetPodGroupLabel(pod)

pkg/coscheduling/core/core_test.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
gochache "github.com/patrickmn/go-cache"
2525
corev1 "k8s.io/api/core/v1"
2626
"k8s.io/apimachinery/pkg/api/resource"
27-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28-
"k8s.io/apimachinery/pkg/util/wait"
2927
"k8s.io/client-go/informers"
3028
clientsetfake "k8s.io/client-go/kubernetes/fake"
3129
clicache "k8s.io/client-go/tools/cache"
@@ -35,7 +33,6 @@ import (
3533
"sigs.k8s.io/scheduler-plugins/apis/scheduling/v1alpha1"
3634
fakepgclientset "sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned/fake"
3735
pgformers "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
38-
"sigs.k8s.io/scheduler-plugins/pkg/util"
3936
testutil "sigs.k8s.io/scheduler-plugins/test/util"
4037
)
4138

@@ -216,73 +213,6 @@ func TestPermit(t *testing.T) {
216213
}
217214
}
218215

219-
func TestPostBind(t *testing.T) {
220-
ctx := context.Background()
221-
pg := testutil.MakePG("pg", "ns1", 1, nil, nil)
222-
pg1 := testutil.MakePG("pg1", "ns1", 2, nil, nil)
223-
pg2 := testutil.MakePG("pg2", "ns1", 3, nil, nil)
224-
pg2.Status.Phase = v1alpha1.PodGroupScheduling
225-
pg2.Status.Scheduled = 1
226-
fakeClient := fakepgclientset.NewSimpleClientset(pg, pg1, pg2)
227-
228-
pgInformerFactory := pgformers.NewSharedInformerFactory(fakeClient, 0)
229-
pgInformer := pgInformerFactory.Scheduling().V1alpha1().PodGroups()
230-
pgInformerFactory.Start(ctx.Done())
231-
232-
pgInformer.Informer().GetStore().Add(pg)
233-
pgInformer.Informer().GetStore().Add(pg1)
234-
pgInformer.Informer().GetStore().Add(pg2)
235-
pgLister := pgInformer.Lister()
236-
237-
tests := []struct {
238-
name string
239-
pod *corev1.Pod
240-
desiredGroupPhase v1alpha1.PodGroupPhase
241-
desiredScheduled int32
242-
}{
243-
{
244-
name: "pg status convert to scheduled",
245-
pod: st.MakePod().Name("p").UID("p").Namespace("ns1").Label(v1alpha1.PodGroupLabel, "pg").Obj(),
246-
desiredGroupPhase: v1alpha1.PodGroupScheduled,
247-
desiredScheduled: 1,
248-
},
249-
{
250-
name: "pg status convert to scheduling",
251-
pod: st.MakePod().Name("p").UID("p").Namespace("ns1").Label(v1alpha1.PodGroupLabel, "pg1").Obj(),
252-
desiredGroupPhase: v1alpha1.PodGroupScheduling,
253-
desiredScheduled: 1,
254-
},
255-
{
256-
name: "pg status does not convert, although scheduled pods change",
257-
pod: st.MakePod().Name("p").UID("p").Namespace("ns1").Label(v1alpha1.PodGroupLabel, "pg2").Obj(),
258-
desiredGroupPhase: v1alpha1.PodGroupScheduling,
259-
desiredScheduled: 1,
260-
},
261-
}
262-
for _, tt := range tests {
263-
t.Run(tt.name, func(t *testing.T) {
264-
pgMgr := &PodGroupManager{pgClient: fakeClient, pgLister: pgLister}
265-
pgMgr.PostBind(ctx, tt.pod, "test")
266-
err := wait.PollImmediate(100*time.Millisecond, 1*time.Second, func() (done bool, err error) {
267-
pg, err := pgMgr.pgClient.SchedulingV1alpha1().PodGroups(tt.pod.Namespace).Get(ctx, util.GetPodGroupLabel(tt.pod), v1.GetOptions{})
268-
if err != nil {
269-
return false, nil
270-
}
271-
if pg.Status.Phase != tt.desiredGroupPhase {
272-
return false, nil
273-
}
274-
if pg.Status.Scheduled != tt.desiredScheduled {
275-
return false, nil
276-
}
277-
return true, nil
278-
})
279-
if err != nil {
280-
t.Error(err)
281-
}
282-
})
283-
}
284-
}
285-
286216
func TestCheckClusterResource(t *testing.T) {
287217
nodeRes := map[corev1.ResourceName]string{corev1.ResourceMemory: "300"}
288218
node := st.MakeNode().Name("fake-node").Capacity(nodeRes).Obj()

pkg/coscheduling/coscheduling.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var _ framework.PreFilterPlugin = &Coscheduling{}
4848
var _ framework.PostFilterPlugin = &Coscheduling{}
4949
var _ framework.PermitPlugin = &Coscheduling{}
5050
var _ framework.ReservePlugin = &Coscheduling{}
51-
var _ framework.PostBindPlugin = &Coscheduling{}
51+
5252
var _ framework.EnqueueExtensions = &Coscheduling{}
5353

5454
const (
@@ -230,9 +230,3 @@ func (cs *Coscheduling) Unreserve(ctx context.Context, state *framework.CycleSta
230230
})
231231
cs.pgMgr.DeletePermittedPodGroup(pgName)
232232
}
233-
234-
// PostBind is called after a pod is successfully bound. These plugins are used update PodGroup when pod is bound.
235-
func (cs *Coscheduling) PostBind(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, nodeName string) {
236-
klog.V(5).InfoS("PostBind", "pod", klog.KObj(pod))
237-
cs.pgMgr.PostBind(ctx, pod, nodeName)
238-
}

test/integration/coscheduling_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func TestCoschedulingPlugin(t *testing.T) {
8080
cfg.Profiles[0].Plugins.PreFilter.Enabled = append(cfg.Profiles[0].Plugins.PreFilter.Enabled, schedapi.Plugin{Name: coscheduling.Name})
8181
cfg.Profiles[0].Plugins.PostFilter.Enabled = append(cfg.Profiles[0].Plugins.PostFilter.Enabled, schedapi.Plugin{Name: coscheduling.Name})
8282
cfg.Profiles[0].Plugins.Permit.Enabled = append(cfg.Profiles[0].Plugins.Permit.Enabled, schedapi.Plugin{Name: coscheduling.Name})
83-
cfg.Profiles[0].Plugins.PostBind.Enabled = append(cfg.Profiles[0].Plugins.PostBind.Enabled, schedapi.Plugin{Name: coscheduling.Name})
8483
cfg.Profiles[0].PluginConfig = append(cfg.Profiles[0].PluginConfig, schedapi.PluginConfig{
8584
Name: coscheduling.Name,
8685
Args: &schedconfig.CoschedulingArgs{

0 commit comments

Comments
 (0)