@@ -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.
@@ -132,6 +132,7 @@ func InitNewFilterWeigherPipeline[RequestType FilterWeigherPipelineRequest](
132132// During this process, the request is mutated to only include the
133133// remaining hosts.
134134func (p * filterWeigherPipeline [RequestType ]) runFilters (
135+ ctx context.Context ,
135136 log * slog.Logger ,
136137 request RequestType ,
137138) (filteredRequest RequestType ) {
@@ -141,7 +142,7 @@ func (p *filterWeigherPipeline[RequestType]) runFilters(
141142 filter := p .filters [filterName ]
142143 stepLog := log .With ("filter" , filterName )
143144 stepLog .Info ("scheduler: running filter" )
144- result , err := filter .Run (stepLog , filteredRequest )
145+ result , err := filter .Run (ctx , stepLog , filteredRequest )
145146 if errors .Is (err , ErrStepSkipped ) {
146147 stepLog .Info ("scheduler: filter skipped" )
147148 continue
@@ -160,6 +161,7 @@ func (p *filterWeigherPipeline[RequestType]) runFilters(
160161
161162// Execute weighers and collect their activations by step name.
162163func (p * filterWeigherPipeline [RequestType ]) runWeighers (
164+ ctx context.Context ,
163165 log * slog.Logger ,
164166 filteredRequest RequestType ,
165167) map [string ]map [string ]float64 {
@@ -173,7 +175,7 @@ func (p *filterWeigherPipeline[RequestType]) runWeighers(
173175 wg .Go (func () {
174176 stepLog := log .With ("weigher" , weigherName )
175177 stepLog .Info ("scheduler: running weigher" )
176- result , err := weigher .Run (stepLog , filteredRequest )
178+ result , err := weigher .Run (ctx , stepLog , filteredRequest )
177179 if errors .Is (err , ErrStepSkipped ) {
178180 stepLog .Info ("scheduler: weigher skipped" )
179181 return
@@ -243,7 +245,7 @@ func (s *filterWeigherPipeline[RequestType]) sortHostsByWeights(weights map[stri
243245}
244246
245247// Evaluate the pipeline and return a list of hosts in order of preference.
246- func (p * filterWeigherPipeline [RequestType ]) Run (request RequestType ) (v1alpha1.DecisionResult , error ) {
248+ func (p * filterWeigherPipeline [RequestType ]) Run (ctx context. Context , request RequestType ) (v1alpha1.DecisionResult , error ) {
247249 slogArgs := request .GetTraceLogArgs ()
248250 slogArgsAny := make ([]any , 0 , len (slogArgs ))
249251 for _ , arg := range slogArgs {
@@ -260,7 +262,7 @@ func (p *filterWeigherPipeline[RequestType]) Run(request RequestType) (v1alpha1.
260262
261263 // Run filters first to reduce the number of hosts.
262264 // Any weights assigned to filtered out hosts are ignored.
263- filteredRequest := p .runFilters (traceLog , request )
265+ filteredRequest := p .runFilters (ctx , traceLog , request )
264266 traceLog .Info (
265267 "scheduler: finished filters" ,
266268 "remainingHosts" , filteredRequest .GetHosts (),
@@ -271,7 +273,7 @@ func (p *filterWeigherPipeline[RequestType]) Run(request RequestType) (v1alpha1.
271273 for _ , host := range filteredRequest .GetHosts () {
272274 remainingWeights [host ] = inWeights [host ]
273275 }
274- stepWeights := p .runWeighers (traceLog , filteredRequest )
276+ stepWeights := p .runWeighers (ctx , traceLog , filteredRequest )
275277 outWeights := p .applyWeights (stepWeights , remainingWeights )
276278 traceLog .Info ("scheduler: output weights" , "weights" , outWeights )
277279
0 commit comments