@@ -273,7 +273,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
273
273
}
274
274
p , err := factory (args , f )
275
275
if err != nil {
276
- return nil , fmt .Errorf ("error initializing plugin %q: %v " , name , err )
276
+ return nil , fmt .Errorf ("initializing plugin %q: %w " , name , err )
277
277
}
278
278
pluginsMap [name ] = p
279
279
@@ -397,9 +397,9 @@ func (f *frameworkImpl) RunPreFilterPlugins(ctx context.Context, state *framewor
397
397
if status .IsUnschedulable () {
398
398
return status
399
399
}
400
- msg := fmt . Sprintf ( "prefilter plugin %q failed for pod %q: %v" , pl . Name (), pod . Name , status .Message () )
401
- klog .Error ( msg )
402
- return framework .NewStatus ( framework . Error , msg )
400
+ err := status .AsError ( )
401
+ klog .ErrorS ( err , "Failed running PreFilter plugin" , "plugin" , pl . Name (), "pod" , klog . KObj ( pod ) )
402
+ return framework .AsStatus ( fmt . Errorf ( "running PreFilter plugin %q: %w" , pl . Name (), err ) )
403
403
}
404
404
}
405
405
@@ -432,10 +432,9 @@ func (f *frameworkImpl) RunPreFilterExtensionAddPod(
432
432
}
433
433
status = f .runPreFilterExtensionAddPod (ctx , pl , state , podToSchedule , podToAdd , nodeInfo )
434
434
if ! status .IsSuccess () {
435
- msg := fmt .Sprintf ("error while running AddPod for plugin %q while scheduling pod %q: %v" ,
436
- pl .Name (), podToSchedule .Name , status .Message ())
437
- klog .Error (msg )
438
- return framework .NewStatus (framework .Error , msg )
435
+ err := status .AsError ()
436
+ klog .ErrorS (err , "Failed running AddPod on PreFilter plugin" , "plugin" , pl .Name (), "pod" , klog .KObj (podToSchedule ))
437
+ return framework .AsStatus (fmt .Errorf ("running AddPod on PreFilter plugin %q: %w" , pl .Name (), err ))
439
438
}
440
439
}
441
440
@@ -468,10 +467,9 @@ func (f *frameworkImpl) RunPreFilterExtensionRemovePod(
468
467
}
469
468
status = f .runPreFilterExtensionRemovePod (ctx , pl , state , podToSchedule , podToRemove , nodeInfo )
470
469
if ! status .IsSuccess () {
471
- msg := fmt .Sprintf ("error while running RemovePod for plugin %q while scheduling pod %q: %v" ,
472
- pl .Name (), podToSchedule .Name , status .Message ())
473
- klog .Error (msg )
474
- return framework .NewStatus (framework .Error , msg )
470
+ err := status .AsError ()
471
+ klog .ErrorS (err , "Failed running RemovePod on PreFilter plugin" , "plugin" , pl .Name (), "pod" , klog .KObj (podToSchedule ))
472
+ return framework .AsStatus (fmt .Errorf ("running RemovePod on PreFilter plugin %q: %w" , pl .Name (), err ))
475
473
}
476
474
}
477
475
@@ -577,9 +575,9 @@ func (f *frameworkImpl) RunPreScorePlugins(
577
575
for _ , pl := range f .preScorePlugins {
578
576
status = f .runPreScorePlugin (ctx , pl , state , pod , nodes )
579
577
if ! status .IsSuccess () {
580
- msg := fmt . Sprintf ( "error while running %q prescore plugin for pod %q: %v" , pl . Name (), pod . Name , status .Message () )
581
- klog .Error ( msg )
582
- return framework .NewStatus ( framework . Error , msg )
578
+ err := status .AsError ( )
579
+ klog .ErrorS ( err , "Failed running PreScore plugin" , "plugin" , pl . Name (), "pod" , klog . KObj ( pod ) )
580
+ return framework .AsStatus ( fmt . Errorf ( "running PreScore plugin %q: %w" , pl . Name (), err ) )
583
581
}
584
582
}
585
583
@@ -618,7 +616,8 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy
618
616
nodeName := nodes [index ].Name
619
617
s , status := f .runScorePlugin (ctx , pl , state , pod , nodeName )
620
618
if ! status .IsSuccess () {
621
- errCh .SendErrorWithCancel (fmt .Errorf (status .Message ()), cancel )
619
+ err := fmt .Errorf ("plugin %q failed with: %w" , pl .Name (), status .AsError ())
620
+ errCh .SendErrorWithCancel (err , cancel )
622
621
return
623
622
}
624
623
pluginToNodeScores [pl .Name ()][index ] = framework.NodeScore {
@@ -628,9 +627,8 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy
628
627
}
629
628
})
630
629
if err := errCh .ReceiveError (); err != nil {
631
- msg := fmt .Sprintf ("error while running score plugin for pod %q: %v" , pod .Name , err )
632
- klog .Error (msg )
633
- return nil , framework .NewStatus (framework .Error , msg )
630
+ klog .ErrorS (err , "Failed running Score plugins" , "pod" , klog .KObj (pod ))
631
+ return nil , framework .AsStatus (fmt .Errorf ("running Score plugins: %w" , err ))
634
632
}
635
633
636
634
// Run NormalizeScore method for each ScorePlugin in parallel.
@@ -642,15 +640,14 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy
642
640
}
643
641
status := f .runScoreExtension (ctx , pl , state , pod , nodeScoreList )
644
642
if ! status .IsSuccess () {
645
- err := fmt .Errorf ("normalize score plugin %q failed with error %v " , pl .Name (), status .Message ())
643
+ err := fmt .Errorf ("plugin %q failed with: %w " , pl .Name (), status .AsError ())
646
644
errCh .SendErrorWithCancel (err , cancel )
647
645
return
648
646
}
649
647
})
650
648
if err := errCh .ReceiveError (); err != nil {
651
- msg := fmt .Sprintf ("error while running normalize score plugin for pod %q: %v" , pod .Name , err )
652
- klog .Error (msg )
653
- return nil , framework .NewStatus (framework .Error , msg )
649
+ klog .ErrorS (err , "Failed running Normalize on Score plugins" , "pod" , klog .KObj (pod ))
650
+ return nil , framework .AsStatus (fmt .Errorf ("running Normalize on Score plugins: %w" , err ))
654
651
}
655
652
656
653
// Apply score defaultWeights for each ScorePlugin in parallel.
@@ -663,17 +660,16 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy
663
660
for i , nodeScore := range nodeScoreList {
664
661
// return error if score plugin returns invalid score.
665
662
if nodeScore .Score > framework .MaxNodeScore || nodeScore .Score < framework .MinNodeScore {
666
- err := fmt .Errorf ("score plugin %q returns an invalid score %v, it should in the range of [%v, %v] after normalizing" , pl .Name (), nodeScore .Score , framework .MinNodeScore , framework .MaxNodeScore )
663
+ err := fmt .Errorf ("plugin %q returns an invalid score %v, it should in the range of [%v, %v] after normalizing" , pl .Name (), nodeScore .Score , framework .MinNodeScore , framework .MaxNodeScore )
667
664
errCh .SendErrorWithCancel (err , cancel )
668
665
return
669
666
}
670
667
nodeScoreList [i ].Score = nodeScore .Score * int64 (weight )
671
668
}
672
669
})
673
670
if err := errCh .ReceiveError (); err != nil {
674
- msg := fmt .Sprintf ("error while applying score defaultWeights for pod %q: %v" , pod .Name , err )
675
- klog .Error (msg )
676
- return nil , framework .NewStatus (framework .Error , msg )
671
+ klog .ErrorS (err , "Failed applying score defaultWeights on Score plugins" , "pod" , klog .KObj (pod ))
672
+ return nil , framework .AsStatus (fmt .Errorf ("applying score defaultWeights on Score plugins: %w" , err ))
677
673
}
678
674
679
675
return pluginToNodeScores , nil
@@ -710,9 +706,9 @@ func (f *frameworkImpl) RunPreBindPlugins(ctx context.Context, state *framework.
710
706
for _ , pl := range f .preBindPlugins {
711
707
status = f .runPreBindPlugin (ctx , pl , state , pod , nodeName )
712
708
if ! status .IsSuccess () {
713
- err := fmt . Errorf ( "error while running %q prebind plugin for pod %q: %w" , pl . Name (), pod . Name , status .AsError () )
714
- klog .Error (err )
715
- return framework .AsStatus (err )
709
+ err := status .AsError ()
710
+ klog .ErrorS (err , "Failed running PreBind plugin" , "plugin" , pl . Name (), "pod" , klog . KObj ( pod ) )
711
+ return framework .AsStatus (fmt . Errorf ( "running PreBind plugin %q: %w" , pl . Name (), err ) )
716
712
}
717
713
}
718
714
return nil
@@ -743,9 +739,9 @@ func (f *frameworkImpl) RunBindPlugins(ctx context.Context, state *framework.Cyc
743
739
continue
744
740
}
745
741
if ! status .IsSuccess () {
746
- err := fmt . Errorf ( "plugin %q failed to bind pod \" %v/%v \" : %w" , bp . Name (), pod . Namespace , pod . Name , status .AsError () )
747
- klog .Error (err )
748
- return framework .AsStatus (err )
742
+ err := status .AsError ()
743
+ klog .ErrorS (err , "Failed running Bind plugin" , "plugin" , bp . Name (), "pod" , klog . KObj ( pod ) )
744
+ return framework .AsStatus (fmt . Errorf ( "running Bind plugin %q: %w" , bp . Name (), err ) )
749
745
}
750
746
return status
751
747
}
@@ -796,9 +792,9 @@ func (f *frameworkImpl) RunReservePluginsReserve(ctx context.Context, state *fra
796
792
for _ , pl := range f .reservePlugins {
797
793
status = f .runReservePluginReserve (ctx , pl , state , pod , nodeName )
798
794
if ! status .IsSuccess () {
799
- msg := fmt . Sprintf ( "error while running Reserve in %q reserve plugin for pod %q: %v" , pl . Name (), pod . Name , status .Message () )
800
- klog .Error ( msg )
801
- return framework .NewStatus ( framework . Error , msg )
795
+ err := status .AsError ( )
796
+ klog .ErrorS ( err , "Failed running Reserve plugin" , "plugin" , pl . Name (), "pod" , klog . KObj ( pod ) )
797
+ return framework .AsStatus ( fmt . Errorf ( "running Reserve plugin %q: %w" , pl . Name (), err ) )
802
798
}
803
799
}
804
800
return nil
@@ -867,9 +863,9 @@ func (f *frameworkImpl) RunPermitPlugins(ctx context.Context, state *framework.C
867
863
pluginsWaitTime [pl .Name ()] = timeout
868
864
statusCode = framework .Wait
869
865
} else {
870
- msg := fmt . Sprintf ( "error while running %q permit plugin for pod %q: %v" , pl . Name (), pod . Name , status .Message () )
871
- klog .Error ( msg )
872
- return framework .NewStatus ( framework . Error , msg )
866
+ err := status .AsError ( )
867
+ klog .ErrorS ( err , "Failed running Permit plugin" , "plugin" , pl . Name (), "pod" , klog . KObj ( pod ) )
868
+ return framework .AsStatus ( fmt . Errorf ( "running Permit plugin %q: %w" , pl . Name (), err ) )
873
869
}
874
870
}
875
871
}
@@ -912,9 +908,9 @@ func (f *frameworkImpl) WaitOnPermit(ctx context.Context, pod *v1.Pod) (status *
912
908
klog .V (4 ).Infof (msg )
913
909
return framework .NewStatus (s .Code (), msg )
914
910
}
915
- msg := fmt . Sprintf ( "error received while waiting on permit for pod %q: %v" , pod . Name , s . Message () )
916
- klog .Error ( msg )
917
- return framework .NewStatus ( framework . Error , msg )
911
+ err := s . AsError ( )
912
+ klog .ErrorS ( err , "Failed waiting on permit for pod" , "pod" , klog . KObj ( pod ) )
913
+ return framework .AsStatus ( fmt . Errorf ( "waiting on permit for pod: %w" , err ) )
918
914
}
919
915
return nil
920
916
}
0 commit comments