@@ -18,24 +18,23 @@ package scheduler
18
18
19
19
import (
20
20
"fmt"
21
+ "k8s.io/apimachinery/pkg/runtime"
21
22
"testing"
22
23
"time"
23
24
24
25
"k8s.io/api/core/v1"
25
- "k8s.io/apimachinery/pkg/runtime"
26
26
"k8s.io/apimachinery/pkg/util/wait"
27
27
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
28
28
)
29
29
30
30
// TesterPlugin is common ancestor for a test plugin that allows injection of
31
31
// failures and some other test functionalities.
32
32
type TesterPlugin struct {
33
- numReserveCalled int
34
- numPrebindCalled int
35
- numUnreserveCalled int
36
- failReserve bool
37
- failPrebind bool
38
- rejectPrebind bool
33
+ numReserveCalled int
34
+ numPrebindCalled int
35
+ failReserve bool
36
+ failPrebind bool
37
+ rejectPrebind bool
39
38
}
40
39
41
40
type ReservePlugin struct {
@@ -46,27 +45,19 @@ type PrebindPlugin struct {
46
45
TesterPlugin
47
46
}
48
47
49
- type UnreservePlugin struct {
50
- TesterPlugin
51
- }
52
-
53
48
const (
54
- reservePluginName = "reserve-plugin"
55
- prebindPluginName = "prebind-plugin"
56
- unreservePluginName = "unreserve-plugin"
49
+ reservePluginName = "reserve-plugin"
50
+ prebindPluginName = "prebind-plugin"
57
51
)
58
52
59
53
var _ = framework .ReservePlugin (& ReservePlugin {})
60
54
var _ = framework .PrebindPlugin (& PrebindPlugin {})
61
- var _ = framework .UnreservePlugin (& UnreservePlugin {})
62
55
63
56
// Name returns name of the plugin.
64
57
func (rp * ReservePlugin ) Name () string {
65
58
return reservePluginName
66
59
}
67
60
68
- var resPlugin = & ReservePlugin {}
69
-
70
61
// Reserve is a test function that returns an error or nil, depending on the
71
62
// value of "failReserve".
72
63
func (rp * ReservePlugin ) Reserve (pc * framework.PluginContext , pod * v1.Pod , nodeName string ) * framework.Status {
@@ -77,13 +68,14 @@ func (rp *ReservePlugin) Reserve(pc *framework.PluginContext, pod *v1.Pod, nodeN
77
68
return nil
78
69
}
79
70
71
+ var resPlugin = & ReservePlugin {}
72
+ var pbdPlugin = & PrebindPlugin {}
73
+
80
74
// NewReservePlugin is the factory for reserve plugin.
81
75
func NewReservePlugin (_ * runtime.Unknown , _ framework.FrameworkHandle ) (framework.Plugin , error ) {
82
76
return resPlugin , nil
83
77
}
84
78
85
- var pbdPlugin = & PrebindPlugin {}
86
-
87
79
// Name returns name of the plugin.
88
80
func (pp * PrebindPlugin ) Name () string {
89
81
return prebindPluginName
@@ -106,29 +98,6 @@ func NewPrebindPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framewor
106
98
return pbdPlugin , nil
107
99
}
108
100
109
- var unresPlugin = & UnreservePlugin {}
110
-
111
- // Name returns name of the plugin.
112
- func (up * UnreservePlugin ) Name () string {
113
- return unreservePluginName
114
- }
115
-
116
- // Unreserve is a test function that returns an error or nil, depending on the
117
- // value of "failUnreserve".
118
- func (up * UnreservePlugin ) Unreserve (pc * framework.PluginContext , pod * v1.Pod , nodeName string ) {
119
- up .numUnreserveCalled ++
120
- }
121
-
122
- // reset used to reset numUnreserveCalled.
123
- func (up * UnreservePlugin ) reset () {
124
- up .numUnreserveCalled = 0
125
- }
126
-
127
- // NewUnreservePlugin is the factory for unreserve plugin.
128
- func NewUnreservePlugin (_ * runtime.Unknown , _ framework.FrameworkHandle ) (framework.Plugin , error ) {
129
- return unresPlugin , nil
130
- }
131
-
132
101
// TestReservePlugin tests invocation of reserve plugins.
133
102
func TestReservePlugin (t * testing.T ) {
134
103
// Create a plugin registry for testing. Register only a reserve plugin.
@@ -247,86 +216,3 @@ func TestPrebindPlugin(t *testing.T) {
247
216
cleanupPods (cs , t , []* v1.Pod {pod })
248
217
}
249
218
}
250
-
251
- // TestUnreservePlugin tests invocation of un-reserve plugin
252
- func TestUnreservePlugin (t * testing.T ) {
253
- // TODO: register more plugin which would trigger un-reserve plugin
254
- registry := framework.Registry {
255
- unreservePluginName : NewUnreservePlugin ,
256
- prebindPluginName : NewPrebindPlugin ,
257
- }
258
-
259
- // Create the master and the scheduler with the test plugin set.
260
- context := initTestSchedulerWithOptions (t ,
261
- initTestMaster (t , "unreserve-plugin" , nil ),
262
- false , nil , registry , false , time .Second )
263
- defer cleanupTest (t , context )
264
-
265
- cs := context .clientSet
266
- // Add a few nodes.
267
- _ , err := createNodes (cs , "test-node" , nil , 2 )
268
- if err != nil {
269
- t .Fatalf ("Cannot create nodes: %v" , err )
270
- }
271
-
272
- tests := []struct {
273
- prebindFail bool
274
- prebindReject bool
275
- }{
276
- {
277
- prebindFail : false ,
278
- prebindReject : false ,
279
- },
280
- {
281
- prebindFail : true ,
282
- prebindReject : false ,
283
- },
284
- {
285
- prebindFail : false ,
286
- prebindReject : true ,
287
- },
288
- {
289
- prebindFail : true ,
290
- prebindReject : true ,
291
- },
292
- }
293
-
294
- for i , test := range tests {
295
- pbdPlugin .failPrebind = test .prebindFail
296
- pbdPlugin .rejectPrebind = test .prebindReject
297
-
298
- // Create a best effort pod.
299
- pod , err := createPausePod (cs ,
300
- initPausePod (cs , & pausePodConfig {Name : "test-pod" , Namespace : context .ns .Name }))
301
- if err != nil {
302
- t .Errorf ("Error while creating a test pod: %v" , err )
303
- }
304
-
305
- if test .prebindFail {
306
- if err = wait .Poll (10 * time .Millisecond , 30 * time .Second , podSchedulingError (cs , pod .Namespace , pod .Name )); err != nil {
307
- t .Errorf ("test #%v: Expected a scheduling error, but didn't get it. error: %v" , i , err )
308
- }
309
- if unresPlugin .numUnreserveCalled != 1 {
310
- t .Errorf ("test #%v: Expected the unreserve plugin to be called only once." , i )
311
- }
312
- } else {
313
- if test .prebindReject {
314
- if err = waitForPodUnschedulable (cs , pod ); err != nil {
315
- t .Errorf ("test #%v: Didn't expected the pod to be scheduled. error: %v" , i , err )
316
- }
317
- if unresPlugin .numUnreserveCalled != 1 {
318
- t .Errorf ("test #%v: Expected the unreserve plugin to be called only once." , i )
319
- }
320
- } else {
321
- if err = waitForPodToSchedule (cs , pod ); err != nil {
322
- t .Errorf ("test #%v: Expected the pod to be scheduled. error: %v" , i , err )
323
- }
324
- if unresPlugin .numUnreserveCalled > 0 {
325
- t .Errorf ("test #%v: Didn't expected the unreserve plugin to be called." , i )
326
- }
327
- }
328
- }
329
- unresPlugin .reset ()
330
- cleanupPods (cs , t , []* v1.Pod {pod })
331
- }
332
- }
0 commit comments