Skip to content

Commit f844b9c

Browse files
committed
added the ability to configure postResponse plugins in requestcontrol layer
Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent 9662d0c commit f844b9c

File tree

5 files changed

+58
-18
lines changed

5 files changed

+58
-18
lines changed

cmd/epp/runner/runner.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,20 @@ var (
118118

119119
// NewRunner initializes a new EPP Runner and returns its pointer.
120120
func NewRunner() *Runner {
121-
return &Runner{}
121+
return &Runner{
122+
requestControlConfig: requestcontrol.NewConfig(), // default requestcontrol config has empty plugin list
123+
}
122124
}
123125

124126
// Runner is used to run epp with its plugins
125127
type Runner struct {
126-
schedulerConfig *scheduling.SchedulerConfig
128+
requestControlConfig *requestcontrol.Config
129+
schedulerConfig *scheduling.SchedulerConfig
130+
}
131+
132+
func (r *Runner) WithRequestControlConfig(requestControlConfig *requestcontrol.Config) *Runner {
133+
r.requestControlConfig = requestControlConfig
134+
return r
127135
}
128136

129137
func (r *Runner) WithSchedulerConfig(schedulerConfig *scheduling.SchedulerConfig) *Runner {
@@ -210,7 +218,7 @@ func (r *Runner) Run() error {
210218

211219
saturationDetector := saturationdetector.NewDetector(sdConfig, datastore, ctrl.Log)
212220

213-
director := requestcontrol.NewDirector(datastore, scheduler, saturationDetector) // can call "director.WithPostResponsePlugins" to add post response plugins
221+
director := requestcontrol.NewDirectorWithConfig(datastore, scheduler, saturationDetector, r.requestControlConfig)
214222

215223
// --- Setup ExtProc Server Runner ---
216224
serverRunner := &runserver.ExtProcServerRunner{

pkg/epp/requestcontrol/director.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ type SaturationDetector interface {
4848
IsSaturated(ctx context.Context) bool
4949
}
5050

51-
// NewDirector creates a new Director instance with all dependencies.
52-
// postResponsePlugins remains nil as this is an optional field that can be set using the "WithPostResponsePlugins" function.
53-
func NewDirector(datastore datastore.Datastore, scheduler Scheduler, saturationDetector SaturationDetector) *Director {
54-
return &Director{datastore: datastore, scheduler: scheduler, saturationDetector: saturationDetector}
51+
// NewDirectorWithConfig creates a new Director instance with all dependencies.
52+
func NewDirectorWithConfig(datastore datastore.Datastore, scheduler Scheduler, saturationDetector SaturationDetector, config *Config) *Director {
53+
return &Director{
54+
datastore: datastore,
55+
scheduler: scheduler,
56+
saturationDetector: saturationDetector,
57+
postResponsePlugins: config.postResponsePlugins,
58+
}
5559
}
5660

5761
// Director orchestrates the request handling flow, including scheduling.
@@ -62,13 +66,6 @@ type Director struct {
6266
postResponsePlugins []PostResponse
6367
}
6468

65-
// WithPostResponsePlugins sets the given plugins as the PostResponse plugins.
66-
// If the Director has PostResponse plugins already, this call replaces the existing plugins with the given ones.
67-
func (d *Director) WithPostResponsePlugins(plugins ...PostResponse) *Director {
68-
d.postResponsePlugins = plugins
69-
return d
70-
}
71-
7269
// HandleRequest orchestrates the request lifecycle:
7370
// 1. Parses request details.
7471
// 2. Calls PreDispatch for admission control.

pkg/epp/requestcontrol/director_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func TestDirector_HandleRequest(t *testing.T) {
344344
if test.schedulerMockSetup != nil {
345345
test.schedulerMockSetup(mockSched)
346346
}
347-
director := NewDirector(ds, mockSched, test.mockSaturationDetector)
347+
director := NewDirectorWithConfig(ds, mockSched, test.mockSaturationDetector, NewConfig())
348348

349349
reqCtx := &handlers.RequestContext{
350350
Request: &handlers.Request{
@@ -521,8 +521,7 @@ func TestDirector_HandleResponse(t *testing.T) {
521521
ctx := logutil.NewTestLoggerIntoContext(context.Background())
522522
ds := datastore.NewDatastore(t.Context(), nil)
523523
mockSched := &mockScheduler{}
524-
director := NewDirector(ds, mockSched, nil).
525-
WithPostResponsePlugins(pr1)
524+
director := NewDirectorWithConfig(ds, mockSched, nil, NewConfig().WithPostResponsePlugins(pr1))
526525

527526
reqCtx := &handlers.RequestContext{
528527
Request: &handlers.Request{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 requestcontrol
18+
19+
// NewConfig creates a new Config object and returns its pointer.
20+
func NewConfig() *Config {
21+
return &Config{
22+
postResponsePlugins: []PostResponse{},
23+
}
24+
}
25+
26+
// Config provides a configuration for the requestcontrol plugins.
27+
type Config struct {
28+
postResponsePlugins []PostResponse
29+
}
30+
31+
// WithPostResponsePlugins sets the given plugins as the PostResponse plugins.
32+
// If the Config has PostResponse plugins already, this call replaces the existing plugins with the given ones.
33+
func (c *Config) WithPostResponsePlugins(plugins ...PostResponse) *Config {
34+
c.postResponsePlugins = plugins
35+
return c
36+
}

test/integration/epp/hermetic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ func BeforeSuite() func() {
934934
}
935935
detector := saturationdetector.NewDetector(sdConfig, serverRunner.Datastore, logger.WithName("saturation-detector"))
936936
serverRunner.SaturationDetector = detector
937-
serverRunner.Director = requestcontrol.NewDirector(serverRunner.Datastore, scheduler, detector)
937+
serverRunner.Director = requestcontrol.NewDirectorWithConfig(serverRunner.Datastore, scheduler, detector, requestcontrol.NewConfig())
938938
serverRunner.SecureServing = false
939939

940940
if err := serverRunner.SetupWithManager(context.Background(), mgr); err != nil {

0 commit comments

Comments
 (0)