Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions pkg/epp/scheduling/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package scheduling

import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/filter"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/picker"
)

// NewSchedulerConfig creates a new SchedulerConfig object with the given plugins.
Expand All @@ -42,15 +40,3 @@ type SchedulerConfig struct {
picker plugins.Picker
postSchedulePlugins []plugins.PostSchedule
}

// When the scheduler is initialized with NewScheduler function, this config will be used as default.
// it's possible to call NewSchedulerWithConfig to pass a different argument.

// For build time plugins changes, it's recommended to change the defaultConfig variable in this file.
var defaultConfig = &SchedulerConfig{
preSchedulePlugins: []plugins.PreSchedule{},
filters: []plugins.Filter{&filter.SheddableRequestFilter{}, filter.LowLatencyFilter},
scorers: map[plugins.Scorer]int{},
picker: &picker.RandomPicker{},
postSchedulePlugins: []plugins.PostSchedule{},
}
Comment on lines -50 to -56
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after having some experience with setting a custom plugins, the recommended way would be to set in main.go the scheduler using NewSchedulerWithConfig.
no need for global var. default configuration is defined inside NewScheduler instead.

81 changes: 81 additions & 0 deletions pkg/epp/scheduling/plugins/filter/decision_tree_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package filter

import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
)

// DecisionTreeFilter applies current fitler, and then recursively applies next filters
// depending success or failure of the current filter.
// It can be used to construct a flow chart algorithm.
type DecisionTreeFilter struct {
Current plugins.Filter
// NextOnSuccess filter will be applied after successfully applying the current filter.
// The filtered results will be passed to the next filter.
NextOnSuccess plugins.Filter
// NextOnFailure filter will be applied if current filter results in no pods.
// The original input will be passed to the next filter.
NextOnFailure plugins.Filter
// NextOnSuccessOrFailure is a convenience field to configure the next filter regardless of the
// success or failure of the current filter.
// NOTE: When using NextOnSuccessOrFailure, both nextOnSuccess and nextOnFailure SHOULD be nil.
// However if that's not the case, nextOnSuccess and nextOnFailure will be used, instead of
// NextOnSuccessOrFailure, in the success and failure scenarios, respectively.
NextOnSuccessOrFailure plugins.Filter
}

// Name returns the name of the filter.
func (f *DecisionTreeFilter) Name() string {
if f == nil {
return "nil"
}
return f.Current.Name()
}

// Filter filters out pods that doesn't meet the filter criteria.
func (f *DecisionTreeFilter) Filter(ctx *types.SchedulingContext, pods []types.Pod) []types.Pod {
loggerTrace := ctx.Logger.V(logutil.TRACE)
filteredPod := f.Current.Filter(ctx, pods)

next := f.NextOnSuccessOrFailure
if len(filteredPod) > 0 {
if f.NextOnSuccess == nil && f.NextOnSuccessOrFailure == nil {
// No succeeding filters to run, return.
return filteredPod
}
if f.NextOnSuccess != nil {
next = f.NextOnSuccess
}
loggerTrace.Info("Filter succeeded", "filter", f.Name(), "next", next.Name(), "filteredPodCount", len(filteredPod))
// On success, pass the filtered result to the next filter.
return next.Filter(ctx, filteredPod)
} else {
if f.NextOnFailure == nil && f.NextOnSuccessOrFailure == nil {
// No succeeding filters to run, return.
return filteredPod
}
if f.NextOnFailure != nil {
next = f.NextOnFailure
}
loggerTrace.Info("Filter failed", "filter", f.Name(), "next", next.Name())
// On failure, pass the initial set of pods to the next filter.
return next.Filter(ctx, pods)
}
}
Loading