8000 add preScore for volumeBinding · kubernetes/kubernetes@210ed2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 210ed2e

Browse files
committed
add preScore for volumeBinding
1 parent 55f2bc1 commit 210ed2e

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

cmd/kube-scheduler/app/server_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ leaderElection:
260260
{Name: "NodePorts"},
261261
}
262262
plugins.PreScore.Enabled = []config.Plugin{
263+
{Name: "VolumeBinding"},
263264
{Name: "NodeResourcesFit"},
264265
{Name: "InterPodAffinity"},
265266
{Name: "TaintToleration"},

pkg/scheduler/apis/config/testing/defaults/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ var ExpandedPluginsV1 = &config.Plugins{
107107
{Name: names.TaintToleration},
108108
{Name: names.NodeAffinity},
109109
{Name: names.NodeResourcesFit},
110+
{Name: names.VolumeBinding},
110111
{Name: names.PodTopologySpread},
111112
{Name: names.InterPodAffinity},
112113
{Name: names.NodeResourcesBalancedAllocation},

pkg/scheduler/framework/plugins/volumebinding/volume_binding.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ type stateData struct {
5353
// it's initialized in the PreFilter phase
5454
podVolumesByNode map[string]*PodVolumes
5555
podVolumeClaims *PodVolumeClaims
56+
// hasStaticBindings declares whether the pod contains one or more StaticBinding.
57+
// If not, vloumeBinding will skip score extension point.
58+
hasStaticBindings bool
5659
sync.Mutex
5760
}
5861

@@ -74,6 +77,7 @@ var _ framework.PreFilterPlugin = &VolumeBinding{}
7477
var _ framework.FilterPlugin = &VolumeBinding{}
7578
var _ framework.ReservePlugin = &VolumeBinding{}
7679
var _ framework.PreBindPlugin = &VolumeBinding{}
80+
var _ framework.PreScorePlugin = &VolumeBinding{}
7781
var _ framework.ScorePlugin = &VolumeBinding{}
7882
var _ framework.EnqueueExtensions = &VolumeBinding{}
7983

@@ -258,10 +262,26 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p
258262
// multiple goroutines call `Filter` on different nodes simultaneously and the `CycleState` may be duplicated, so we must use a local lock here
259263
state.Lock()
260264
state.podVolumesByNode[node.Name] = podVolumes
265+
state.hasStaticBindings = state.hasStaticBindings || (podVolumes != nil && len(podVolumes.StaticBindings) > 0)
261266
state.Unlock()
262267
return nil
263268
}
264269

270+
// PreScore invoked at the preScore extension point. It checks whether volumeBinding can skip Score
271+
func (pl *VolumeBinding) PreScore(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodes []*v1.Node) *framework.Status {
272+
if pl.scorer == nil {
273+
return framework.NewStatus(framework.Skip)
274+
}
275+
state, err := getStateData(cs)
276+
if err != nil {
277+
return framework.AsStatus(err)
278+
}
279+
if state.hasStaticBindings {
280+
return nil
281+
}
282+
return framework.NewStatus(framework.Skip)
283+
}
284+
265285
// Score invoked at the score extension point.
266286
func (pl *VolumeBinding) Score(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
267287
if pl.scorer == nil {

pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func TestVolumeBinding(t *testing.T) {
8585
wantStateAfterPreFilter *stateData
8686
wantFilterStatus []*framework.Status
8787
wantScores []int64
88+
wantPreScoreStatus *framework.Status
8889
}{
8990
{
9091
name: "pod has not pvcs",
@@ -96,9 +97,7 @@ func TestVolumeBinding(t *testing.T) {
9697
wantFilterStatus: []*framework.Status{
9798
nil,
9899
},
99-
wantScores: []int64{
100-
0,
101-
},
100+
wantPreScoreStatus: framework.NewStatus(framework.Skip),
102101
},
103102
{
104103
name: "all bound",
@@ -125,9 +124,7 @@ func TestVolumeBinding(t *testing.T) {
125124
wantFilterStatus: []*framework.Status{
126125
nil,
127126
},
128-
wantScores: []int64{
129-
0,
130-
},
127+
wantPreScoreStatus: framework.NewStatus(framework.Skip),
131128
},
132129
{
133130
name: "all bound with local volumes",
@@ -164,9 +161,7 @@ func TestVolumeBinding(t *testing.T) {
164161
wantFilterStatus: []*framework.Status{
165162
nil,
166163
},
167-
wantScores: []int64{
168-
0,
169-
},
164+
wantPreScoreStatus: framework.NewStatus(framework.Skip),
170165
},
171166
{
172167
name: "PVC does not exist",
@@ -239,9 +234,7 @@ func TestVolumeBinding(t *testing.T) {
239234
wantFilterStatus: []*framework.Status{
240235
framework.NewStatus(framework.UnschedulableAndUnresolvable, string(ErrReasonBindConflict)),
241236
},
242-
wantScores: []int64{
243-
0,
244-
},
237+
wantPreScoreStatus: framework.NewStatus(framework.Skip),
245238
},
246239
{
247240
name: "bound and unbound unsatisfied",
@@ -279,9 +272,7 @@ func TestVolumeBinding(t *testing.T) {
279272
wantFilterStatus: []*framework.Status{
280273
framework.NewStatus(framework.UnschedulableAndUnresolvable, string(ErrReasonNodeConflict), string(ErrReasonBindConflict)),
281274
},
282-
wantScores: []int64{
283-
0,
284-
},
275+
wantPreScoreStatus: framework.NewStatus(framework.Skip),
285276
},
286277
{
287278
name: "pvc not found",
@@ -320,9 +311,7 @@ func TestVolumeBinding(t *testing.T) {
320311
wantFilterStatus: []*framework.Status{
321312
framework.NewStatus(framework.UnschedulableAndUnresolvable, `node(s) unavailable due to one or more pvc(s) bound to non-existent pv(s)`),
322313
},
323-
wantScores: []int64{
324-
0,
325-
},
314+
wantPreScoreStatus: framework.NewStatus(framework.Skip),
326315
},
327316
{
328317
name: "pv not found claim lost",
@@ -878,6 +867,15 @@ func TestVolumeBinding(t *testing.T) {
878867
assert.Equal(t, item.wantFilterStatus[i], gotStatus)
879868
}
880869

870+
t.Logf("Verify: call PreScore and check status")
871+
gotPreScoreStatus := p.PreScore(ctx, state, item.pod, item.nodes)
872+
if diff := cmp.Diff(item.wantPreScoreStatus, gotPreScoreStatus); diff != "" {
873+
t.Errorf("state got after prescore does not match (-want,+got):\n%s", diff)
874+
}
875+
if !gotPreScoreStatus.IsSuccess() {
876+
return
877+
}
878+
881879
t.Logf("Verify: Score")
882880
for i, node := range item.nodes {
883881
score, status := p.Score(ctx, state, item.pod, node.Name)

0 commit comments

Comments
 (0)
0