@@ -7,6 +7,7 @@ package controller
77
88import (
99 "fmt"
10+ "strconv"
1011 "testing"
1112
1213 "github.com/stretchr/testify/require"
@@ -21,6 +22,7 @@ import (
2122 gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
2223
2324 aigv1a1 "github.com/envoyproxy/ai-gateway/api/v1alpha1"
25+ "github.com/envoyproxy/ai-gateway/internal/internalapi"
2426)
2527
2628func TestGatewayMutator_Default (t * testing.T ) {
@@ -51,6 +53,7 @@ func TestGatewayMutator_mutatePod(t *testing.T) {
5153 extProcImagePullSecrets string
5254 extprocTest func (t * testing.T , container corev1.Container )
5355 podTest func (t * testing.T , pod corev1.Pod )
56+ needMCP bool
5457 }{
5558 {
5659 name : "basic extproc container" ,
@@ -61,6 +64,25 @@ func TestGatewayMutator_mutatePod(t *testing.T) {
6164 require .Empty (t , pod .Spec .ImagePullSecrets )
6265 },
6366 },
67+ {
68+ name : "basic extproc container with MCPRoute" ,
69+ needMCP : true ,
70+ extprocTest : func (t * testing.T , container corev1.Container ) {
71+ var foundMCPAddr , foundMCPSeed bool
72+ for i , arg := range container .Args {
73+ switch arg {
74+ case "-mcpAddr" :
75+ foundMCPAddr = true
76+ require .Equal (t , ":" + strconv .Itoa (internalapi .MCPProxyPort ), container .Args [i + 1 ])
77+ case "-mcpSessionEncryptionSeed" :
78+ foundMCPSeed = true
79+ require .Equal (t , "seed" , container .Args [i + 1 ])
80+ }
81+ }
82+ require .True (t , foundMCPAddr )
83+ require .True (t , foundMCPSeed )
84+ },
85+ },
6486 {
6587 name : "with extra env vars" ,
6688 extProcExtraEnvVars : "OTEL_SERVICE_NAME=ai-gateway-extproc;OTEL_TRACES_EXPORTER=otlp" ,
@@ -190,6 +212,22 @@ func TestGatewayMutator_mutatePod(t *testing.T) {
190212 })
191213 require .NoError (t , err )
192214
215+ if tt .needMCP {
216+ err = fakeClient .Create (t .Context (), & aigv1a1.MCPRoute {
217+ ObjectMeta : metav1.ObjectMeta {Name : "test-mcp" , Namespace : gwNamespace },
218+ Spec : aigv1a1.MCPRouteSpec {
219+ ParentRefs : []gwapiv1a2.ParentReference {
220+ {
221+ Name : gwName ,
222+ Kind : ptr .To (gwapiv1a2 .Kind ("Gateway" )),
223+ Group : ptr .To (gwapiv1a2 .Group ("gateway.networking.k8s.io" )),
224+ },
225+ },
226+ },
227+ })
228+ require .NoError (t , err )
229+ }
230+
193231 pod := & corev1.Pod {
194232 ObjectMeta : metav1.ObjectMeta {Name : "test-pod" , Namespace : "test-namespace" },
195233 Spec : corev1.PodSpec {
@@ -227,7 +265,9 @@ func TestGatewayMutator_mutatePod(t *testing.T) {
227265
228266 require .Equal (t , "ai-gateway-extproc" , extProcContainer .Name )
229267 tt .extprocTest (t , extProcContainer )
230- tt .podTest (t , * pod )
268+ if tt .podTest != nil {
269+ tt .podTest (t , * pod )
270+ }
231271 })
232272 }
233273 })
@@ -239,7 +279,7 @@ func newTestGatewayMutator(fakeClient client.Client, fakeKube *fake2.Clientset,
239279 return newGatewayMutator (
240280 fakeClient , fakeKube , ctrl .Log , "docker.io/envoyproxy/ai-gateway-extproc:latest" , corev1 .PullIfNotPresent ,
241281 "info" , "/tmp/extproc.sock" , metricsRequestHeaderAttributes , spanRequestHeaderAttributes , "/v1" , extProcExtraEnvVars , extProcImagePullSecrets , 512 * 1024 * 1024 ,
242- sidecar ,
282+ sidecar , "seed" ,
243283 )
244284}
245285
0 commit comments