Skip to content

Commit 634c7a7

Browse files
committed
make epp flags configurable using NGF flags
1 parent e4eed2d commit 634c7a7

File tree

8 files changed

+111
-12
lines changed

8 files changed

+111
-12
lines changed

cmd/gateway/commands.go

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ const (
3737
`The controller name must be of the form: DOMAIN/PATH. The controller's domain is '%s'`
3838
plusFlag = "nginx-plus"
3939

40-
serverTLSSecret = "server-tls"
41-
agentTLSSecret = "agent-tls"
42-
nginxOneTelemetryEndpointHost = "agent.connect.nginx.com"
40+
serverTLSSecret = "server-tls"
41+
agentTLSSecret = "agent-tls"
42+
nginxOneTelemetryEndpointHost = "agent.connect.nginx.com"
43+
endpointPickerEnableTLSFlag = "endpoint-picker-enable-tls"
44+
endpointPickerSkipSecureVerifyFlag = "endpoint-picker-skip-secure-verify"
45+
)
46+
47+
// common flags.
48+
var (
49+
endpointPickerEnableTLS bool
50+
endpointPickerSkipSecureVerify bool
4351
)
4452

4553
// usageReportParams holds the parameters for building the usage report configuration for PLUS.
@@ -288,6 +296,8 @@ func createControllerCommand() *cobra.Command {
288296
EndpointPort: nginxOneConsoleTelemetryEndpointPort.value,
289297
EndpointTLSSkipVerify: nginxOneConsoleTLSSkipVerify,
290298
},
299+
EndpointPickerEnableTLS: endpointPickerEnableTLS,
300+
EndpointPickerSkipSecureVerify: endpointPickerSkipSecureVerify,
291301
}
292302

293303
if err := controller.StartManager(conf); err != nil {
@@ -320,6 +330,20 @@ func createControllerCommand() *cobra.Command {
320330
` Lives in the same Namespace as the controller.`,
321331
)
322332

333+
cmd.Flags().BoolVar(
334+
&endpointPickerEnableTLS,
335+
endpointPickerEnableTLSFlag,
336+
true,
337+
"Enables TLS when connecting to the endpoint picker.",
338+
)
339+
340+
cmd.Flags().BoolVar(
341+
&endpointPickerSkipSecureVerify,
342+
endpointPickerSkipSecureVerifyFlag,
343+
true,
344+
"Disables server certificate verification when connecting to the endpoint picker, if TLS is enabled",
345+
)
346+
323347
cmd.Flags().Var(
324348
&serviceName,
325349
serviceFlag,
@@ -763,11 +787,28 @@ func createEndpointPickerCommand() *cobra.Command {
763787
Short: "Shim server for communication between NGINX and the Gateway API Inference Extension Endpoint Picker",
764788
RunE: func(_ *cobra.Command, _ []string) error {
765789
logger := ctlrZap.New().WithName("endpoint-picker-shim")
766-
handler := createEndpointPickerHandler(realExtProcClientFactory(), logger)
790+
handler := createEndpointPickerHandler(
791+
realExtProcClientFactory(endpointPickerEnableTLS, endpointPickerSkipSecureVerify),
792+
logger,
793+
)
767794
return endpointPickerServer(handler)
768795
},
769796
}
770797

798+
cmd.Flags().BoolVar(
799+
&endpointPickerEnableTLS,
800+
endpointPickerEnableTLSFlag,
801+
true,
802+
"Enables TLS when connecting to the endpoint picker.",
803+
)
804+
805+
cmd.Flags().BoolVar(
806+
&endpointPickerSkipSecureVerify,
807+
endpointPickerSkipSecureVerifyFlag,
808+
true,
809+
"Disables server certificate verification when connecting to the endpoint picker, if TLS is enabled",
810+
)
811+
771812
return cmd
772813
}
773814

cmd/gateway/commands_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ func TestControllerCmdFlagValidation(t *testing.T) {
161161
"--nginx-one-telemetry-endpoint-host=telemetry-endpoint-host",
162162
"--nginx-one-telemetry-endpoint-port=443",
163163
"--nginx-one-tls-skip-verify",
164+
"--endpoint-picker-enable-tls",
165+
"--endpoint-picker-skip-secure-verify",
164166
},
165167
wantErr: false,
166168
},
@@ -924,3 +926,43 @@ func TestUsageReportConfig(t *testing.T) {
924926
})
925927
}
926928
}
929+
930+
func TestEndpointPickerFlags(t *testing.T) {
931+
t.Parallel()
932+
tests := []flagTestCase{
933+
{
934+
name: "valid flags",
935+
args: []string{
936+
"--endpoint-picker-enable-tls=true",
937+
"--endpoint-picker-skip-secure-verify=false",
938+
},
939+
wantErr: false,
940+
},
941+
{
942+
name: "endpoint-picker-enable-tls is not a bool",
943+
args: []string{
944+
"--endpoint-picker-enable-tls=not-a-bool",
945+
},
946+
wantErr: true,
947+
expectedErrPrefix: `invalid argument "not-a-bool" for "--endpoint-picker-enable-tls" flag:` +
948+
` strconv.ParseBool: parsing "not-a-bool": invalid syntax`,
949+
},
950+
{
951+
name: "endpoint-picker-skip-secure-verify is not a bool",
952+
args: []string{
953+
"--endpoint-picker-skip-secure-verify=not-a-bool",
954+
},
955+
wantErr: true,
956+
expectedErrPrefix: `invalid argument "not-a-bool" for "--endpoint-picker-skip-secure-verify" flag:` +
957+
` strconv.ParseBool: parsing "not-a-bool": invalid syntax`,
958+
},
959+
}
960+
961+
for _, test := range tests {
962+
t.Run(test.name, func(t *testing.T) {
963+
t.Parallel()
964+
cmd := createEndpointPickerCommand()
965+
testFlag(t, cmd, test)
966+
})
967+
}
968+
}

cmd/gateway/endpoint_picker.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@ func endpointPickerServer(handler http.Handler) error {
3535
}
3636

3737
// realExtProcClientFactory returns a factory that creates a new gRPC connection and client per request.
38-
func realExtProcClientFactory() extProcClientFactory {
38+
func realExtProcClientFactory(enableTLS, skipSecureVerify bool) extProcClientFactory {
3939
return func(target string) (extprocv3.ExternalProcessorClient, func() error, error) {
4040
var opts []grpc.DialOption
41-
enableTLS := true
42-
insecureSkipVerify := true
4341

4442
if !enableTLS {
4543
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
4644
} else {
4745
creds := credentials.NewTLS(&tls.Config{
48-
InsecureSkipVerify: insecureSkipVerify, //nolint:gosec
46+
InsecureSkipVerify: skipSecureVerify, //nolint:gosec
4947
})
5048
opts = append(opts, grpc.WithTransportCredentials(creds))
5149
}
50+
5251
conn, err := grpc.NewClient(target, opts...)
5352
if err != nil {
5453
return nil, nil, err

gateway

72.8 MB
Binary file not shown.

internal/controller/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ type Config struct {
5252
InferenceExtension bool
5353
// SnippetsFilters indicates if SnippetsFilters are enabled.
5454
SnippetsFilters bool
55+
// EndpointPickerEnableTLS indicates if TLS is enabled for EndpointPicker communication.
56+
EndpointPickerEnableTLS bool
57+
// EndpointPickerSkipSecureVerify indicates if secure verification is skipped for EndpointPicker communication.
58+
EndpointPickerSkipSecureVerify bool
5559
}
5660

5761
// GatewayPodConfig contains information about this Pod.

internal/controller/manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ func StartManager(cfg config.Config) error {
221221
PlusUsageConfig: &cfg.UsageReportConfig,
222222
NginxOneConsoleTelemetryConfig: cfg.NginxOneConsoleTelemetryConfig,
223223
InferenceExtension: cfg.InferenceExtension,
224+
EndpointPickerEnableTLS: cfg.EndpointPickerEnableTLS,
225+
EndpointPickerSkipSecureVerify: cfg.EndpointPickerSkipSecureVerify,
224226
},
225227
)
226228
if err != nil {

internal/controller/provisioner/objects.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,14 +1121,23 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
11211121
}
11221122

11231123
if p.cfg.InferenceExtension {
1124+
command := []string{
1125+
"/usr/bin/gateway",
1126+
"endpoint-picker",
1127+
}
1128+
1129+
if p.cfg.EndpointPickerEnableTLS {
1130+
command = append(command, "--endpoint-picker-enable-tls")
1131+
}
1132+
if p.cfg.EndpointPickerSkipSecureVerify {
1133+
command = append(command, "--endpoint-picker-skip-secure-verify")
1134+
}
1135+
11241136
spec.Spec.Containers = append(spec.Spec.Containers, corev1.Container{
11251137
Name: "endpoint-picker-shim",
11261138
Image: p.cfg.GatewayPodConfig.Image,
11271139
ImagePullPolicy: pullPolicy,
1128-
Command: []string{
1129-
"/usr/bin/gateway",
1130-
"endpoint-picker",
1131-
},
1140+
Command: command,
11321141
SecurityContext: &corev1.SecurityContext{
11331142
AllowPrivilegeEscalation: helpers.GetPointer(false),
11341143
Capabilities: &corev1.Capabilities{

internal/controller/provisioner/provisioner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type Config struct {
5959
NginxOneConsoleTelemetryConfig config.NginxOneConsoleTelemetryConfig
6060
Plus bool
6161
InferenceExtension bool
62+
EndpointPickerEnableTLS bool
63+
EndpointPickerSkipSecureVerify bool
6264
}
6365

6466
// NginxProvisioner handles provisioning nginx kubernetes resources.

0 commit comments

Comments
 (0)