@@ -19,7 +19,7 @@ import (
1919
2020type FilterWeigherPipeline [RequestType FilterWeigherPipelineRequest ] interface {
2121 // Run the scheduling pipeline with the given request.
22- Run (request RequestType ) (v1alpha1.DecisionResult , error )
22+ Run (ctx context. Context , request RequestType ) (v1alpha1.DecisionResult , error )
2323}
2424
2525// Pipeline of scheduler steps.
@@ -136,6 +136,7 @@ func InitNewFilterWeigherPipeline[RequestType FilterWeigherPipelineRequest](
136136// During this process, the request is mutated to only include the
137137// remaining hosts.
138138func (p * filterWeigherPipeline [RequestType ]) runFilters (
139+ ctx context.Context ,
139140 log * slog.Logger ,
140141 request RequestType ,
141142) (filteredRequest RequestType , stepResults []v1alpha1.StepResult ) {
@@ -145,7 +146,7 @@ func (p *filterWeigherPipeline[RequestType]) runFilters(
145146 filter := p .filters [filterName ]
146147 stepLog := log .With ("filter" , filterName )
147148 stepLog .Info ("scheduler: running filter" )
148- result , err := filter .Run (stepLog , filteredRequest )
149+ result , err := filter .Run (ctx , stepLog , filteredRequest )
149150 if errors .Is (err , ErrStepSkipped ) {
150151 stepLog .Info ("scheduler: filter skipped" )
151152 continue
@@ -168,6 +169,7 @@ func (p *filterWeigherPipeline[RequestType]) runFilters(
168169
169170// Execute weighers and collect their activations by step name.
170171func (p * filterWeigherPipeline [RequestType ]) runWeighers (
172+ ctx context.Context ,
171173 log * slog.Logger ,
172174 filteredRequest RequestType ,
173175) map [string ]map [string ]float64 {
@@ -181,7 +183,7 @@ func (p *filterWeigherPipeline[RequestType]) runWeighers(
181183 wg .Go (func () {
182184 stepLog := log .With ("weigher" , weigherName )
183185 stepLog .Info ("scheduler: running weigher" )
184- result , err := weigher .Run (stepLog , filteredRequest )
186+ result , err := weigher .Run (ctx , stepLog , filteredRequest )
185187 if errors .Is (err , ErrStepSkipped ) {
186188 stepLog .Info ("scheduler: weigher skipped" )
187189 return
@@ -262,7 +264,7 @@ func (s *filterWeigherPipeline[RequestType]) sortHostsByWeights(weights map[stri
262264}
263265
264266// Evaluate the pipeline and return a list of hosts in order of preference.
265- func (p * filterWeigherPipeline [RequestType ]) Run (request RequestType ) (v1alpha1.DecisionResult , error ) {
267+ func (p * filterWeigherPipeline [RequestType ]) Run (ctx context. Context , request RequestType ) (v1alpha1.DecisionResult , error ) {
266268 slogArgs := request .GetTraceLogArgs ()
267269 slogArgsAny := make ([]any , 0 , len (slogArgs ))
268270 for _ , arg := range slogArgs {
@@ -279,7 +281,7 @@ func (p *filterWeigherPipeline[RequestType]) Run(request RequestType) (v1alpha1.
279281
280282 // Run filters first to reduce the number of hosts.
281283 // Any weights assigned to filtered out hosts are ignored.
282- filteredRequest , filterStepResults := p .runFilters (traceLog , request )
284+ filteredRequest , filterStepResults := p .runFilters (ctx , traceLog , request )
283285 traceLog .Info (
284286 "scheduler: finished filters" ,
285287 "remainingHosts" , filteredRequest .GetHosts (),
@@ -290,7 +292,7 @@ func (p *filterWeigherPipeline[RequestType]) Run(request RequestType) (v1alpha1.
290292 for _ , host := range filteredRequest .GetHosts () {
291293 remainingWeights [host ] = inWeights [host ]
292294 }
293- stepWeights := p .runWeighers (traceLog , filteredRequest )
295+ stepWeights := p .runWeighers (ctx , traceLog , filteredRequest )
294296 outWeights := p .applyWeights (traceLog , stepWeights , remainingWeights )
295297 traceLog .Info ("scheduler: output weights" , "weights" , outWeights )
296298
0 commit comments