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
4 changes: 0 additions & 4 deletions cmd/epp/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,6 @@ func (r *Runner) registerInTreePlugins() {
}

func (r *Runner) parseConfigurationPhaseOne(ctx context.Context, opts *runserver.Options) (*configapi.EndpointPickerConfig, error) {
if opts.ConfigText == "" && opts.ConfigFile == "" {
return nil, nil // configuring through code, not through file
}

logger := log.FromContext(ctx)

var configBytes []byte
Expand Down
16 changes: 12 additions & 4 deletions pkg/epp/config/loader/configloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ func RegisterFeatureGate(gate string) {
// LoadRawConfig parses the raw configuration bytes, applies initial defaults, and extracts feature gates.
// It does not instantiate plugins.
func LoadRawConfig(configBytes []byte, logger logr.Logger) (*configapi.EndpointPickerConfig, map[string]bool, error) {
rawConfig, err := decodeRawConfig(configBytes)
if err != nil {
return nil, nil, err
var rawConfig *configapi.EndpointPickerConfig
var err error
if len(configBytes) != 0 {
rawConfig, err = decodeRawConfig(configBytes)
if err != nil {
return nil, nil, err
}
logger.Info("Loaded raw configuration", "config", rawConfig.String())
} else {
logger.Info("A configuration wasn't specified. A default one is being used.")
rawConfig = loadDefaultConfig()
logger.Info("Default raw configuration used", "config", rawConfig.String())
}
logger.Info("Loaded raw configuration", "config", rawConfig)

applyStaticDefaults(rawConfig)

Expand Down
51 changes: 51 additions & 0 deletions pkg/epp/config/loader/configloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
framework "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/interface/scheduling"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/picker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/profile"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/scorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/scorer/prefix"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector/framework/plugins/utilizationdetector"
"sigs.k8s.io/gateway-api-inference-extension/test/utils"
)
Expand All @@ -67,6 +69,10 @@ func TestLoadRawConfiguration(t *testing.T) {
RegisterFeatureGate(datalayer.ExperimentalDatalayerFeatureGate)
RegisterFeatureGate(flowcontrol.FeatureGate)

queueScorerWeight := 2.0
kvCacheUtilizationScorerWeight := 2.0
prefixCacheScorerWeight := 3.0

tests := []struct {
name string
configText string
Expand Down Expand Up @@ -124,6 +130,51 @@ func TestLoadRawConfiguration(t *testing.T) {
},
wantErr: false,
},
{
name: "Success - Default configuration",
configText: "",
want: &configapi.EndpointPickerConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "inference.networking.x-k8s.io/v1alpha1",
Kind: "EndpointPickerConfig",
},
FeatureGates: configapi.FeatureGates{},
Plugins: []configapi.PluginSpec{
{
Name: scorer.QueueScorerType,
Type: scorer.QueueScorerType,
},
{
Name: scorer.KvCacheUtilizationScorerType,
Type: scorer.KvCacheUtilizationScorerType,
},
{
Name: prefix.PrefixCachePluginType,
Type: prefix.PrefixCachePluginType,
},
},
SchedulingProfiles: []configapi.SchedulingProfile{
{
Name: "default",
Plugins: []configapi.SchedulingPlugin{
{
PluginRef: scorer.QueueScorerType,
Weight: &queueScorerWeight,
},
{
PluginRef: scorer.KvCacheUtilizationScorerType,
Weight: &kvCacheUtilizationScorerWeight,
},
{
PluginRef: prefix.PrefixCachePluginType,
Weight: &prefixCacheScorerWeight,
},
},
},
},
},
wantErr: false,
},
{
name: "Error - Invalid YAML",
configText: errorBadYamlText,
Expand Down
46 changes: 46 additions & 0 deletions pkg/epp/config/loader/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,65 @@ package loader
import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

configapi "sigs.k8s.io/gateway-api-inference-extension/apix/config/v1alpha1"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/registry"
fwkplugin "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/interface/plugin"
framework "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/interface/scheduling"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/picker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/profile"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/scorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/framework/plugins/scheduling/scorer/prefix"
)

// DefaultScorerWeight is the weight used for scorers referenced in the configuration without explicit weights.
const DefaultScorerWeight = 1.0

var defaultScorerWeight = DefaultScorerWeight

func loadDefaultConfig() *configapi.EndpointPickerConfig {
queueScorerWeight := 2.0
kvCacheUtilizationScorerWeight := 2.0
prefixCacheScorerWeight := 3.0
return &configapi.EndpointPickerConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "inference.networking.x-k8s.io/v1alpha1",
Kind: "EndpointPickerConfig",
},
Plugins: []configapi.PluginSpec{
{
Type: scorer.QueueScorerType,
},
{
Type: scorer.KvCacheUtilizationScorerType,
},
{
Type: prefix.PrefixCachePluginType,
},
},
SchedulingProfiles: []configapi.SchedulingProfile{
{
Name: "default",
Plugins: []configapi.SchedulingPlugin{
{
PluginRef: scorer.QueueScorerType,
Weight: &queueScorerWeight,
},
{
PluginRef: scorer.KvCacheUtilizationScorerType,
Weight: &kvCacheUtilizationScorerWeight,
},
{
PluginRef: prefix.PrefixCachePluginType,
Weight: &prefixCacheScorerWeight,
},
},
},
},
}
}

// applyStaticDefaults sanitizes the configuration object before plugin instantiation.
// It handles "Static" defaults: simple structural changes to the API object that do not require access to the plugin
// registry.
Expand Down
3 changes: 0 additions & 3 deletions pkg/epp/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ func (opts *Options) Validate() error {
}
}

if opts.ConfigText == "" && opts.ConfigFile == "" {
return fmt.Errorf("one of the %q and %q flags must be set", "configText", "configFile")
}
if opts.ConfigText != "" && opts.ConfigFile != "" {
return fmt.Errorf("both the %q and %q flags can not be set at the same time", "configText", "configFile")
}
Expand Down