|
| 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 | +} |
0 commit comments