@@ -125,6 +125,7 @@ func New(ctx context.Context, obj runtime.Object, handle framework.Handle) (fram
125
125
podLister : handle .SharedInformerFactory ().Core ().V1 ().Pods ().Lister (),
126
126
pdbLister : getPDBLister (handle .SharedInformerFactory ()),
127
127
}
128
+ logger := klog .FromContext (ctx )
128
129
129
130
client , err := client .New (handle .KubeConfig (), client.Options {Scheme : scheme })
130
131
if err != nil {
@@ -187,7 +188,7 @@ func New(ctx context.Context, obj runtime.Object, handle framework.Handle) (fram
187
188
},
188
189
},
189
190
)
190
- klog . InfoS ("CapacityScheduling start" )
191
+ logger . Info ("CapacityScheduling start" )
191
192
return c , nil
192
193
}
193
194
@@ -288,17 +289,19 @@ func (c *CapacityScheduling) PreFilterExtensions() framework.PreFilterExtensions
288
289
289
290
// AddPod from pre-computed data in cycleState.
290
291
func (c * CapacityScheduling ) AddPod (ctx context.Context , cycleState * framework.CycleState , podToSchedule * v1.Pod , podToAdd * framework.PodInfo , nodeInfo * framework.NodeInfo ) * framework.Status {
292
+ logger := klog .FromContext (ctx )
293
+
291
294
elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (cycleState )
292
295
if err != nil {
293
- klog . ErrorS (err , "Failed to read elasticQuotaSnapshot from cycleState" , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
296
+ logger . Error (err , "Failed to read elasticQuotaSnapshot from cycleState" , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
294
297
return framework .NewStatus (framework .Error , err .Error ())
295
298
}
296
299
297
300
elasticQuotaInfo := elasticQuotaSnapshotState .elasticQuotaInfos [podToAdd .Pod .Namespace ]
298
301
if elasticQuotaInfo != nil {
299
302
err := elasticQuotaInfo .addPodIfNotPresent (podToAdd .Pod )
300
303
if err != nil {
301
- klog . ErrorS (err , "Failed to add Pod to its associated elasticQuota" , "pod" , klog .KObj (podToAdd .Pod ))
304
+ logger . Error (err , "Failed to add Pod to its associated elasticQuota" , "pod" , klog .KObj (podToAdd .Pod ))
302
305
}
303
306
}
304
307
@@ -307,17 +310,19 @@ func (c *CapacityScheduling) AddPod(ctx context.Context, cycleState *framework.C
307
310
308
311
// RemovePod from pre-computed data in cycleState.
309
312
func (c * CapacityScheduling ) RemovePod (ctx context.Context , cycleState * framework.CycleState , podToSchedule * v1.Pod , podToRemove * framework.PodInfo , nodeInfo * framework.NodeInfo ) * framework.Status {
313
+ logger := klog .FromContext (ctx )
314
+
310
315
elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (cycleState )
311
316
if err != nil {
312
- klog . ErrorS (err , "Failed to read elasticQuotaSnapshot from cycleState" , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
317
+ logger . Error (err , "Failed to read elasticQuotaSnapshot from cycleState" , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
313
318
return framework .NewStatus (framework .Error , err .Error ())
314
319
}
315
320
316
321
elasticQuotaInfo := elasticQuotaSnapshotState .elasticQuotaInfos [podToRemove .Pod .Namespace ]
317
322
if elasticQuotaInfo != nil {
318
323
err = elasticQuotaInfo .deletePodIfPresent (podToRemove .Pod )
319
324
if err != nil {
320
- klog . ErrorS (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (podToRemove .Pod ))
325
+ logger . Error (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (podToRemove .Pod ))
321
326
}
322
327
}
323
328
@@ -348,11 +353,13 @@ func (c *CapacityScheduling) Reserve(ctx context.Context, state *framework.Cycle
348
353
c .Lock ()
349
354
defer c .Unlock ()
350
355
356
+ logger := klog .FromContext (ctx )
357
+
351
358
elasticQuotaInfo := c .elasticQuotaInfos [pod .Namespace ]
352
359
if elasticQuotaInfo != nil {
353
360
err := elasticQuotaInfo .addPodIfNotPresent (pod )
354
361
if err != nil {
355
- klog . ErrorS (err , "Failed to add Pod to its associated elasticQuota" , "pod" , klog .KObj (pod ))
362
+ logger . Error (err , "Failed to add Pod to its associated elasticQuota" , "pod" , klog .KObj (pod ))
356
363
return framework .NewStatus (framework .Error , err .Error ())
357
364
}
358
365
}
@@ -363,11 +370,13 @@ func (c *CapacityScheduling) Unreserve(ctx context.Context, state *framework.Cyc
363
370
c .Lock ()
364
371
defer c .Unlock ()
365
372
373
+ logger := klog .FromContext (ctx )
374
+
366
375
elasticQuotaInfo := c .elasticQuotaInfos [pod .Namespace ]
367
376
if elasticQuotaInfo != nil {
368
377
err := elasticQuotaInfo .deletePodIfPresent (pod )
369
378
if err != nil {
370
- klog . ErrorS (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (pod ))
379
+ logger . Error (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (pod ))
371
380
}
372
381
}
373
382
}
@@ -400,14 +409,16 @@ func (p *preemptor) CandidatesToVictimsMap(candidates []preemption.Candidate) ma
400
409
// We look at the node that is nominated for this pod and as long as there are
401
410
// terminating pods on the node, we don't consider this for preempting more pods.
402
411
func (p * preemptor ) PodEligibleToPreemptOthers (pod * v1.Pod , nominatedNodeStatus * framework.Status ) (bool , string ) {
412
+ logger := klog .FromContext (context .TODO ())
413
+
403
414
if pod .Spec .PreemptionPolicy != nil && * pod .Spec .PreemptionPolicy == v1 .PreemptNever {
404
- klog .V (5 ).InfoS ("Pod is not eligible for preemption because of its preemptionPolicy" , "pod" , klog .KObj (pod ), "preemptionPolicy" , v1 .PreemptNever )
415
+ logger .V (5 ).Info ("Pod is not eligible for preemption because of its preemptionPolicy" , "pod" , klog .KObj (pod ), "preemptionPolicy" , v1 .PreemptNever )
405
416
return false , "not eligible due to preemptionPolicy=Never."
406
417
}
407
418
408
419
preFilterState , err := getPreFilterState (p .state )
409
420
if err != nil {
410
- klog .V (5 ).InfoS ("Failed to read preFilterState from cycleState, err: %s" , err , "preFilterStateKey" , preFilterStateKey )
421
+ logger .V (5 ).Info ("Failed to read preFilterState from cycleState, err: %s" , err , "preFilterStateKey" , preFilterStateKey )
411
422
return false , "not eligible due to failed to read from cycleState"
412
423
}
413
424
@@ -422,7 +433,7 @@ func (p *preemptor) PodEligibleToPreemptOthers(pod *v1.Pod, nominatedNodeStatus
422
433
423
434
elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (p .state )
424
435
if err != nil {
425
- klog . ErrorS (err , "Failed to read elasticQuotaSnapshot from cycleState" , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
436
+ logger . Error (err , "Failed to read elasticQuotaSnapshot from cycleState" , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
426
437
return true , ""
427
438
}
428
439
@@ -480,25 +491,27 @@ func (p *preemptor) SelectVictimsOnNode(
480
491
pod * v1.Pod ,
481
492
nodeInfo * framework.NodeInfo ,
482
493
pdbs []* policy.PodDisruptionBudget ) ([]* v1.Pod , int , * framework.Status ) {
494
+
495
+ logger := klog .FromContext (ctx )
496
+
483
497
elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (state )
484
498
if err != nil {
485
499
msg := "Failed to read elasticQuotaSnapshot from cycleState"
486
- klog . ErrorS (err , msg , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
500
+ logger . Error (err , msg , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
487
501
return nil , 0 , framework .NewStatus (framework .Unschedulable , msg )
488
502
}
489
503
490
504
preFilterState , err := getPreFilterState (state )
491
505
if err != nil {
492
506
msg := "Failed to read preFilterState from cycleState"
493
- klog . ErrorS (err , msg , "preFilterStateKey" , preFilterStateKey )
507
+ logger . Error (err , msg , "preFilterStateKey" , preFilterStateKey )
494
508
return nil , 0 , framework .NewStatus (framework .Unschedulable , msg )
495
509
}
496
510
497
511
var nominatedPodsReqInEQWithPodReq framework.Resource
498
512
var nominatedPodsReqWithPodReq framework.Resource
499
513
podReq := preFilterState .podReq
500
514
501
- logger := klog .FromContext (ctx )
502
515
removePod := func (rpi * framework.PodInfo ) error {
503
516
if err := nodeInfo .RemovePod (logger , rpi .Pod ); err != nil {
504
517
return err
@@ -625,22 +638,22 @@ func (p *preemptor) SelectVictimsOnNode(
625
638
return false , err
626
639
}
627
640
victims = append (victims , pi .Pod )
628
- klog .V (5 ).InfoS ("Found a potential preemption victim on node" , "pod" , klog .KObj (pi .Pod ), "node" , klog .KObj (nodeInfo .Node ()))
641
+ logger .V (5 ).Info ("Found a potential preemption victim on node" , "pod" , klog .KObj (pi .Pod ), "node" , klog .KObj (nodeInfo .Node ()))
629
642
}
630
643
631
644
if preemptorWithElasticQuota && (preemptorElasticQuotaInfo .usedOverMaxWith (& nominatedPodsReqInEQWithPodReq ) || elasticQuotaInfos .aggregatedUsedOverMinWith (nominatedPodsReqWithPodReq )) {
632
645
if err := removePod (pi ); err != nil {
633
646
return false , err
634
647
}
635
648
victims = append (victims , pi .Pod )
636
- klog .V (5 ).InfoS ("Found a potential preemption victim on node" , "pod" , klog .KObj (pi .Pod ), " node" , klog .KObj (nodeInfo .Node ()))
649
+ logger .V (5 ).Info ("Found a potential preemption victim on node" , "pod" , klog .KObj (pi .Pod ), " node" , klog .KObj (nodeInfo .Node ()))
637
650
}
638
651
639
652
return fits , nil
640
653
}
641
654
for _ , pi := range violatingVictims {
642
655
if fits , err := reprievePod (pi ); err != nil {
643
- klog . ErrorS (err , "Failed to reprieve pod" , "pod" , klog .KObj (pi .Pod ))
656
+ logger . Error (err , "Failed to reprieve pod" , "pod" , klog .KObj (pi .Pod ))
644
657
return nil , 0 , framework .AsStatus (err )
645
658
} else if ! fits {
646
659
numViolatingVictim ++
@@ -649,7 +662,7 @@ func (p *preemptor) SelectVictimsOnNode(
649
662
// Now we try to reprieve non-violating victims.
650
663
for _ , pi := range nonViolatingVictims {
651
664
if _ , err := reprievePod (pi ); err != nil {
652
- klog . ErrorS (err , "Failed to reprieve pod" , "pod" , klog .KObj (pi .Pod ))
665
+ logger . Error (err , "Failed to reprieve pod" , "pod" , klog .KObj (pi .Pod ))
653
666
return nil , 0 , framework .AsStatus (err )
654
667
}
655
668
}
@@ -694,6 +707,9 @@ func (c *CapacityScheduling) deleteElasticQuota(obj interface{}) {
694
707
}
695
708
696
709
func (c * CapacityScheduling ) addPod (obj interface {}) {
710
+ ctx := context .TODO ()
711
+ logger := klog .FromContext (ctx )
712
+
697
713
pod := obj .(* v1.Pod )
698
714
699
715
c .Lock ()
@@ -703,8 +719,8 @@ func (c *CapacityScheduling) addPod(obj interface{}) {
703
719
// If elasticQuotaInfo is nil, try to list ElasticQuotas through elasticQuotaLister
704
720
if elasticQuotaInfo == nil {
705
721
var eqList v1alpha1.ElasticQuotaList
706
- if err := c .client .List (context . Background () , & eqList , client .InNamespace (pod .Namespace )); err != nil {
707
- klog . ErrorS (err , "Failed to get elasticQuota" , "elasticQuota" , pod .Namespace )
722
+ if err := c .client .List (ctx , & eqList , client .InNamespace (pod .Namespace )); err != nil {
723
+ logger . Error (err , "Failed to get elasticQuota" , "elasticQuota" , pod .Namespace )
708
724
return
709
725
}
710
726
@@ -724,11 +740,13 @@ func (c *CapacityScheduling) addPod(obj interface{}) {
724
740
725
741
err := elasticQuotaInfo .addPodIfNotPresent (pod )
726
742
if err != nil {
727
- klog . ErrorS (err , "Failed to add Pod to its associated elasticQuota" , "pod" , klog .KObj (pod ))
743
+ logger . Error (err , "Failed to add Pod to its associated elasticQuota" , "pod" , klog .KObj (pod ))
728
744
}
729
745
}
730
746
731
747
func (c * CapacityScheduling ) updatePod (oldObj , newObj interface {}) {
748
+ logger := klog .FromContext (context .TODO ())
749
+
732
750
oldPod := oldObj .(* v1.Pod )
733
751
newPod := newObj .(* v1.Pod )
734
752
@@ -744,13 +762,15 @@ func (c *CapacityScheduling) updatePod(oldObj, newObj interface{}) {
744
762
if elasticQuotaInfo != nil {
745
763
err := elasticQuotaInfo .deletePodIfPresent (newPod )
746
764
if err != nil {
747
- klog . ErrorS (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (newPod ))
765
+ logger . Error (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (newPod ))
748
766
}
749
767
}
750
768
}
751
769
}
752
770
753
771
func (c * CapacityScheduling ) deletePod (obj interface {}) {
772
+ logger := klog .FromContext (context .TODO ())
773
+
754
774
pod := obj .(* v1.Pod )
755
775
c .Lock ()
756
776
defer c .Unlock ()
@@ -759,7 +779,7 @@ func (c *CapacityScheduling) deletePod(obj interface{}) {
759
779
if elasticQuotaInfo != nil {
760
780
err := elasticQuotaInfo .deletePodIfPresent (pod )
761
781
if err != nil {
762
- klog . ErrorS (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (pod ))
782
+ logger . Error (err , "Failed to delete Pod from its associated elasticQuota" , "pod" , klog .KObj (pod ))
763
783
}
764
784
}
765
785
}
0 commit comments