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
34 changes: 23 additions & 11 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

if policy.Spec.MergeType == nil {
// Set conditions for translation error if it got any
if err := t.translateBackendTrafficPolicyForRoute(policy, route, xdsIR, resources); err != nil {
if err := t.translateBackendTrafficPolicyForRoute(policy, route, xdsIR, resources, nil); err != nil {
status.SetTranslationErrorForPolicyAncestors(&policy.Status,
ancestorRefs,
t.GatewayControllerName,
Expand All @@ -176,28 +176,34 @@
} else {
// merge with parent target policy if exists
for _, gwNN := range routeParents.UnsortedList() {
ancestorRef := getAncestorRefForPolicy(gwNN, nil)
// find policy for Gateway
gwPolicy := gatewayPolicyMap[gwNN]
if gwPolicy == nil {
// not found, fall back to the current policy
if err := t.translateBackendTrafficPolicyForRoute(policy, route, xdsIR, resources); err != nil {
status.SetTranslationErrorForPolicyAncestors(&policy.Status,
ancestorRefs,
if err := t.translateBackendTrafficPolicyForRoute(policy, route, xdsIR, resources, &gwNN); err != nil {
status.SetConditionForPolicyAncestor(&policy.Status,
ancestorRef,

Check warning on line 186 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L185-L186

Added lines #L185 - L186 were not covered by tests
t.GatewayControllerName,
policy.Generation,
gwapiv1a2.PolicyConditionAccepted, metav1.ConditionFalse,
egv1a1.PolicyReasonInvalid,

Check warning on line 189 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L188-L189

Added lines #L188 - L189 were not covered by tests
status.Error2ConditionMsg(err),
policy.Generation,

Check warning on line 191 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L191

Added line #L191 was not covered by tests
)
}

continue
}

// merge with parent policy
if err := t.translateBackendTrafficPolicyForRouteWithMerge(policy, gwNN, gwPolicy, route, xdsIR, resources); err != nil {
status.SetTranslationErrorForPolicyAncestors(&policy.Status,
ancestorRefs,
status.SetConditionForPolicyAncestor(&policy.Status,
ancestorRef,

Check warning on line 201 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L200-L201

Added lines #L200 - L201 were not covered by tests
t.GatewayControllerName,
policy.Generation,
gwapiv1a2.PolicyConditionAccepted, metav1.ConditionFalse,
egv1a1.PolicyReasonInvalid,

Check warning on line 204 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L203-L204

Added lines #L203 - L204 were not covered by tests
status.Error2ConditionMsg(err),
policy.Generation,

Check warning on line 206 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L206

Added line #L206 was not covered by tests
)
continue
}
Expand All @@ -207,8 +213,8 @@
}
gatewayPolicyMerged[gwNN].Insert(utils.NamespacedName(route).String())

status.SetConditionForPolicyAncestors(&policy.Status,
ancestorRefs,
status.SetConditionForPolicyAncestor(&policy.Status,
ancestorRef,
t.GatewayControllerName,
egv1a1.PolicyConditionMerged,
metav1.ConditionTrue,
Expand Down Expand Up @@ -393,6 +399,7 @@
route RouteContext,
xdsIR resource.XdsIRMap,
resources *resource.Resources,
gatewayNN *types.NamespacedName,
) error {
tf, errs := t.buildTrafficFeatures(policy, resources)
if tf == nil {
Expand All @@ -401,7 +408,12 @@
}

// Apply IR to all relevant routes
for _, x := range xdsIR {
for key, x := range xdsIR {
// if gatewayNN is not nil, only apply to the specific gateway
if gatewayNN != nil && key != t.IRKey(*gatewayNN) {
// Skip if not the gateway wanted
continue
}
applyTrafficFeatureToRoute(route, tf, errs, policy, x)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-2
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
hostnames:
- gateway.envoyproxy.io
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
- namespace: envoy-gateway
name: gateway-2
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
backendTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
namespace: envoy-gateway
name: policy-for-gateway1
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-1
timeout:
tcp:
connectTimeout: 15s
http:
connectionIdleTimeout: 16s
maxConnectionDuration: 17s
httpUpgrade:
- type: websocket
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
namespace: default
name: policy-for-route
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: httproute-1
mergeType: StrategicMerge
timeout:
tcp:
connectTimeout: 10s
connection:
bufferLimit: 100M
httpUpgrade:
- type: "spdy/3.1"
Loading