Skip to content

Commit c8d0a56

Browse files
committed
Support multiple TargetRefs; Gateway level configures http context
1 parent 0c8760d commit c8d0a56

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

docs/proposals/proxy-settings.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ In the future, we can extend the Proxy Settings Policy to include more proxy-rel
5050

5151
The `ProxySettingsPolicy` API is a CRD that is a part of the `gateway.nginx.org` Group. It adheres to the guidelines and requirements of an Inherited Policy as outlined in the [Policy Attachment GEP (GEP-713)](https://gateway-api.sigs.k8s.io/geps/gep-713/).
5252

53+
The policy uses `targetRefs` (plural) to support targeting multiple resources with a single policy instance. This follows the current GEP-713 guidance and provides better user experience by:
54+
55+
- Avoiding policy duplication when applying the same settings to multiple targets
56+
- Reducing maintenance burden and risk of configuration inconsistencies
57+
- Preventing future migration challenges from singular to plural forms
58+
5359
Below is the Golang API for the `ProxySettingsPolicy` API:
5460

5561
### Go
@@ -85,14 +91,17 @@ type ProxySettingsPolicy struct {
8591

8692
// ProxySettingsPolicySpec defines the desired state of the ProxySettingsPolicy.
8793
type ProxySettingsPolicySpec struct {
88-
// TargetRef identifies an API object to apply the policy to.
89-
// Object must be in the same namespace as the policy.
94+
// TargetRefs identifies API object(s) to apply the policy to.
95+
// Objects must be in the same namespace as the policy.
9096
//
9197
// Support: Gateway, HTTPRoute, GRPCRoute
9298
//
93-
// +kubebuilder:validation:XValidation:message="TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute",rule="self.kind == 'Gateway' || self.kind == 'HTTPRoute' || self.kind == 'GRPCRoute'"
94-
// +kubebuilder:validation:XValidation:message="TargetRef Group must be gateway.networking.k8s.io",rule="self.group == 'gateway.networking.k8s.io'"
95-
TargetRef gatewayv1.LocalPolicyTargetReference `json:"targetRef"`
99+
// +kubebuilder:validation:MinItems=1
100+
// +kubebuilder:validation:MaxItems=16
101+
// +kubebuilder:validation:XValidation:message="TargetRefs entries must have kind Gateway, HTTPRoute, or GRPCRoute",rule="self.all(t, t.kind == 'Gateway' || t.kind == 'HTTPRoute' || t.kind == 'GRPCRoute')"
102+
// +kubebuilder:validation:XValidation:message="TargetRefs entries must have group gateway.networking.k8s.io",rule="self.all(t, t.group == 'gateway.networking.k8s.io')"
103+
// +kubebuilder:validation:XValidation:message="TargetRefs must be unique",rule="self.all(t1, self.exists_one(t2, t1.group == t2.group && t1.kind == t2.kind && t1.name == t2.name))"
104+
TargetRefs []gatewayv1.LocalPolicyTargetReference `json:"targetRefs"`
96105

97106
// Buffering defines the proxy buffering settings.
98107
//
@@ -255,8 +264,8 @@ metadata:
255264
name: example-proxy-settings
256265
namespace: default
257266
spec:
258-
targetRef:
259-
group: gateway.networking.k8s.io
267+
targetRefs:
268+
- group: gateway.networking.k8s.io
260269
kind: Gateway
261270
name: example-gateway
262271
buffering:
@@ -293,8 +302,8 @@ metadata:
293302
name: streaming-proxy-settings
294303
namespace: default
295304
spec:
296-
targetRef:
297-
group: gateway.networking.k8s.io
305+
targetRefs:
306+
- group: gateway.networking.k8s.io
298307
kind: HTTPRoute
299308
name: streaming-route
300309
buffering:
@@ -342,12 +351,12 @@ NGINX directives inherit downwards only. The `location` context inherits values
342351

343352
### Creating the Effective Policy in NGINX Config
344353

345-
The findings from the ClientSettingsPolicy proposal apply here as well. The strategy for implementing the effective policy is:
354+
The strategy for implementing the effective policy is:
346355

347-
- When a `ProxySettingsPolicy` is attached to a Gateway, add the corresponding NGINX directives to each `server` block generated from that Gateway.
348-
- When a `ProxySettingsPolicy` is attached to an HTTPRoute or GRPCRoute, add the corresponding NGINX directives to each of the final `location` blocks generated for the Route.
356+
- When a `ProxySettingsPolicy` is attached to a Gateway, add the corresponding NGINX directives to the `http` block.
357+
- When a `ProxySettingsPolicy` is attached to an HTTPRoute or GRPCRoute, add the corresponding NGINX directives to the final `location` blocks generated for the Route.
349358

350-
We can rely on NGINX to compute the effective policy by applying its own inheritance rules.
359+
We can rely on NGINX to compute the effective policy by applying its own inheritance rules. Since each Gateway has a 1-1 relationship with an NGINX deployment, Gateway-level policies naturally map to the `http` context, and Route-level policies in the `location` context can override them as needed.
351360

352361
## Testing
353362

0 commit comments

Comments
 (0)