Skip to content

Commit 1569cde

Browse files
vMaroonmayabar
authored andcommitted
- minor refactoring
- updated scorer interface Signed-off-by: Maroon Ayoub <[email protected]>
1 parent 58797e3 commit 1569cde

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

pkg/epp/scheduling/plugins/picker/random_picker.go

+4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ import (
2424
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
2525
)
2626

27+
// RandomPicker picks a pod randomly from the list of candidates.
2728
type RandomPicker struct{}
2829

30+
var _ types.Picker = &RandomPicker{}
31+
32+
// Name returns the name of the picker.
2933
func (rp *RandomPicker) Name() string {
3034
return "random"
3135
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
<<<<<<<< HEAD:pkg/epp/scheduling/plugins/picker/random_picker.go
18+
package picker
19+
========
20+
package pickers
21+
>>>>>>>> 62526b1 (- minor refactoring):pkg/epp/scheduling/plugins/pickers/random.go
22+
23+
import (
24+
"fmt"
25+
"math/rand"
26+
27+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
28+
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
29+
)
30+
31+
// RandomPicker picks a pod randomly from the list of candidates.
32+
type RandomPicker struct{}
33+
34+
var _ types.Picker = &RandomPicker{}
35+
36+
// Name returns the name of the picker.
37+
func (rp *RandomPicker) Name() string {
38+
return "random"
39+
}
40+
41+
<<<<<<<< HEAD:pkg/epp/scheduling/plugins/picker/random_picker.go
42+
func (rp *RandomPicker) Pick(ctx *types.SchedulingContext, pods []types.Pod) *types.Result {
43+
========
44+
// Pick selects a random pod from the list of candidates.
45+
func (rp *RandomPicker) Pick(ctx *types.Context, pods []types.Pod) (*types.Result, error) {
46+
>>>>>>>> 62526b1 (- minor refactoring):pkg/epp/scheduling/plugins/pickers/random.go
47+
ctx.Logger.V(logutil.DEBUG).Info(fmt.Sprintf("Selecting a random pod from %d candidates: %+v", len(pods), pods))
48+
i := rand.Intn(len(pods))
49+
return &types.Result{TargetPod: pods[i]}
50+
}

pkg/epp/scheduling/plugins/plugins.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Filter interface {
5050
}
5151

5252
// Scorer defines the interface for scoring pods based on context.
53+
// Scorers must return a score between 0 and 1, where 1 is the best score.
5354
type Scorer interface {
5455
Plugin
5556
Score(ctx *types.SchedulingContext, pod types.Pod) float64

0 commit comments

Comments
 (0)