@@ -19,17 +19,6 @@ func TestModifyStaticPodForPinnedManagementErrorStates(t *testing.T) {
19
19
pod * v1.Pod
20
20
expectedError error
21
21
}{
22
- {
23
- pod : createPod (workloadAnnotations , nil ,
24
- & v1.Container {
25
- Name : "nginx" ,
26
- Image : "test/image" ,
27
- Resources : v1.ResourceRequirements {
28
- Requests : nil ,
29
- },
30
- }),
31
- expectedError : fmt .Errorf ("managed container nginx does not have Resource.Requests" ),
32
- },
33
22
{
34
23
pod : createPod (workloadAnnotations , nil ,
35
24
& v1.Container {
@@ -129,6 +118,7 @@ func TestStaticPodManaged(t *testing.T) {
129
118
pod * v1.Pod
130
119
expectedAnnotations map [string ]string
131
120
isGuaranteed bool
121
+ isBestEffort bool
132
122
}{
133
123
{
134
124
pod : & v1.Pod {
@@ -270,6 +260,164 @@ func TestStaticPodManaged(t *testing.T) {
270
260
"resources.workload.openshift.io/c1" : `{"cpushares":20,"cpulimit":100}` ,
271
261
},
272
262
},
263
+ {
264
+ pod : & v1.Pod {
265
+ TypeMeta : metav1.TypeMeta {
266
+ Kind : "Pod" ,
267
+ APIVersion : "" ,
268
+ },
269
+ ObjectMeta : metav1.ObjectMeta {
270
+ Name : "test" ,
271
+ UID : "12345" ,
272
+ Namespace : "mynamespace" ,
273
+ Annotations : map [string ]string {
274
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
275
+ },
276
+ },
277
+ Spec : v1.PodSpec {
278
+ Containers : []v1.Container {
279
+ {
280
+ Name : "c1" ,
281
+ Image : "test/nginx" ,
282
+ Resources : v1.ResourceRequirements {},
283
+ },
284
+ },
285
+ SecurityContext : & v1.PodSecurityContext {},
286
+ },
287
+ Status : v1.PodStatus {
288
+ Phase : v1 .PodPending ,
289
+ },
290
+ },
291
+ expectedAnnotations : map [string ]string {
292
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
293
+ },
294
+ isBestEffort : true ,
295
+ },
296
+ {
297
+ pod : & v1.Pod {
298
+ TypeMeta : metav1.TypeMeta {
299
+ Kind : "Pod" ,
300
+ APIVersion : "" ,
301
+ },
302
+ ObjectMeta : metav1.ObjectMeta {
303
+ Name : "test" ,
304
+ UID : "12345" ,
305
+ Namespace : "mynamespace" ,
306
+ Annotations : map [string ]string {
307
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
308
+ },
309
+ },
310
+ Spec : v1.PodSpec {
311
+ Containers : []v1.Container {
312
+ {
313
+ Name : "c1" ,
314
+ Image : "test/nginx" ,
315
+ Resources : v1.ResourceRequirements {
316
+ Requests : v1.ResourceList {
317
+ v1 .ResourceName ("dummy" ): resource .MustParse ("20m" ),
318
+ },
319
+ },
320
+ },
321
+ },
322
+ SecurityContext : & v1.PodSecurityContext {},
323
+ },
324
+ Status : v1.PodStatus {
325
+ Phase : v1 .PodPending ,
326
+ },
327
+ },
328
+ expectedAnnotations : map [string ]string {
329
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
330
+ },
331
+ isBestEffort : true ,
332
+ },
333
+ {
334
+ pod : & v1.Pod {
335
+ TypeMeta : metav1.TypeMeta {
336
+ Kind : "Pod" ,
337
+ APIVersion : "" ,
338
+ },
339
+ ObjectMeta : metav1.ObjectMeta {
340
+ Name : "test" ,
341
+ UID : "12345" ,
342
+ Namespace : "mynamespace" ,
343
+ Annotations : map [string ]string {
344
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
345
+ },
346
+ },
347
+ Spec : v1.PodSpec {
348
+ Containers : []v1.Container {
349
+ {
350
+ Name : "c1" ,
351
+ Image : "test/nginx" ,
352
+ Resources : v1.ResourceRequirements {},
353
+ },
354
+ },
355
+ InitContainers : []v1.Container {
356
+ {
357
+ Name : "ic1" ,
358
+ Image : "test/nginx" ,
359
+ Resources : v1.ResourceRequirements {},
360
+ },
361
+ },
362
+ SecurityContext : & v1.PodSecurityContext {},
363
+ },
364
+ Status : v1.PodStatus {
365
+ Phase : v1 .PodPending ,
366
+ },
367
+ },
368
+ expectedAnnotations : map [string ]string {
369
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
370
+ },
371
+ isBestEffort : true ,
372
+ },
373
+ {
374
+ pod : & v1.Pod {
375
+ TypeMeta : metav1.TypeMeta {
376
+ Kind : "Pod" ,
377
+ APIVersion : "" ,
378
+ },
379
+ ObjectMeta : metav1.ObjectMeta {
380
+ Name : "test" ,
381
+ UID : "12345" ,
382
+ Namespace : "mynamespace" ,
383
+ Annotations : map [string ]string {
384
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
385
+ },
386
+ },
387
+ Spec : v1.PodSpec {
388
+ Containers : []v1.Container {
389
+ {
390
+ Name : "c1" ,
391
+ Image : "test/nginx" ,
392
+ Resources : v1.ResourceRequirements {
393
+ Requests : v1.ResourceList {
394
+ v1 .ResourceName ("dummy" ): resource .MustParse ("20m" ),
395
+ },
396
+ },
397
+ },
398
+ },
399
+ InitContainers : []v1.Container {
400
+ {
401
+ Name : "ic1" ,
402
+ Image : "test/nginx" ,
403
+ Resources : v1.ResourceRequirements {
404
+ Requests : v1.ResourceList {
405
+ v1 .ResourceName ("dummy" ): resource .MustParse ("20m" ),
406
+ },
407
+ },
408
+ },
409
+ },
410
+ SecurityContext : & v1.PodSecurityContext {},
411
+ },
412
+ Status : v1.PodStatus {
413
+ Phase : v1 .PodPending ,
414
+ },
415
+ },
416
+ expectedAnnotations : map [string ]string {
417
+ "target.workload.openshift.io/management" : `{"effect": "PreferredDuringScheduling"}` ,
418
+ },
419
+ isBestEffort : true ,
420
+ },
273
421
{
274
422
pod : & v1.Pod {
275
423
TypeMeta : metav1.TypeMeta {
@@ -481,15 +629,24 @@ func TestStaticPodManaged(t *testing.T) {
481
629
if container .Resources .Requests .Cpu ().String () != "0" && ! tc .isGuaranteed {
482
630
t .Errorf ("cpu requests should be 0 got %v" , container .Resources .Requests .Cpu ().String ())
483
631
}
484
- if container .Resources .Requests .Memory ().String () == "0" && ! tc .isGuaranteed {
632
+ if container .Resources .Requests .Memory ().String () == "0" && ! tc .isGuaranteed && ! tc . isBestEffort {
485
633
t .Errorf ("memory requests were %v but should be %v" , container .Resources .Requests .Memory ().String (), container .Resources .Requests .Memory ().String ())
486
634
}
487
- if _ , exists := container .Resources .Requests [GenerateResourceName (workloadName )]; ! exists && ! tc .isGuaranteed {
635
+ if container .Resources .Requests .Memory ().String () != "0" && ! tc .isGuaranteed && tc .isBestEffort {
636
+ t .Errorf ("memory requests should be 0 got %v" , container .Resources .Requests .Memory ().String ())
637
+ }
638
+ if _ , exists := container .Resources .Requests [GenerateResourceName (workloadName )]; ! exists && ! tc .isGuaranteed && ! tc .isBestEffort {
488
639
t .Errorf ("managed capacity label missing from pod %v and container %v" , tc .pod .Name , container .Name )
489
640
}
490
- if _ , exists := container .Resources .Limits [GenerateResourceName (workloadName )]; ! exists && ! tc .isGuaranteed {
641
+ if _ , exists := container .Resources .Limits [GenerateResourceName (workloadName )]; ! exists && ! tc .isGuaranteed && ! tc . isBestEffort {
491
642
t .Errorf ("managed capacity label missing from pod %v and container %v limits" , tc .pod .Name , container .Name )
492
643
}
644
+ if _ , exists := container .Resources .Requests [GenerateResourceName (workloadName )]; exists && tc .isBestEffort {
645
+ t .Errorf ("managed capacity label present in best-effort pod %v and container %v requests" , tc .pod .Name , container .Name )
646
+ }
647
+ if _ , exists := container .Resources .Limits [GenerateResourceName (workloadName )]; exists && tc .isBestEffort {
648
+ t .Errorf ("managed capacity label present in best-effort pod %v and container %v limits" , tc .pod .Name , container .Name )
649
+ }
493
650
}
494
651
}
495
652
}
0 commit comments