Skip to content

Commit 4afc6aa

Browse files
committed
update validation checks for EPP picker
1 parent 05b166e commit 4afc6aa

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

internal/controller/nginx/config/maps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func buildInferenceMaps(groups []dataplane.BackendGroup) []shared.Map {
189189

190190
for _, group := range groups {
191191
for _, backend := range group.Backends {
192-
if backend.EndpointPickerConfig == nil {
192+
if backend.EndpointPickerConfig == nil || backend.EndpointPickerConfig.EndpointPickerRef == nil {
193193
continue
194194
}
195195

internal/controller/nginx/config/servers.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,18 @@ func createInternalLocationsForRule(
453453
intLocation, match = initializeInternalMatchLocationWithInference(pathRuleIdx, matchRuleIdx, r.Match)
454454
intInfLocation := initializeInternalInferenceRedirectLocation(pathRuleIdx, matchRuleIdx)
455455
for _, b := range r.BackendGroup.Backends {
456-
if b.EndpointPickerConfig != nil {
456+
if b.EndpointPickerConfig != nil && b.EndpointPickerConfig.EndpointPickerRef != nil {
457457
eppRef := b.EndpointPickerConfig.EndpointPickerRef
458458
var portNum int
459459
if eppRef.Port != nil {
460460
portNum = int(eppRef.Port.Number)
461461
}
462462
intInfLocation.EPPInternalPath = intLocation.Path
463-
intInfLocation.EPPHost = string(eppRef.Name) + "." + b.EndpointPickerConfig.NsName + svcClusterLocal
463+
if b.EndpointPickerConfig.NsName != "" {
464+
intInfLocation.EPPHost = string(eppRef.Name) + "." + b.EndpointPickerConfig.NsName + svcClusterLocal
465+
} else {
466+
intInfLocation.EPPHost = string(eppRef.Name)
467+
}
464468
intInfLocation.EPPPort = portNum
465469
}
466470
}
@@ -516,7 +520,11 @@ func createInferenceLocationsForRule(
516520
portNum = int(eppRef.Port.Number)
517521
}
518522
extLocations[i].EPPInternalPath = intLocation.Path
519-
extLocations[i].EPPHost = string(eppRef.Name) + "." + b.EndpointPickerConfig.NsName + svcClusterLocal
523+
if b.EndpointPickerConfig.NsName != "" {
524+
extLocations[i].EPPHost = string(eppRef.Name) + "." + b.EndpointPickerConfig.NsName + svcClusterLocal
525+
} else {
526+
extLocations[i].EPPHost = string(eppRef.Name)
527+
}
520528
extLocations[i].EPPPort = portNum
521529
}
522530
}

internal/controller/state/conditions/conditions.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ const (
3939
// Route rules has a backendRef with an unsupported value.
4040
RouteReasonBackendRefUnsupportedValue v1.RouteConditionReason = "UnsupportedValue"
4141

42-
// RouteReasonBackendRefInvalidInferencePool is used with the "ResolvedRefs" condition when
43-
// the InferencePool backendRef is invalid.
44-
RouteReasonBackendRefInvalidInferencePool v1.RouteConditionReason = "InvalidInferencePool"
45-
4642
// RouteReasonInvalidGateway is used with the "Accepted" (false) condition when the Gateway the Route
4743
// references is invalid.
4844
RouteReasonInvalidGateway v1.RouteConditionReason = "InvalidGateway"
@@ -67,6 +63,9 @@ const (
6763
// invalid. Used with ResolvedRefs (false).
6864
RouteReasonInvalidFilter v1.RouteConditionReason = "InvalidFilter"
6965

66+
// RouteReasonInvalidInferencePool is used when a InferencePool backendRef referenced by a Route is invalid.
67+
RouteReasonInvalidInferencePool v1.RouteConditionReason = "InvalidInferencePool"
68+
7069
// GatewayReasonUnsupportedValue is used with GatewayConditionAccepted (false) when a value of a field in a Gateway
7170
// is invalid or not supported.
7271
GatewayReasonUnsupportedValue v1.GatewayConditionReason = "UnsupportedValue"
@@ -456,7 +455,7 @@ func NewRouteBackendRefInvalidInferencePool(msg string) Condition {
456455
return Condition{
457456
Type: string(v1.RouteConditionResolvedRefs),
458457
Status: metav1.ConditionFalse,
459-
Reason: string(RouteReasonBackendRefInvalidInferencePool),
458+
Reason: string(RouteReasonInvalidInferencePool),
460459
Message: msg,
461460
}
462461
}

internal/controller/state/dataplane/configuration.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,20 @@ func newBackendGroup(
394394

395395
inferencePoolBackendExists = inferencePoolBackendExists || ref.IsInferencePool
396396

397-
backends = append(backends, Backend{
398-
UpstreamName: ref.ServicePortReference(),
399-
Weight: ref.Weight,
400-
Valid: valid,
401-
VerifyTLS: convertBackendTLS(ref.BackendTLSPolicy, gatewayName),
402-
EndpointPickerConfig: &EndpointPickerConfig{
403-
NsName: ref.EndpointPickerConfig.NsName,
397+
var eppRef *EndpointPickerConfig
398+
if ref.EndpointPickerConfig.EndpointPickerRef != nil {
399+
eppRef = &EndpointPickerConfig{
404400
EndpointPickerRef: ref.EndpointPickerConfig.EndpointPickerRef,
405-
},
401+
NsName: ref.EndpointPickerConfig.NsName,
402+
}
403+
}
404+
405+
backends = append(backends, Backend{
406+
UpstreamName: ref.ServicePortReference(),
407+
Weight: ref.Weight,
408+
Valid: valid,
409+
VerifyTLS: convertBackendTLS(ref.BackendTLSPolicy, gatewayName),
410+
EndpointPickerConfig: eppRef,
406411
})
407412
}
408413

internal/controller/state/graph/backend_refs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ func addBackendRefsToRules(
123123

124124
if pool, exists := referencedInferencePools[poolName]; exists {
125125
// If the InferencePool is invalid, add a condition to the route
126-
// and set the port to nil to avoid generating backendRefs for it.
127126
if !pool.Valid {
128127
route.Conditions = append(route.Conditions, conditions.NewRouteBackendRefInvalidInferencePool(
129128
fmt.Sprintf("Referenced InferencePool %s/%s is invalid",
@@ -133,7 +132,6 @@ func addBackendRefsToRules(
133132
))
134133
continue
135134
}
136-
137135
port := gatewayv1.PortNumber(pool.Source.Spec.TargetPorts[0].Number)
138136
ref.Port = helpers.GetPointer(port)
139137
ref.EndpointPickerConfig.EndpointPickerRef = &pool.Source.Spec.EndpointPickerRef
@@ -199,7 +197,9 @@ func createBackendRef(
199197
refPath,
200198
)
201199

202-
if !valid {
200+
validBackendRef := valid && len(route.Conditions) == 0
201+
202+
if !validBackendRef {
203203
backendRef := BackendRef{
204204
Weight: weight,
205205
Valid: false,

internal/controller/state/graph/route_common.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ type RouteBackendRef struct {
177177

178178
// EndpointPickerConfig specifies the namespace and reference to the EndpointPicker extension.
179179
type EndpointPickerConfig struct {
180+
// EndpointPickerRef is the reference to the EndpointPicker.
180181
EndpointPickerRef *inference.EndpointPickerRef
181-
NsName string
182+
// NsName is the namespace of the EndpointPicker.
183+
NsName string
182184
}
183185

184186
// CreateRouteKey takes a client.Object and creates a RouteKey.

0 commit comments

Comments
 (0)