Skip to content

Commit f56f623

Browse files
authored
refactor: Flatten plugins/interflow structure (#1841)
Moves inter-flow policy implementations directly into the `plugins/interflow` package, removing the unnecessary nested directories. This simplifies the import paths and project structure. This is a no-op refactoring.
1 parent 5033e19 commit f56f623

File tree

11 files changed

+24
-35
lines changed

11 files changed

+24
-35
lines changed

pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/README.md renamed to pkg/epp/flowcontrol/framework/plugins/interflow/README.md

File renamed without changes.

pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/besthead/besthead.go renamed to pkg/epp/flowcontrol/framework/plugins/interflow/besthead.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@ limitations under the License.
1616

1717
// Package besthead provides a `framework.InterFlowDispatchPolicy` that selects the queue containing the single "best"
1818
// item from across all queues in a priority band.
19-
package besthead
19+
package interflow
2020

2121
import (
2222
"fmt"
2323

2424
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework"
25-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch"
2625
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types"
2726
)
2827

2928
// BestHeadPolicyName is the name of the Best Head policy implementation.
3029
const BestHeadPolicyName = "BestHead"
3130

3231
func init() {
33-
dispatch.MustRegisterPolicy(dispatch.RegisteredPolicyName(BestHeadPolicyName),
32+
MustRegisterPolicy(RegisteredPolicyName(BestHeadPolicyName),
3433
func() (framework.InterFlowDispatchPolicy, error) {
3534
return newBestHead(), nil
3635
})

pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/besthead/besthead_test.go renamed to pkg/epp/flowcontrol/framework/plugins/interflow/besthead_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package besthead
17+
package interflow
1818

1919
import (
2020
"testing"
@@ -35,11 +35,6 @@ const (
3535
commonScoreType = "enqueue_time_ns_asc"
3636
)
3737

38-
var (
39-
flow1Key = types.FlowKey{ID: flow1ID, Priority: 0}
40-
flow2Key = types.FlowKey{ID: flow2ID, Priority: 0}
41-
)
42-
4338
// enqueueTimeComparatorFunc is a test utility. Lower enqueue time is better.
4439
func enqueueTimeComparatorFunc(a, b types.QueueItemAccessor) bool {
4540
return a.EnqueueTime().Before(b.EnqueueTime())

pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/factory.go renamed to pkg/epp/flowcontrol/framework/plugins/interflow/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
// Package dispatch provides the factory and registration mechanism for all `framework.InterFlowDispatchPolicy`
1818
// implementations.
1919
// It allows new policies to be added to the system and instantiated by name.
20-
package dispatch
20+
package interflow
2121

2222
import (
2323
"fmt"

pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/functional_test.go renamed to pkg/epp/flowcontrol/framework/plugins/interflow/functional_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package dispatch_test
17+
package interflow
1818

1919
import (
2020
"testing"
@@ -24,9 +24,6 @@ import (
2424

2525
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework"
2626
frameworkmocks "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/mocks"
27-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch"
28-
_ "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/besthead"
29-
_ "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/roundrobin"
3027
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types"
3128
)
3229

@@ -37,7 +34,7 @@ import (
3734
func TestInterFlowDispatchPolicyConformance(t *testing.T) {
3835
t.Parallel()
3936

40-
for policyName, constructor := range dispatch.RegisteredPolicies {
37+
for policyName, constructor := range RegisteredPolicies {
4138
t.Run(string(policyName), func(t *testing.T) {
4239
t.Parallel()
4340

pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/roundrobin/roundrobin.go renamed to pkg/epp/flowcontrol/framework/plugins/interflow/roundrobin.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ limitations under the License.
1616

1717
// Package roundrobin provides a `framework.InterFlowDispatchPolicy` that selects a queue from a priority band using a
1818
// simple round-robin strategy.
19-
package roundrobin
19+
package interflow
2020

2121
import (
2222
"slices"
2323
"sync"
2424

2525
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework"
26-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch"
2726
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types"
2827
)
2928

3029
// RoundRobinPolicyName is the name of the Round Robin policy implementation.
3130
const RoundRobinPolicyName = "RoundRobin"
3231

3332
func init() {
34-
dispatch.MustRegisterPolicy(dispatch.RegisteredPolicyName(RoundRobinPolicyName),
33+
MustRegisterPolicy(RegisteredPolicyName(RoundRobinPolicyName),
3534
func() (framework.InterFlowDispatchPolicy, error) {
3635
return newRoundRobin(), nil
3736
})
@@ -104,7 +103,7 @@ func (r *iterator) selectNextQueue(band framework.PriorityBandAccessor) framewor
104103
}
105104

106105
numFlows := len(keys)
107-
for i := 0; i < numFlows; i++ {
106+
for i := range numFlows {
108107
currentIdx := (startIndex + i) % numFlows
109108
currentKey := keys[currentIdx]
110109
queue := band.Queue(currentKey.ID)

pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/roundrobin/roundrobin_test.go renamed to pkg/epp/flowcontrol/framework/plugins/interflow/roundrobin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package roundrobin
17+
package interflow
1818

1919
import (
2020
"fmt"

pkg/epp/flowcontrol/registry/config.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323

2424
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/contracts"
2525
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework"
26-
inter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch"
27-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/besthead"
26+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/interflow"
2827
intra "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/intraflow/dispatch"
2928
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/intraflow/dispatch/fcfs"
3029
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/queue"
@@ -41,7 +40,7 @@ const (
4140
// defaultIntraFlowDispatchPolicy is the default policy for selecting items within a single flow's queue.
4241
defaultIntraFlowDispatchPolicy intra.RegisteredPolicyName = fcfs.FCFSPolicyName
4342
// defaultInterFlowDispatchPolicy is the default policy for selecting which flow's queue to service next.
44-
defaultInterFlowDispatchPolicy inter.RegisteredPolicyName = besthead.BestHeadPolicyName
43+
defaultInterFlowDispatchPolicy interflow.RegisteredPolicyName = interflow.BestHeadPolicyName
4544
// defaultQueue is the default queue implementation for flows.
4645
defaultQueue queue.RegisteredQueueName = queue.ListQueueName
4746
// defaultInitialShardCount is the default number of parallel shards to create when the registry is initialized.
@@ -128,7 +127,7 @@ type PriorityBandConfig struct {
128127
// InterFlowDispatchPolicy specifies the name of the policy used to select which flow's queue to service next from
129128
// this band.
130129
// Optional: Defaults to `defaultInterFlowDispatchPolicy` ("BestHead").
131-
InterFlowDispatchPolicy inter.RegisteredPolicyName
130+
InterFlowDispatchPolicy interflow.RegisteredPolicyName
132131

133132
// Queue specifies the default name of the `framework.SafeQueue` implementation for flow queues in this band.
134133
// Optional: Defaults to `defaultQueue` ("ListQueue").
@@ -167,7 +166,7 @@ type ShardPriorityBandConfig struct {
167166
// IntraFlowDispatchPolicy is the name of the policy for dispatch within a flow's queue.
168167
IntraFlowDispatchPolicy intra.RegisteredPolicyName
169168
// InterFlowDispatchPolicy is the name of the policy for dispatch between flow queues.
170-
InterFlowDispatchPolicy inter.RegisteredPolicyName
169+
InterFlowDispatchPolicy interflow.RegisteredPolicyName
171170
// Queue is the name of the queue implementation to use.
172171
Queue queue.RegisteredQueueName
173172
// MaxBytes is this shard's partitioned portion of this band's global capacity limit.
@@ -209,7 +208,7 @@ func (c *Config) ValidateAndApplyDefaults() (*Config, error) {
209208

210209
// Ensure the DI factories are initialized for production use if `NewConfig` was called without options.
211210
if cfg.interFlowDispatchPolicyFactory == nil {
212-
cfg.interFlowDispatchPolicyFactory = inter.NewPolicyFromName
211+
cfg.interFlowDispatchPolicyFactory = interflow.NewPolicyFromName
213212
}
214213
if cfg.intraFlowDispatchPolicyFactory == nil {
215214
cfg.intraFlowDispatchPolicyFactory = intra.NewPolicyFromName
@@ -362,9 +361,9 @@ type configOption func(*Config)
362361

363362
// interFlowDispatchPolicyFactory defines the signature for a function that creates an
364363
// `framework.InterFlowDispatchPolicy` instance from its registered name.
365-
// It serves as an abstraction over the concrete `inter.NewPolicyFromName` factory, enabling dependency injection for
364+
// It serves as an abstraction over the concrete `interflow.NewPolicyFromName` factory, enabling dependency injection for
366365
// testing validation logic.
367-
type interFlowDispatchPolicyFactory func(name inter.RegisteredPolicyName) (framework.InterFlowDispatchPolicy, error)
366+
type interFlowDispatchPolicyFactory func(name interflow.RegisteredPolicyName) (framework.InterFlowDispatchPolicy, error)
368367

369368
// intraFlowDispatchPolicyFactory defines the signature for a function that creates an
370369
// `framework.IntraFlowDispatchPolicy` instance from its registered name.

pkg/epp/flowcontrol/registry/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/contracts"
2929
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework"
3030
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/mocks"
31-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch/besthead"
31+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/interflow"
3232
intra "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/intraflow/dispatch"
3333
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/intraflow/dispatch/fcfs"
3434
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/queue"
@@ -82,7 +82,7 @@ func TestConfig_ValidateAndApplyDefaults(t *testing.T) {
8282
Priority: 1,
8383
PriorityName: "Critical",
8484
IntraFlowDispatchPolicy: fcfs.FCFSPolicyName,
85-
InterFlowDispatchPolicy: besthead.BestHeadPolicyName,
85+
InterFlowDispatchPolicy: interflow.BestHeadPolicyName,
8686
Queue: queue.ListQueueName,
8787
MaxBytes: 500,
8888
}},

pkg/epp/flowcontrol/registry/registry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/contracts"
3333
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework"
34-
inter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/interflow/dispatch"
34+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/interflow"
3535
intra "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/framework/plugins/policies/intraflow/dispatch"
3636
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types"
3737
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types/mocks"
@@ -139,7 +139,7 @@ func TestFlowRegistry_New(t *testing.T) {
139139
t.Parallel()
140140
config, err := newConfig(
141141
Config{PriorityBands: []PriorityBandConfig{{Priority: highPriority, PriorityName: "A"}}},
142-
withInterFlowDispatchPolicyFactory(func(inter.RegisteredPolicyName) (framework.InterFlowDispatchPolicy, error) {
142+
withInterFlowDispatchPolicyFactory(func(interflow.RegisteredPolicyName) (framework.InterFlowDispatchPolicy, error) {
143143
return nil, errors.New("injected factory failure")
144144
}),
145145
)

0 commit comments

Comments
 (0)