Skip to content

Commit 6193b60

Browse files
authored
Refactor the configuration defaults handling code (#1294)
* Removed defaults handling under K8S machinery Signed-off-by: Shmuel Kallner <[email protected]> * Added String functions for configuration objects Signed-off-by: Shmuel Kallner <[email protected]> * Refactored defaults handling for configuration objects Signed-off-by: Shmuel Kallner <[email protected]> * Updates to code and tests due to API changes Signed-off-by: Shmuel Kallner <[email protected]> * Removed defaults from various configurations Signed-off-by: Shmuel Kallner <[email protected]> * Documentation updates Signed-off-by: Shmuel Kallner <[email protected]> * Fixed broken test Signed-off-by: Shmuel Kallner <[email protected]> --------- Signed-off-by: Shmuel Kallner <[email protected]>
1 parent cfdf19e commit 6193b60

File tree

15 files changed

+426
-223
lines changed

15 files changed

+426
-223
lines changed

apix/config/v1alpha1/defaults.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

apix/config/v1alpha1/endpointpickerconfig_types.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ package v1alpha1
1818

1919
import (
2020
"encoding/json"
21+
"fmt"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
2425

25-
// +k8s:defaulter-gen=true
2626
// +kubebuilder:object:root=true
2727

2828
// EndpointPickerConfig is the Schema for the endpointpickerconfigs API
@@ -41,6 +41,14 @@ type EndpointPickerConfig struct {
4141
SchedulingProfiles []SchedulingProfile `json:"schedulingProfiles"`
4242
}
4343

44+
func (cfg EndpointPickerConfig) String() string {
45+
return fmt.Sprintf(
46+
"{Plugins: %v, SchedulingProfiles: %v}",
47+
cfg.Plugins,
48+
cfg.SchedulingProfiles,
49+
)
50+
}
51+
4452
// PluginSpec contains the information that describes a plugin that
4553
// will be instantiated.
4654
type PluginSpec struct {
@@ -61,6 +69,14 @@ type PluginSpec struct {
6169
Parameters json.RawMessage `json:"parameters"`
6270
}
6371

72+
func (ps PluginSpec) String() string {
73+
var parameters string
74+
if ps.Parameters != nil {
75+
parameters = fmt.Sprintf(", Parameters: %s", ps.Parameters)
76+
}
77+
return fmt.Sprintf("{%s/%s%s}", ps.Name, ps.Type, parameters)
78+
}
79+
6480
// SchedulingProfile contains the information to create a SchedulingProfile
6581
// entry to be used by the scheduler.
6682
type SchedulingProfile struct {
@@ -75,6 +91,10 @@ type SchedulingProfile struct {
7591
Plugins []SchedulingPlugin `json:"plugins"`
7692
}
7793

94+
func (sp SchedulingProfile) String() string {
95+
return fmt.Sprintf("{Name: %s, Plugins: %v}", sp.Name, sp.Plugins)
96+
}
97+
7898
// SchedulingPlugin describes a plugin that will be associated with a
7999
// SchedulingProfile entry.
80100
type SchedulingPlugin struct {
@@ -90,3 +110,11 @@ type SchedulingPlugin struct {
90110
// Weight is the weight fo be used if this plugin is a Scorer.
91111
Weight *int `json:"weight"`
92112
}
113+
114+
func (sp SchedulingPlugin) String() string {
115+
var weight string
116+
if sp.Weight != nil {
117+
weight = fmt.Sprintf(", Weight: %d", *sp.Weight)
118+
}
119+
return fmt.Sprintf("{PluginRef: %s%s}", sp.PluginRef, weight)
120+
}

apix/config/v1alpha1/zz_generated.defaults.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

cmd/epp/runner/runner.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
412412
return nil // configuring through code, not through file
413413
}
414414

415+
logger := log.FromContext(ctx)
416+
415417
var configBytes []byte
416418
if *configText != "" {
417419
configBytes = []byte(*configText)
@@ -425,20 +427,17 @@ func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
425427

426428
r.registerInTreePlugins()
427429
handle := plugins.NewEppHandle(ctx)
428-
config, err := loader.LoadConfig(configBytes, handle)
430+
config, err := loader.LoadConfig(configBytes, handle, logger)
429431
if err != nil {
430432
return fmt.Errorf("failed to load the configuration - %w", err)
431433
}
432434

433-
r.schedulerConfig, err = loader.LoadSchedulerConfig(config.SchedulingProfiles, handle)
434-
if err != nil {
435-
return fmt.Errorf("failed to create Scheduler configuration - %w", err)
436-
}
435+
r.schedulerConfig = config.SchedulerConfig
437436

438437
// Add requestControl plugins
439438
r.requestControlConfig.AddPlugins(handle.GetAllPlugins()...)
440439

441-
log.FromContext(ctx).Info("loaded configuration from file/text successfully")
440+
logger.Info("loaded configuration from file/text successfully")
442441
return nil
443442
}
444443

config/charts/inferencepool/templates/epp-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ data:
1111
- type: queue-scorer
1212
- type: kv-cache-utilization-scorer
1313
- type: prefix-cache-scorer
14-
- type: max-score-picker
15-
- type: single-profile-handler
1614
schedulingProfiles:
1715
- name: default
1816
plugins:

config/charts/inferencepool/values.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ inferenceExtension:
2121
# - type: custom-scorer
2222
# parameters:
2323
# custom-threshold: 64
24-
# - type: max-score-picker
25-
# - type: single-profile-handler
2624
# schedulingProfiles:
2725
# - name: default
2826
# plugins:
2927
# - pluginRef: custom-scorer
30-
# weight: 1
31-
# - pluginRef: max-score-picker
32-
# weight: 1
3328

3429
# Example environment variables:
3530
# env:

config/manifests/inferencepool-resources.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ data:
112112
- type: queue-scorer
113113
- type: kv-cache-utilization-scorer
114114
- type: prefix-cache-scorer
115-
- type: max-score-picker
116-
- type: single-profile-handler
117115
schedulingProfiles:
118116
- name: default
119117
plugins:

conformance/resources/base.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,10 @@ data:
343343
kind: EndpointPickerConfig
344344
plugins:
345345
- type: header-based-testing-filter
346-
- type: max-score-picker
347-
parameters:
348-
maxNumOfEndpoints: 1
349-
- type: single-profile-handler
350346
schedulingProfiles:
351347
- name: conformance-profile
352348
plugins:
353349
- pluginRef: header-based-testing-filter
354-
- pluginRef: max-score-picker
355350
---
356351
# --- Required Role and RoleBinding for Conformance Test for EPP ---
357352
apiVersion: rbac.authorization.k8s.io/v1

pkg/epp/config/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
package config
18+
19+
import "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
20+
21+
// Config is the configuration loaded from the text based configuration
22+
type Config struct {
23+
SchedulerConfig *scheduling.SchedulerConfig
24+
}

0 commit comments

Comments
 (0)