@@ -235,12 +235,12 @@ func (pl *TestPlugin) Reserve(ctx context.Context, state fwk.CycleState, p *v1.P
235235func (pl * TestPlugin ) Unreserve (ctx context.Context , state fwk.CycleState , p * v1.Pod , nodeName string ) {
236236}
237237
238- func (pl * TestPlugin ) PreBind (ctx context.Context , state fwk.CycleState , p * v1.Pod , nodeName string ) * fwk.Status {
239- return fwk .NewStatus (fwk .Code (pl .inj .PreBindStatus ), injectReason )
238+ func (pl * TestPlugin ) PreBindPreFlight (ctx context.Context , state fwk.CycleState , p * v1.Pod , nodeName string ) * fwk.Status {
239+ return fwk .NewStatus (fwk .Code (pl .inj .PreBindPreFlightStatus ), injectReason )
240240}
241241
242- func (pl * TestPlugin ) PreBindPreFlight (ctx context.Context , state fwk.CycleState , p * v1.Pod , nodeName string ) * fwk.Status {
243- return nil
242+ func (pl * TestPlugin ) PreBind (ctx context.Context , state fwk.CycleState , p * v1.Pod , nodeName string ) * fwk.Status {
243+ return fwk . NewStatus ( fwk . Code ( pl . inj . PreBindStatus ), injectReason )
244244}
245245
246246func (pl * TestPlugin ) PostBind (ctx context.Context , state fwk.CycleState , p * v1.Pod , nodeName string ) {
@@ -2613,6 +2613,110 @@ func TestPreBindPlugins(t *testing.T) {
26132613 }
26142614}
26152615
2616+ func TestPreBindPreFlightPlugins (t * testing.T ) {
2617+ tests := []struct {
2618+ name string
2619+ plugins []* TestPlugin
2620+ wantStatus * fwk.Status
2621+ }{
2622+ {
2623+ name : "Skip when there's no PreBind Plugin" ,
2624+ plugins : []* TestPlugin {},
2625+ wantStatus : fwk .NewStatus (fwk .Skip ),
2626+ },
2627+ {
2628+ name : "Success when PreBindPreFlight returns Success" ,
2629+ plugins : []* TestPlugin {
2630+ {
2631+ name : "TestPlugin1" ,
2632+ inj : injectedResult {PreBindPreFlightStatus : int (fwk .Skip )},
2633+ },
2634+ {
2635+ name : "TestPlugin2" ,
2636+ inj : injectedResult {PreBindPreFlightStatus : int (fwk .Success )},
2637+ },
2638+ },
2639+ wantStatus : nil ,
2640+ },
2641+ {
2642+ name : "Skip when all PreBindPreFlight returns Skip" ,
2643+ plugins : []* TestPlugin {
2644+ {
2645+ name : "TestPlugin1" ,
2646+ inj : injectedResult {PreBindPreFlightStatus : int (fwk .Skip )},
2647+ },
2648+ {
2649+ name : "TestPlugin2" ,
2650+ inj : injectedResult {PreBindPreFlightStatus : int (fwk .Skip )},
2651+ },
2652+ },
2653+ wantStatus : fwk .NewStatus (fwk .Skip ),
2654+ },
2655+ {
2656+ name : "Error when PreBindPreFlight returns Error" ,
2657+ plugins : []* TestPlugin {
2658+ {
2659+ name : "TestPlugin1" ,
2660+ inj : injectedResult {PreBindPreFlightStatus : int (fwk .Skip )},
2661+ },
2662+ {
2663+ name : "TestPlugin2" ,
2664+ inj : injectedResult {PreBindPreFlightStatus : int (fwk .Error )},
2665+ },
2666+ },
2667+ wantStatus : fwk .AsStatus (fmt .Errorf (`running PreBindPreFlight "TestPlugin2": %w` , errInjectedStatus )),
2668+ },
2669+ {
2670+ name : "Error when PreBindPreFlight returns Unschedulable" ,
2671+ plugins : []* TestPlugin {
2672+ {
2673+ name : "TestPlugin" ,
2674+ inj : injectedResult {PreBindPreFlightStatus : int (fwk .Unschedulable )},
2675+ },
2676+ },
2677+ wantStatus : fwk .NewStatus (fwk .Error , "PreBindPreFlight TestPlugin returned \" Unschedulable\" , which is unsupported. It is supposed to return Success, Skip, or Error status" ),
2678+ },
2679+ }
2680+
2681+ for _ , tt := range tests {
2682+ t .Run (tt .name , func (t * testing.T ) {
2683+ _ , ctx := ktesting .NewTestContext (t )
2684+ registry := Registry {}
2685+ configPlugins := & config.Plugins {}
2686+
2687+ for _ , pl := range tt .plugins {
2688+ tmpPl := pl
2689+ if err := registry .Register (pl .name , func (_ context.Context , _ runtime.Object , _ framework.Handle ) (framework.Plugin , error ) {
2690+ return tmpPl , nil
2691+ }); err != nil {
2692+ t .Fatalf ("Unable to register pre bind plugins: %s" , pl .name )
2693+ }
2694+
2695+ configPlugins .PreBind .Enabled = append (
2696+ configPlugins .PreBind .Enabled ,
2697+ config.Plugin {Name : pl .name },
2698+ )
2699+ }
2700+ profile := config.KubeSchedulerProfile {Plugins : configPlugins }
2701+ ctx , cancel := context .WithCancel (ctx )
2702+ defer cancel ()
2703+ f , err := newFrameworkWithQueueSortAndBind (ctx , registry , profile )
2704+ if err != nil {
2705+ t .Fatalf ("fail to create framework: %s" , err )
2706+ }
2707+ defer func () {
2708+ _ = f .Close ()
2709+ }()
2710+
2711+ status := f .RunPreBindPreFlights (ctx , state , pod , "" )
2712+
2713+ if diff := cmp .Diff (tt .wantStatus , status , statusCmpOpts ... ); diff != "" {
2714+ t .Errorf ("Wrong status code (-want,+got):\n %s" , diff )
2715+ }
2716+ })
2717+ }
2718+ }
2719+
26162720func TestReservePlugins (t * testing.T ) {
26172721 tests := []struct {
26182722 name string
@@ -3458,6 +3562,7 @@ type injectedResult struct {
34583562 PostFilterStatus int `json:"postFilterStatus,omitempty"`
34593563 PreScoreStatus int `json:"preScoreStatus,omitempty"`
34603564 ReserveStatus int `json:"reserveStatus,omitempty"`
3565+ PreBindPreFlightStatus int `json:"preBindPreFlightStatus,omitempty"`
34613566 PreBindStatus int `json:"preBindStatus,omitempty"`
34623567 BindStatus int `json:"bindStatus,omitempty"`
34633568 PermitStatus int `json:"permitStatus,omitempty"`
0 commit comments