@@ -152,7 +152,7 @@ func run(ctx context.Context, c cmdRun, o runOpts, stdout, stderr io.Writer) err
152152	if  err  !=  nil  {
153153		return  err 
154154	}
155- 	fakeClient , extProxDone , envoyAdminPort , envoyPort ,  err  :=  runCtx .writeEnvoyResourcesAndRunExtProc (ctx , aiGatewayResourcesYaml )
155+ 	fakeClient , extProxDone , envoyAdminPort , err  :=  runCtx .writeEnvoyResourcesAndRunExtProc (ctx , aiGatewayResourcesYaml )
156156	if  err  !=  nil  {
157157		return  fmt .Errorf ("failed to write envoy resources and run extproc: %w" , err )
158158	}
@@ -208,7 +208,13 @@ func run(ctx context.Context, c cmdRun, o runOpts, stdout, stderr io.Writer) err
208208	// Start a monitoring goroutine to poll Envoy's readiness. This starts 
209209	// before the server to ensure we don't miss the readiness window. 
210210	go  func () {
211- 		envoyAdmin  :=  aigw .NewEnvoyAdminClient (ctx , stderrLogger , os .Getpid (), envoyAdminPort , envoyPort )
211+ 		envoyAdmin , err  :=  aigw .NewEnvoyAdminClient (ctx , os .Getpid (), envoyAdminPort )
212+ 		if  err  !=  nil  {
213+ 			stderrLogger .Error ("Failed to find Envoy admin server" , "error" , err )
214+ 			serverCancel () // Likely a crashed envoy process 
215+ 			return 
216+ 		}
217+ 		stderrLogger .Info ("Found Envoy admin server" , "adminPort" , envoyAdmin .Port ())
212218		pollEnvoyReady (ctx , stderrLogger , envoyAdmin , 2 * time .Second )
213219	}()
214220
@@ -254,33 +260,33 @@ func recreateDir(path string) error {
254260
255261// writeEnvoyResourcesAndRunExtProc reads all resources from the given string, writes them to the output file, and runs 
256262// external processes for EnvoyExtensionPolicy resources. 
257- func  (runCtx  * runCmdContext ) writeEnvoyResourcesAndRunExtProc (ctx  context.Context , original  string ) (client.Client , <- chan  error , int , int ,  error ) {
263+ func  (runCtx  * runCmdContext ) writeEnvoyResourcesAndRunExtProc (ctx  context.Context , original  string ) (client.Client , <- chan  error , int , error ) {
258264	aigwRoutes , mcpRoutes , aigwBackends , backendSecurityPolicies , backendTLSPolicies , gateways , secrets , envoyProxies , err  :=  collectObjects (original , runCtx .envoyGatewayResourcesOut , runCtx .stderrLogger )
259265	if  err  !=  nil  {
260- 		return  nil , nil , 0 , 0 ,  fmt .Errorf ("error collecting: %w" , err )
266+ 		return  nil , nil , 0 , fmt .Errorf ("error collecting: %w" , err )
261267	}
262268	if  len (gateways ) >  1  {
263- 		return  nil , nil , 0 , 0 ,  fmt .Errorf ("multiple gateways are not supported: %s" , gateways [0 ].Name )
269+ 		return  nil , nil , 0 , fmt .Errorf ("multiple gateways are not supported: %s" , gateways [0 ].Name )
264270	}
265271	for  _ , bsp  :=  range  backendSecurityPolicies  {
266272		spec  :=  bsp .Spec 
267273		if  spec .AWSCredentials  !=  nil  &&  spec .AWSCredentials .OIDCExchangeToken  !=  nil  {
268274			// TODO: We can make it work by generalizing the rotation logic. 
269- 			return  nil , nil , 0 , 0 ,  fmt .Errorf ("OIDC exchange token is not supported: %s" , bsp .Name )
275+ 			return  nil , nil , 0 , fmt .Errorf ("OIDC exchange token is not supported: %s" , bsp .Name )
270276		}
271277	}
272278
273279	// Do the substitution for the secrets. 
274280	for  _ , s  :=  range  secrets  {
275281		if  err  =  runCtx .rewriteSecretWithAnnotatedLocation (s ); err  !=  nil  {
276- 			return  nil , nil , 0 , 0 ,  fmt .Errorf ("failed to rewrite secret %s: %w" , s .Name , err )
282+ 			return  nil , nil , 0 , fmt .Errorf ("failed to rewrite secret %s: %w" , s .Name , err )
277283		}
278284	}
279285
280286	var  secretList  * corev1.SecretList 
281287	fakeClient , _fakeClientSet , httpRoutes , eps , httpRouteFilters , backends , secretList , backendTrafficPolicies , securityPolicies , err  :=  translateCustomResourceObjects (ctx , aigwRoutes , mcpRoutes , aigwBackends , backendSecurityPolicies , backendTLSPolicies , gateways , secrets , runCtx .stderrLogger )
282288	if  err  !=  nil  {
283- 		return  nil , nil , 0 , 0 ,  fmt .Errorf ("error translating: %w" , err )
289+ 		return  nil , nil , 0 , fmt .Errorf ("error translating: %w" , err )
284290	}
285291	runCtx .fakeClientSet  =  _fakeClientSet 
286292
@@ -304,7 +310,7 @@ func (runCtx *runCmdContext) writeEnvoyResourcesAndRunExtProc(ctx context.Contex
304310	}
305311	gw  :=  gateways [0 ]
306312	if  len (gw .Spec .Listeners ) ==  0  {
307- 		return  nil , nil , 0 , 0 ,  fmt .Errorf ("gateway %s has no listeners configured" , gw .Name )
313+ 		return  nil , nil , 0 , fmt .Errorf ("gateway %s has no listeners configured" , gw .Name )
308314	}
309315	runCtx .mustClearSetOwnerReferencesAndStatusAndWriteObj (& gw .TypeMeta , gw )
310316	for  _ , ep  :=  range  eps .Items  {
@@ -315,20 +321,20 @@ func (runCtx *runCmdContext) writeEnvoyResourcesAndRunExtProc(ctx context.Contex
315321		Secrets ("" ).Get (ctx ,
316322		controller .FilterConfigSecretPerGatewayName (gw .Name , gw .Namespace ), metav1.GetOptions {})
317323	if  err  !=  nil  {
318- 		return  nil , nil , 0 , 0 ,  fmt .Errorf ("failed to get filter config secret: %w" , err )
324+ 		return  nil , nil , 0 , fmt .Errorf ("failed to get filter config secret: %w" , err )
319325	}
320326
321327	rawConfig , ok  :=  filterConfigSecret .StringData [controller .FilterConfigKeyInSecret ]
322328	if  ! ok  {
323- 		return  nil , nil , 0 , 0 ,  fmt .Errorf ("failed to get filter config from secret: %w" , err )
329+ 		return  nil , nil , 0 , fmt .Errorf ("failed to get filter config from secret: %w" , err )
324330	}
325331	var  fc  filterapi.Config 
326332	if  err  =  yaml .Unmarshal ([]byte (rawConfig ), & fc ); err  !=  nil  {
327- 		return  nil , nil , 0 , 0 ,  fmt .Errorf ("failed to unmarshal filter config: %w" , err )
333+ 		return  nil , nil , 0 , fmt .Errorf ("failed to unmarshal filter config: %w" , err )
328334	}
329335	runCtx .stderrLogger .Info ("Running external process" , "config" , fc )
330336	done  :=  runCtx .mustStartExtProc (ctx , & fc )
331- 	return  fakeClient , done , runCtx .tryFindEnvoyAdminPort (gw , envoyProxies ), runCtx . tryFindEnvoyListenerPort ( gw ),  nil 
337+ 	return  fakeClient , done , runCtx .tryFindEnvoyAdminPort (gw , envoyProxies ), nil 
332338}
333339
334340// mustStartExtProc starts the external process with the given working directory, port, and filter configuration. 
0 commit comments