@@ -125,6 +125,7 @@ func New(ctx context.Context, obj runtime.Object, handle framework.Handle) (fram
125125 podLister : handle .SharedInformerFactory ().Core ().V1 ().Pods ().Lister (),
126126 pdbLister : getPDBLister (handle .SharedInformerFactory ()),
127127 }
128+ logger := klog .FromContext (ctx )
128129
129130 client , err := client .New (handle .KubeConfig (), client.Options {Scheme : scheme })
130131 if err != nil {
@@ -187,7 +188,7 @@ func New(ctx context.Context, obj runtime.Object, handle framework.Handle) (fram
187188 },
188189 },
189190 )
190- klog . InfoS ("CapacityScheduling start" )
191+ logger . Info ("CapacityScheduling start" )
191192 return c , nil
192193}
193194
@@ -288,17 +289,19 @@ func (c *CapacityScheduling) PreFilterExtensions() framework.PreFilterExtensions
288289
289290// AddPod from pre-computed data in cycleState.
290291func (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+
291294 elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (cycleState )
292295 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 )
294297 return framework .NewStatus (framework .Error , err .Error ())
295298 }
296299
297300 elasticQuotaInfo := elasticQuotaSnapshotState .elasticQuotaInfos [podToAdd .Pod .Namespace ]
298301 if elasticQuotaInfo != nil {
299302 err := elasticQuotaInfo .addPodIfNotPresent (podToAdd .Pod )
300303 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 ))
302305 }
303306 }
304307
@@ -307,17 +310,19 @@ func (c *CapacityScheduling) AddPod(ctx context.Context, cycleState *framework.C
307310
308311// RemovePod from pre-computed data in cycleState.
309312func (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+
310315 elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (cycleState )
311316 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 )
313318 return framework .NewStatus (framework .Error , err .Error ())
314319 }
315320
316321 elasticQuotaInfo := elasticQuotaSnapshotState .elasticQuotaInfos [podToRemove .Pod .Namespace ]
317322 if elasticQuotaInfo != nil {
318323 err = elasticQuotaInfo .deletePodIfPresent (podToRemove .Pod )
319324 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 ))
321326 }
322327 }
323328
@@ -348,11 +353,13 @@ func (c *CapacityScheduling) Reserve(ctx context.Context, state *framework.Cycle
348353 c .Lock ()
349354 defer c .Unlock ()
350355
356+ logger := klog .FromContext (ctx )
357+
351358 elasticQuotaInfo := c .elasticQuotaInfos [pod .Namespace ]
352359 if elasticQuotaInfo != nil {
353360 err := elasticQuotaInfo .addPodIfNotPresent (pod )
354361 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 ))
356363 return framework .NewStatus (framework .Error , err .Error ())
357364 }
358365 }
@@ -363,11 +370,13 @@ func (c *CapacityScheduling) Unreserve(ctx context.Context, state *framework.Cyc
363370 c .Lock ()
364371 defer c .Unlock ()
365372
373+ logger := klog .FromContext (ctx )
374+
366375 elasticQuotaInfo := c .elasticQuotaInfos [pod .Namespace ]
367376 if elasticQuotaInfo != nil {
368377 err := elasticQuotaInfo .deletePodIfPresent (pod )
369378 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 ))
371380 }
372381 }
373382}
@@ -400,14 +409,16 @@ func (p *preemptor) CandidatesToVictimsMap(candidates []preemption.Candidate) ma
400409// We look at the node that is nominated for this pod and as long as there are
401410// terminating pods on the node, we don't consider this for preempting more pods.
402411func (p * preemptor ) PodEligibleToPreemptOthers (pod * v1.Pod , nominatedNodeStatus * framework.Status ) (bool , string ) {
412+ logger := klog .FromContext (context .TODO ())
413+
403414 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 )
405416 return false , "not eligible due to preemptionPolicy=Never."
406417 }
407418
408419 preFilterState , err := getPreFilterState (p .state )
409420 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 )
411422 return false , "not eligible due to failed to read from cycleState"
412423 }
413424
@@ -422,7 +433,7 @@ func (p *preemptor) PodEligibleToPreemptOthers(pod *v1.Pod, nominatedNodeStatus
422433
423434 elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (p .state )
424435 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 )
426437 return true , ""
427438 }
428439
@@ -480,25 +491,27 @@ func (p *preemptor) SelectVictimsOnNode(
480491 pod * v1.Pod ,
481492 nodeInfo * framework.NodeInfo ,
482493 pdbs []* policy.PodDisruptionBudget ) ([]* v1.Pod , int , * framework.Status ) {
494+
495+ logger := klog .FromContext (ctx )
496+
483497 elasticQuotaSnapshotState , err := getElasticQuotaSnapshotState (state )
484498 if err != nil {
485499 msg := "Failed to read elasticQuotaSnapshot from cycleState"
486- klog . ErrorS (err , msg , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
500+ logger . Error (err , msg , "elasticQuotaSnapshotKey" , ElasticQuotaSnapshotKey )
487501 return nil , 0 , framework .NewStatus (framework .Unschedulable , msg )
488502 }
489503
490504 preFilterState , err := getPreFilterState (state )
491505 if err != nil {
492506 msg := "Failed to read preFilterState from cycleState"
493- klog . ErrorS (err , msg , "preFilterStateKey" , preFilterStateKey )
507+ logger . Error (err , msg , "preFilterStateKey" , preFilterStateKey )
494508 return nil , 0 , framework .NewStatus (framework .Unschedulable , msg )
495509 }
496510
497511 var nominatedPodsReqInEQWithPodReq framework.Resource
498512 var nominatedPodsReqWithPodReq framework.Resource
499513 podReq := preFilterState .podReq
500514
501- logger := klog .FromContext (ctx )
502515 removePod := func (rpi * framework.PodInfo ) error {
503516 if err := nodeInfo .RemovePod (logger , rpi .Pod ); err != nil {
504517 return err
@@ -625,22 +638,22 @@ func (p *preemptor) SelectVictimsOnNode(
625638 return false , err
626639 }
627640 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 ()))
629642 }
630643
631644 if preemptorWithElasticQuota && (preemptorElasticQuotaInfo .usedOverMaxWith (& nominatedPodsReqInEQWithPodReq ) || elasticQuotaInfos .aggregatedUsedOverMinWith (nominatedPodsReqWithPodReq )) {
632645 if err := removePod (pi ); err != nil {
633646 return false , err
634647 }
635648 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 ()))
637650 }
638651
639652 return fits , nil
640653 }
641654 for _ , pi := range violatingVictims {
642655 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 ))
644657 return nil , 0 , framework .AsStatus (err )
645658 } else if ! fits {
646659 numViolatingVictim ++
@@ -649,7 +662,7 @@ func (p *preemptor) SelectVictimsOnNode(
649662 // Now we try to reprieve non-violating victims.
650663 for _ , pi := range nonViolatingVictims {
651664 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 ))
653666 return nil , 0 , framework .AsStatus (err )
654667 }
655668 }
@@ -694,6 +707,9 @@ func (c *CapacityScheduling) deleteElasticQuota(obj interface{}) {
694707}
695708
696709func (c * CapacityScheduling ) addPod (obj interface {}) {
710+ ctx := context .TODO ()
711+ logger := klog .FromContext (ctx )
712+
697713 pod := obj .(* v1.Pod )
698714
699715 c .Lock ()
@@ -703,8 +719,8 @@ func (c *CapacityScheduling) addPod(obj interface{}) {
703719 // If elasticQuotaInfo is nil, try to list ElasticQuotas through elasticQuotaLister
704720 if elasticQuotaInfo == nil {
705721 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 )
708724 return
709725 }
710726
@@ -724,11 +740,13 @@ func (c *CapacityScheduling) addPod(obj interface{}) {
724740
725741 err := elasticQuotaInfo .addPodIfNotPresent (pod )
726742 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 ))
728744 }
729745}
730746
731747func (c * CapacityScheduling ) updatePod (oldObj , newObj interface {}) {
748+ logger := klog .FromContext (context .TODO ())
749+
732750 oldPod := oldObj .(* v1.Pod )
733751 newPod := newObj .(* v1.Pod )
734752
@@ -744,13 +762,15 @@ func (c *CapacityScheduling) updatePod(oldObj, newObj interface{}) {
744762 if elasticQuotaInfo != nil {
745763 err := elasticQuotaInfo .deletePodIfPresent (newPod )
746764 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 ))
748766 }
749767 }
750768 }
751769}
752770
753771func (c * CapacityScheduling ) deletePod (obj interface {}) {
772+ logger := klog .FromContext (context .TODO ())
773+
754774 pod := obj .(* v1.Pod )
755775 c .Lock ()
756776 defer c .Unlock ()
@@ -759,7 +779,7 @@ func (c *CapacityScheduling) deletePod(obj interface{}) {
759779 if elasticQuotaInfo != nil {
760780 err := elasticQuotaInfo .deletePodIfPresent (pod )
761781 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 ))
763783 }
764784 }
765785}
0 commit comments