Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,11 @@ func (t *Translator) processDestination(name string, backendRefContext BackendRe
if t.isCustomBackendResource(backendRef.Group, KindDerefOr(backendRef.Kind, resource.KindService)) {
// Add the custom backend resource to ExtensionRefFilters so it can be processed by the extension system
unstructuredRef = t.processBackendExtensions(backendRef.BackendObjectReference, backendNamespace, resources)
return nil, unstructuredRef, nil
return &ir.DestinationSetting{
Name: name,
Weight: &weight,
IsCustomBackend: true,
}, unstructuredRef, nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,16 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- directResponse:
statusCode: 500
- destination:
metadata:
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/1
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/1/backend/0
weight: 1
hostname: gateway.envoyproxy.io
isHTTP2: false
metadata:
Expand All @@ -143,8 +151,16 @@ xdsIR:
distinct: false
name: ""
prefix: /lambda
- directResponse:
statusCode: 500
- destination:
metadata:
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/0
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/0/backend/0
weight: 1
hostname: gateway.envoyproxy.io
isHTTP2: false
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ xdsIR:
name: httproute/default/httproute-1/rule/0/backend/0
protocol: HTTP
weight: 1
- isCustomBackend: true
name: httproute/default/httproute-1/rule/0/backend/1
weight: 1
- isCustomBackend: true
name: httproute/default/httproute-1/rule/0/backend/2
weight: 1
extensionRefs:
- object:
apiVersion: storage.example.io/v1alpha1
Expand Down Expand Up @@ -199,6 +205,12 @@ xdsIR:
namespace: default
name: httproute/default/httproute-1/rule/1
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/1/backend/0
weight: 1
- isCustomBackend: true
name: httproute/default/httproute-1/rule/1/backend/1
weight: 1
- addressType: IP
endpoints:
- host: 7.7.7.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ xdsIR:
name: httproute/default/httproute-1/rule/0/backend/0
protocol: HTTP
weight: 1
- isCustomBackend: true
name: httproute/default/httproute-1/rule/0/backend/1
weight: 1
extensionRefs:
- object:
apiVersion: storage.example.io/v1alpha1
Expand Down Expand Up @@ -181,6 +184,9 @@ xdsIR:
namespace: default
name: httproute/default/httproute-1/rule/1
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/1/backend/0
weight: 1
- addressType: IP
endpoints:
- host: 7.7.7.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,19 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- directResponse:
statusCode: 500
- destination:
metadata:
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/0
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/0/backend/0
weight: 1
- isCustomBackend: true
name: httproute/default/httproute-1/rule/0/backend/1
weight: 1
extensionRefs:
- object:
apiVersion: storage.example.io/v1alpha1
Expand Down Expand Up @@ -172,8 +183,19 @@ xdsIR:
distinct: false
name: ""
prefix: /service
- directResponse:
statusCode: 500
- destination:
metadata:
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/1
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/1/backend/0
weight: 1
- isCustomBackend: true
name: httproute/default/httproute-1/rule/1/backend/1
weight: 1
extensionRefs:
- object:
apiVersion: storage.example.io/v1alpha1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,16 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- directResponse:
statusCode: 500
- destination:
metadata:
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/1
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/1/backend/0
weight: 1
extensionRefs:
- object:
apiVersion: compute.example.io/v1alpha1
Expand All @@ -154,8 +162,16 @@ xdsIR:
distinct: false
name: ""
prefix: /lambda
- directResponse:
statusCode: 500
- destination:
metadata:
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/0
settings:
- isCustomBackend: true
name: httproute/default/httproute-1/rule/0/backend/0
weight: 1
extensionRefs:
- object:
apiVersion: storage.example.io/v1alpha1
Expand Down
5 changes: 5 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,8 @@ func (r *RouteDestination) ToBackendWeights() *BackendWeights {
switch {
case s.IsDynamicResolver: // Dynamic resolver has no endpoints
w.Valid += *s.Weight
case s.IsCustomBackend: // Custom backends has no endpoints
w.Valid += *s.Weight
case len(s.Endpoints) > 0:
w.Valid += *s.Weight
default:
Expand All @@ -1620,6 +1622,9 @@ type DestinationSetting struct {
// A dynamic resolver is a destination that is resolved dynamically using the request's host header.
IsDynamicResolver bool `json:"isDynamicResolver,omitempty" yaml:"isDynamicResolver,omitempty"`

// IsCustomBackend specifies whether the destination is a custom backend.
IsCustomBackend bool `json:"isCustomBackend,omitempty" yaml:"isCustomBackend,omitempty"`

// Weight associated with this destination,
// invalid endpoints are represents with a
// non-zero weight with an empty endpoints list
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ func (r *gatewayAPIReconciler) processBackendRefs(ctx context.Context, gwcResour
}
if !resourceMappings.allAssociatedBackendRefExtensionFilters.Has(key) {
resourceMappings.allAssociatedBackendRefExtensionFilters.Insert(key)
if extRefFilter, exists := resourceMappings.extensionRefFilters[key]; !exists {
if extRefFilter, exists := resourceMappings.extensionRefFilters[key]; exists {
resourceMappings.extensionRefFilters[key] = extRefFilter
gwcResource.ExtensionRefFilters = append(gwcResource.ExtensionRefFilters, extRefFilter)
r.log.Info("added custom backend resource to resource tree",
Expand Down
14 changes: 2 additions & 12 deletions internal/provider/kubernetes/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,8 @@ func TestProcessBackendRefsWithCustomBackends(t *testing.T) {

// Call the function under test
require.NoError(t, r.processBackendRefs(ctx, gwcResource, resourceMappings))

// Verify results
// Note: Due to a bug in the current implementation (line 542 in controller.go),
// custom backends are not properly added to ExtensionRefFilters when they exist
// in the extensionRefFilters map. The logic should be `exists` instead of `!exists`.
// For now, we test the current (buggy) behavior.
if tc.name == "skip non-custom backends" {
require.Len(t, gwcResource.ExtensionRefFilters, tc.expectedExtFiltersCount)
} else {
// Current buggy behavior: custom backends are not added to ExtensionRefFilters
require.Empty(t, gwcResource.ExtensionRefFilters)
}
// Compare the results
require.Len(t, gwcResource.ExtensionRefFilters, tc.expectedExtFiltersCount)

for _, expectedNS := range tc.expectedNamespaces {
require.True(t, resourceMappings.allAssociatedNamespaces.Has(expectedNS))
Expand Down