1
1
//Logic for the scheduler extender - including the server it starts and prioritize + filter methods - is implemented in this package.
2
- package scheduler
2
+ package telemetryscheduler
3
3
4
4
import (
5
5
"bytes"
6
6
"encoding/json"
7
7
"errors"
8
8
"github.com/intel/telemetry-aware-scheduling/pkg/cache"
9
9
"github.com/intel/telemetry-aware-scheduling/pkg/metrics"
10
+ "github.com/intel/telemetry-aware-scheduling/pkg/scheduler"
10
11
telpolv1 "github.com/intel/telemetry-aware-scheduling/pkg/telemetrypolicy/api/v1alpha1"
11
12
telpolclient "github.com/intel/telemetry-aware-scheduling/pkg/telemetrypolicy/client/v1alpha1"
12
13
"io/ioutil"
@@ -20,19 +21,19 @@ import (
20
21
"testing"
21
22
)
22
23
23
- var prioritizerArgs1 = ExtenderArgs {
24
+ var prioritizerArgs1 = scheduler. ExtenderArgs {
24
25
Pod : v1.Pod {TypeMeta : metav1.TypeMeta {}, ObjectMeta : metav1.ObjectMeta {Name : "big pod" , Labels : map [string ]string {"telemetry-policy" : "test-policy" }, Namespace : "default" }},
25
26
Nodes : & v1.NodeList {Items : []v1.Node {{TypeMeta : metav1.TypeMeta {}, ObjectMeta : metav1.ObjectMeta {Name : "node A" }, Spec : v1.NodeSpec {}, Status : v1.NodeStatus {}}}},
26
27
NodeNames : & []string {"node A" , "node B" },
27
28
}
28
29
29
- var twoNodeArgument = ExtenderArgs {
30
+ var twoNodeArgument = scheduler. ExtenderArgs {
30
31
Pod : v1.Pod {TypeMeta : metav1.TypeMeta {}, ObjectMeta : metav1.ObjectMeta {Name : "big pod" , Labels : map [string ]string {"telemetry-policy" : "test-policy" }, Namespace : "default" }},
31
32
Nodes : & v1.NodeList {Items : []v1.Node {{TypeMeta : metav1.TypeMeta {}, ObjectMeta : metav1.ObjectMeta {Name : "node A" }, Spec : v1.NodeSpec {}, Status : v1.NodeStatus {}}, {TypeMeta : metav1.TypeMeta {}, ObjectMeta : metav1.ObjectMeta {Name : "node B" }, Spec : v1.NodeSpec {}, Status : v1.NodeStatus {}}}},
32
33
NodeNames : & []string {"node A" , "node B" },
33
34
}
34
35
35
- var noPolicyPod = ExtenderArgs {
36
+ var noPolicyPod = scheduler. ExtenderArgs {
36
37
Pod : v1.Pod {TypeMeta : metav1.TypeMeta {}, ObjectMeta : metav1.ObjectMeta {Name : "big pod" , Labels : map [string ]string {"useless-label" : "test-policy" }, Namespace : "default" }},
37
38
Nodes : & v1.NodeList {Items : []v1.Node {{TypeMeta : metav1.TypeMeta {}, ObjectMeta : metav1.ObjectMeta {Name : "node A" }, Spec : v1.NodeSpec {}, Status : v1.NodeStatus {}}}},
38
39
NodeNames : & []string {"node A" , "node B" },
@@ -93,8 +94,8 @@ func TestMetricsExtender_prescheduleChecks(t *testing.T) {
93
94
fields fields
94
95
args args
95
96
metric metrics.NodeMetricsInfo
96
- prioritizeArgs ExtenderArgs
97
- wanted HostPriorityList
97
+ prioritizeArgs scheduler. ExtenderArgs
98
+ wanted scheduler. HostPriorityList
98
99
wantErr bool
99
100
}{
100
101
{name : "unlabelled pod" ,
@@ -103,7 +104,7 @@ func TestMetricsExtender_prescheduleChecks(t *testing.T) {
103
104
args : args {httptest .NewRequest ("POST" , "http://localhost/scheduler/prioritize" , nil )},
104
105
metric : map [string ]metrics.NodeMetric {"node A" : {Value : * resource .NewQuantity (100 , resource .DecimalSI )}, "node B" : {Value : * resource .NewQuantity (90 , resource .DecimalSI )}},
105
106
prioritizeArgs : noPolicyPod ,
106
- wanted : []HostPriority {{"node A" , 10 }, {"node B" , 9 }},
107
+ wanted : []scheduler. HostPriority {{Host : "node A" , Score : 10 }, {Host : "node B" , Score : 9 }},
107
108
wantErr : true ,
108
109
},
109
110
}
@@ -128,7 +129,7 @@ func TestMetricsExtender_prescheduleChecks(t *testing.T) {
128
129
tt .args .r .Body = ioutil .NopCloser (bytes .NewReader (argsAsJSON ))
129
130
w := httptest .NewRecorder ()
130
131
m .Prioritize (w , tt .args .r )
131
- result := HostPriorityList {}
132
+ result := scheduler. HostPriorityList {}
132
133
b := w .Body .Bytes ()
133
134
err = json .Unmarshal (b , & result )
134
135
log .Print (result )
@@ -154,8 +155,8 @@ func TestMetricsExtender_Prioritize(t *testing.T) {
154
155
fields fields
155
156
args args
156
157
metric metrics.NodeMetricsInfo
157
- prioritizeArgs ExtenderArgs
158
- wanted HostPriorityList
158
+ prioritizeArgs scheduler. ExtenderArgs
159
+ wanted scheduler. HostPriorityList
159
160
wantErr bool
160
161
}{
161
162
{"get and return node test" ,
@@ -164,7 +165,7 @@ func TestMetricsExtender_Prioritize(t *testing.T) {
164
165
args {httptest .NewRequest ("POST" , "http://localhost/scheduler/prioritize" , nil )},
165
166
map [string ]metrics.NodeMetric {"node A" : {Value : * resource .NewQuantity (100 , resource .DecimalSI )}, "node B" : {Value : * resource .NewQuantity (90 , resource .DecimalSI )}},
166
167
twoNodeArgument ,
167
- []HostPriority {{"node A" , 10 }, {"node B" , 9 }},
168
+ []scheduler. HostPriority {{Host : "node A" , Score : 10 }, {Host : "node B" , Score : 9 }},
168
169
false ,
169
170
},
170
171
{"policy not found" ,
@@ -173,7 +174,7 @@ func TestMetricsExtender_Prioritize(t *testing.T) {
173
174
args {httptest .NewRequest ("POST" , "http://localhost/scheduler/prioritize" , nil )},
174
175
map [string ]metrics.NodeMetric {"node A" : {Value : * resource .NewQuantity (90 , resource .DecimalSI )}, "node B" : {Value : * resource .NewQuantity (100 , resource .DecimalSI )}},
175
176
twoNodeArgument ,
176
- []HostPriority {},
177
+ []scheduler. HostPriority {},
177
178
true ,
178
179
},
179
180
{"cache returns error if empty" ,
@@ -182,15 +183,15 @@ func TestMetricsExtender_Prioritize(t *testing.T) {
182
183
args {httptest .NewRequest ("POST" , "http://localhost/scheduler/prioritize" , nil )},
183
184
map [string ]metrics.NodeMetric {"node A" : {Value : * resource .NewQuantity (100 , resource .DecimalSI )}},
184
185
prioritizerArgs1 ,
185
- []HostPriority {{"node B" , 10 }},
186
+ []scheduler. HostPriority {{Host : "node B" , Score : 10 }},
186
187
true ,
187
188
},
188
- {"malformed arguments return error" , fields {* dummyClient , cache .MockEmptySelfUpdatingCache (),
189
- testPolicy1 },
189
+ {"malformed arguments return error" ,fields {* dummyClient , cache .MockEmptySelfUpdatingCache (),
190
+ testPolicy1 },
190
191
args {httptest .NewRequest ("POST" , "http://localhost/scheduler/prioritize" , nil )},
191
192
map [string ]metrics.NodeMetric {"node A" : {Value : * resource .NewQuantity (100 , resource .DecimalSI )}},
192
- ExtenderArgs {},
193
- []HostPriority {{"node B" , 10 }},
193
+ scheduler. ExtenderArgs {},
194
+ []scheduler. HostPriority {{Host : "node B" , Score : 10 }},
194
195
true ,
195
196
},
196
197
}
@@ -216,7 +217,7 @@ func TestMetricsExtender_Prioritize(t *testing.T) {
216
217
tt .args .r .Body = ioutil .NopCloser (bytes .NewReader (argsAsJSON ))
217
218
w := httptest .NewRecorder ()
218
219
m .Prioritize (w , tt .args .r )
219
- result := HostPriorityList {}
220
+ result := scheduler. HostPriorityList {}
220
221
b := w .Body .Bytes ()
221
222
err = json .Unmarshal (b , & result )
222
223
if err != nil && tt .wantErr {
@@ -265,7 +266,7 @@ func TestMetricsExtender_Filter(t *testing.T) {
265
266
name string
266
267
fields fields
267
268
args args
268
- wanted ExtenderFilterResult
269
+ wanted scheduler. ExtenderFilterResult
269
270
wantErr bool
270
271
}{
271
272
{name : "get and return node test" ,
@@ -275,14 +276,14 @@ func TestMetricsExtender_Filter(t *testing.T) {
275
276
testPolicy1 },
276
277
args : args {
277
278
httptest .NewRequest ("POST" , "http://localhost/scheduler/prioritize" , nil ), metrics .TestNodeMetricCustomInfo ([]string {"node A" , "node B" }, []int64 {10 , 30 })},
278
- wanted : ExtenderFilterResult {& v1.NodeList {}, & []string {"node A" }, map [string ]string {}, "" },
279
+ wanted : scheduler. ExtenderFilterResult {Nodes : & v1.NodeList {}, NodeNames : & []string {"node A" }, FailedNodes : map [string ]string {}},
279
280
},
280
281
{name : "filter out one node" ,
281
282
fields : fields {* dummyClient , cache .MockSelfUpdatingCache (),
282
283
metrics .NewDummyMetricsClient (metrics .InstanceOfMockMetricClientMap ),
283
284
testPolicy1 },
284
285
args : args {httptest .NewRequest ("POST" , "http://localhost/scheduler/prioritize" , nil ), metrics .TestNodeMetricCustomInfo ([]string {"node A" , "node B" }, []int64 {50 , 30 })},
285
- wanted : ExtenderFilterResult {& v1.NodeList {}, & []string {"node A" }, map [string ]string {"node A" : "" }, "" },
286
+ wanted : scheduler. ExtenderFilterResult {Nodes : & v1.NodeList {}, NodeNames : & []string {"node A" }, FailedNodes : map [string ]string {"node A" : "" }},
286
287
},
287
288
}
288
289
for _ , tt := range tests {
@@ -308,7 +309,7 @@ func TestMetricsExtender_Filter(t *testing.T) {
308
309
tt .args .r .Header .Add ("Content-Type" , "application/json" )
309
310
w := httptest .NewRecorder ()
310
311
m .Filter (w , tt .args .r )
311
- result := ExtenderFilterResult {}
312
+ result := scheduler. ExtenderFilterResult {}
312
313
b := w .Body .Bytes ()
313
314
err = json .Unmarshal (b , & result )
314
315
if err != nil {
0 commit comments