@@ -20,8 +20,14 @@ import (
20
20
"fmt"
21
21
"time"
22
22
23
+ "github.com/go-logr/logr"
23
24
"sigs.k8s.io/controller-runtime/pkg/log"
24
25
v1alpha2 "sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
26
+ interd "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontroller/plugins/dispatch/interflow"
27
+ intrad "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontroller/plugins/dispatch/intraflow"
28
+ interp "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontroller/plugins/preemption/interflow"
29
+ intrap "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontroller/plugins/preemption/intraflow"
30
+ "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontroller/plugins/queue"
25
31
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontroller/types"
26
32
envutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/env"
27
33
)
@@ -99,6 +105,49 @@ type FlowControllerConfig struct {
99
105
CustomFairnessPolicies map [v1alpha2.Criticality ]types.FairnessPolicy
100
106
// TODO: Add CustomPreemptionStrategies map[v1alpha2.Criticality]types.PreemptionStrategy
101
107
// if similar custom injection is desired for preemption strategies.
108
+
109
+ PriorityBands []PriorityBandConfig
110
+ }
111
+
112
+ // PriorityBandConfig defines the configuration for a single priority band.
113
+ type PriorityBandConfig struct {
114
+ PriorityLevel uint
115
+ PriorityName string
116
+ InterFlowDispatchPolicy interd.RegisteredInterFlowDispatchPolicyName
117
+ InterFlowPreemptionPolicy interp.RegisteredInterFlowPreemptionPolicyName
118
+ IntraFlowDispatchPolicy intrad.RegisteredIntraFlowDispatchPolicyName
119
+ IntraFlowPreemptionPolicy intrap.RegisteredIntraFlowPreemptionPolicyName
120
+ QueueType queue.RegisteredQueueName
121
+ // TODO: Add MaxBytes for this band here, replacing parts of MaxBytesPerCriticality.
122
+ }
123
+
124
+ // validateAndApplyDefaults validates and applies defaults for a single PriorityBandConfig.
125
+ func (pbc * PriorityBandConfig ) validateAndApplyDefaults (logger logr.Logger ) error {
126
+ if pbc .PriorityName == "" {
127
+ return fmt .Errorf ("PriorityName cannot be empty for priority level %d" , pbc .PriorityLevel )
128
+ }
129
+ bandLogger := logger .WithValues ("priority" , pbc .PriorityLevel , "priorityName" , pbc .PriorityName )
130
+ if pbc .InterFlowDispatchPolicy == "" {
131
+ bandLogger .V (1 ).Info ("InterFlowDispatchPolicy is empty, using default" , "defaultPolicy" , interd .BestHeadPriorityScoreDispatchPolicyName )
132
+ pbc .InterFlowDispatchPolicy = interd .BestHeadPriorityScoreDispatchPolicyName
133
+ }
134
+ if pbc .InterFlowPreemptionPolicy == "" {
135
+ bandLogger .V (1 ).Info ("InterFlowPreemptionPolicy is empty, using default" , "defaultPolicy" , interp .RoundRobinPreemptionPolicyName )
136
+ pbc .InterFlowPreemptionPolicy = interp .RoundRobinPreemptionPolicyName
137
+ }
138
+ if pbc .IntraFlowDispatchPolicy == "" {
139
+ bandLogger .V (1 ).Info ("IntraFlowDispatchPolicy is empty, using default" , "defaultPolicy" , intrad .FCFSDispatchPolicyName )
140
+ pbc .IntraFlowDispatchPolicy = intrad .FCFSDispatchPolicyName
141
+ }
142
+ if pbc .IntraFlowPreemptionPolicy == "" {
143
+ bandLogger .V (1 ).Info ("IntraFlowPreemptionPolicy is empty, using default" , "defaultPolicy" , intrap .TailPreemptionPolicyName )
144
+ pbc .IntraFlowPreemptionPolicy = intrap .TailPreemptionPolicyName
145
+ }
146
+ if pbc .QueueType == "" {
147
+ bandLogger .V (1 ).Info ("QueueType is empty, using default" , "defaultQueue" , queue .ListQueueName )
148
+ pbc .QueueType = queue .ListQueueName
149
+ }
150
+ return nil
102
151
}
103
152
104
153
// validateAndApplyDefaults validates the provided config and assigns default
@@ -144,6 +193,15 @@ func (cfg *FlowControllerConfig) validateAndApplyDefaults() error {
144
193
}
145
194
}
146
195
196
+ // Validate and apply defaults for each priority band.
197
+ // This assumes PriorityBands is the source of truth for band-specific policies.
198
+ // The top-level policy strings might become deprecated or used as global defaults if a band doesn't specify.
199
+ logger := log .Log .WithName ("flow-controller-config-validation" ) // Use a local logger for this phase
200
+ for i := range cfg .PriorityBands {
201
+ if err := cfg .PriorityBands [i ].validateAndApplyDefaults (logger ); err != nil {
202
+ return fmt .Errorf ("invalid config for priority band %s (level %d): %w" , cfg .PriorityBands [i ].PriorityName , cfg .PriorityBands [i ].PriorityLevel , err )
203
+ }
204
+ }
147
205
return nil
148
206
}
149
207
0 commit comments