@@ -186,37 +186,57 @@ func createAddHeadersMap(name string) shared.Map {
186186// buildInferenceMaps creates maps for InferencePool Backends.
187187func buildInferenceMaps (groups []dataplane.BackendGroup ) []shared.Map {
188188 inferenceMaps := make ([]shared.Map , 0 , len (groups ))
189+
189190 for _ , group := range groups {
190191 for _ , backend := range group .Backends {
191- if backend .EndpointPickerConfig != nil {
192- var defaultResult string
193- switch backend .EndpointPickerConfig .FailureMode {
194- // in FailClose mode, if the EPP is unavailable or returns an error,
195- // we return an invalid backend to ensure the request fails
196- case inference .EndpointPickerFailClose :
197- defaultResult = invalidBackendRef
198- // in FailOpen mode, if the EPP is unavailable or returns an error,
199- // we fall back to the upstream
200- case inference .EndpointPickerFailOpen :
201- defaultResult = backend .UpstreamName
202- }
203- params := []shared.MapParameter {
204- {
205- Value : "~.+" ,
206- Result : "$inference_workload_endpoint" ,
207- },
208- {
209- Value : "default" ,
210- Result : defaultResult ,
211- },
212- }
213- backendVarName := strings .ReplaceAll (backend .UpstreamName , "-" , "_" )
214- inferenceMaps = append (inferenceMaps , shared.Map {
215- Source : "$inference_workload_endpoint" ,
216- Variable : fmt .Sprintf ("$inference_backend_%s" , backendVarName ),
217- Parameters : params ,
218- })
192+ if backend .EndpointPickerConfig == nil || backend .EndpointPickerConfig .EndpointPickerRef == nil {
193+ continue
194+ }
195+
196+ // Decide what the map must return when the picker didn’t set a value.
197+ var defaultResult string
198+ switch backend .EndpointPickerConfig .EndpointPickerRef .FailureMode {
199+ // in FailClose mode, if the EPP is unavailable or returns an error,
200+ // we return an invalid backend to ensure the request fails
201+ case inference .EndpointPickerFailClose :
202+ defaultResult = invalidBackendRef
203+
204+ // in FailOpen mode, if the EPP is unavailable or returns an error,
205+ // we fall back to the upstream
206+ case inference .EndpointPickerFailOpen :
207+ defaultResult = backend .UpstreamName
219208 }
209+
210+ // Build the ordered parameter list.
211+ params := make ([]shared.MapParameter , 0 , 3 )
212+
213+ // no endpoint picked by EPP go to inference pool directly
214+ params = append (params , shared.MapParameter {
215+ Value : `""` ,
216+ Result : backend .UpstreamName ,
217+ })
218+
219+ // endpoint picked by the EPP is stored in $inference_workload_endpoint.
220+ params = append (params , shared.MapParameter {
221+ Value : `~.+` ,
222+ Result : `$inference_workload_endpoint` ,
223+ })
224+
225+ // this is set based on EPP failure mode,
226+ // if EPP is failOpen, we set the default to the inference pool upstream,
227+ // if EPP is failClose, we set the default to invalidBackendRef.
228+ params = append (params , shared.MapParameter {
229+ Value : "default" ,
230+ Result : defaultResult ,
231+ })
232+
233+ backendVarName := strings .ReplaceAll (backend .UpstreamName , "-" , "_" )
234+
235+ inferenceMaps = append (inferenceMaps , shared.Map {
236+ Source : `$inference_workload_endpoint` ,
237+ Variable : fmt .Sprintf ("$inference_backend_%s" , backendVarName ),
238+ Parameters : params ,
239+ })
220240 }
221241 }
222242 return inferenceMaps
0 commit comments