Skip to content

Commit b3e7d39

Browse files
authored
Add overview of custom NGF policies (#2088)
Problem: As a user, I need to understand how custom policies work in NGF, so that I can use them correctly. Solution: Add a document that gives an overview of NGF custom policies. This overview includes a summary of the policies, how they are applied, how they are merged, and the format of their statuses.
1 parent d7f63b8 commit b3e7d39

File tree

7 files changed

+186
-17
lines changed

7 files changed

+186
-17
lines changed

site/content/how-to/monitoring/tracing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,7 @@ Select a trace to view the attributes.
330330
{{<img src="img/jaeger-trace-attributes.png" alt="">}}
331331

332332
The trace includes the attribute from the global NginxProxy resource as well as the attribute from the ObservabilityPolicy.
333+
334+
## Further Reading
335+
336+
- [Custom policies]({{< relref "overview/custom-policies.md" >}}): learn about how NGINX Gateway Fabric custom policies work.

site/content/how-to/traffic-management/client-settings.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The settings in `ClientSettingsPolicy` correspond to the following NGINX directi
2424
When applied to a Gateway, the settings specified in the `ClientSettingsPolicy` affect all HTTPRoutes and GRPCRoutes attached to the Gateway. This allows Cluster Operators to set defaults for all applications using the Gateway.
2525

2626
When applied to an HTTPRoute or GRPCRoute, the settings in the `ClientSettingsPolicy` affect only the route they are applied to. This allows Application Developers to set values for their applications based on their application's behavior or requirements.
27-
Settings applied to an HTTPRoute or GRPCRoute take precedence over settings applied to a Gateway.
27+
Settings applied to an HTTPRoute or GRPCRoute take precedence over settings applied to a Gateway. See the [custom policies]({{< relref "overview/custom-policies.md" >}}) document for more information on policies.
2828

2929
This guide will show you how to use the `ClientSettingsPolicy` API to configure the client max body size for your applications.
3030

@@ -276,3 +276,7 @@ spec:
276276
maxSize: "75" # sizes without a unit are bytes.
277277
EOF
278278
```
279+
280+
## Further Reading
281+
282+
- [Custom policies]({{< relref "overview/custom-policies.md" >}}): learn about how NGINX Gateway Fabric custom policies work.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
title: "Custom policies"
3+
weight: 600
4+
toc: true
5+
docs: "DOCS-000"
6+
---
7+
8+
## Overview
9+
10+
Custom policies are NGINX Gateway Fabric CRDs (Custom Resource Definitions) that allow users to configure NGINX data plane features that are unavailable in the Gateway API.
11+
These custom policies follow the Gateway API [Policy Attachment](https://gateway-api.sigs.k8s.io/reference/policy-attachment/) pattern, which allows users to extend the Gateway API functionality by creating implementation-specific policies and attaching them to Kubernetes objects such as HTTPRoutes, Gateways, and Services.
12+
13+
Policies are a Kubernetes object that augments the behavior of an object in a standard way. Policies can be attached to one object ([Direct Policy Attachment](#direct-policy-attachment)) or objects in a hierarchy ([Inherited Policy Attachment](#inherited-policy-attachment)).
14+
The following table summarizes NGINX Gateway Fabric custom policies:
15+
16+
{{< bootstrap-table "table table-striped table-bordered" >}}
17+
18+
| Policy | Description | Attachment Type | Supported Target Object(s) | Supports Multiple Target Refs | Mergeable | API Version |
19+
|---------------------------------------------------------------------------------------|---------------------------------------------------------|-----------------|-------------------------------|-------------------------------|-----------|-------------|
20+
| [ClientSettingsPolicy]({{<relref "/how-to/traffic-management/client-settings.md" >}}) | Configure connection behavior between client and NGINX | Inherited | Gateway, HTTPRoute, GRPCRoute | No | Yes | v1alpha1 |
21+
| [ObservabilityPolicy]({{<relref "/how-to/monitoring/tracing.md" >}}) | Define settings related to tracing, metrics, or logging | Direct | HTTPRoute, GRPCRoute | Yes | No | v1alpha1 |
22+
23+
{{</bootstrap-table>}}
24+
25+
26+
{{< important >}}
27+
NGINX Gateway Fabric policies do not work with [HTTPRoute matches](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteMatch) with `headers`, `params`, or `method` matchers defined. It will be added in a future release.
28+
{{< /important >}}
29+
30+
## Terminology
31+
32+
- _Attachment Type_. How the policy attaches to an object. Attachment type can be "direct" or "inherited".
33+
- _Supported Target Object(s)_. API objects the policy can be applied to.
34+
- _Supports Multiple Target Refs_. Whether a single policy can target multiple objects.
35+
- _Mergeable_. Whether policies that target the same object can be merged.
36+
37+
## Direct Policy Attachment
38+
39+
A Direct Policy Attachment is a policy that references a single object, such as a Gateway or HTTPRoute. It is tightly bound to one instance of a particular Kind within a single Namespace or an instance of a single Kind at the cluster-scope. It affects _only_ the object specified in its TargetRef.
40+
41+
This diagram uses a fictional retry policy to show how Direct Policy Attachment works:
42+
43+
{{<img src="img/direct-policy-attachment.png" alt="">}}
44+
45+
The policy targets the HTTPRoute `baz` and sets `retries` to `3` and `timeout` to `60s`. Since this policy is a Direct Policy Attachment, its settings are only applied to the `baz` HTTPRoute.
46+
47+
## Inherited Policy Attachment
48+
49+
Inherited Policy Attachment allows settings to cascade down a hierarchy. The hierarchy for Gateway API resources looks like this:
50+
51+
{{<img src="img/hierarchy.png" alt="">}}
52+
53+
Settings defined in a policy attached to an object in this hierarchy may be inherited by the resources below it. For example, the settings defined in a policy attached to a Gateway may be inherited by all the HTTPRoutes attached to that Gateway.
54+
55+
Settings in an Inherited Policy can be Defaults or Overrides. Defaults set the default value for something and can be overridden by policies on a lower object. Overrides cannot be overridden by lower objects.
56+
All settings in NGINX Gateway Fabric Inherited Policies are Defaults.
57+
58+
Default values are given precedence from the bottom up. Therefore, a policy setting attached to a Backend will have the highest precedence over the one attached to higher objects.
59+
60+
The following diagram shows how Inherited Policies work in NGINX Gateway Fabric using a fictional retry policy:
61+
62+
{{<img src="img/inherited-policy-attachment.png" alt="">}}
63+
64+
There are three policies defined:
65+
66+
- `dev-policy` that targets the `dev` Gateway
67+
- `baz-policy` that targets the `baz` HTTPRoute
68+
- `foo-policy` that targets the `foo` HTTPRoute
69+
70+
The settings in `dev-policy` affect the `dev` Gateway and are inherited by all the HTTPRoutes attached to `dev`.
71+
The `baz-policy` and `foo-policy` are attached to the `baz` and `foo` HTTPRoutes. Since HTTPRoutes are lower than Gateways in the hierarchy, the settings defined in them override those in the `dev` policy.
72+
Since the `foo-policy` only defines the `retries` setting, it still inherits the `timeout` setting from `dev-policy`.
73+
The `bar` HTTPRoute has no policy attached to it and inherits all the settings from `dev-policy`.
74+
75+
## Merging Policies
76+
77+
With some NGINX Gateway Fabric Policies, it is possible to create multiple policies that target the same resource as long as the fields in those policies do not conflict.
78+
79+
For example, consider the following fictional policies:
80+
81+
```yaml
82+
apiVersion: gateway.nginx.org/v1alpha1
83+
kind: ExamplePolicy
84+
metadata:
85+
name: retries
86+
spec:
87+
targetRef:
88+
group: gateway.networking.k8s.io
89+
kind: HTTPRoute
90+
name: foo
91+
retries: 10
92+
```
93+
94+
95+
```yaml
96+
apiVersion: gateway.nginx.org/v1alpha1
97+
kind: ExamplePolicy
98+
metadata:
99+
name: timeout
100+
spec:
101+
targetRef:
102+
kind: HTTPRoute
103+
name: foo
104+
timeout: 60s
105+
```
106+
107+
The `retries` ExamplePolicy defines the number of retries for the `foo` HTTPRoute, and the `timeout` ExamplePolicy defines the timeout for the `foo` HTTPRoute.
108+
NGINX Gateway Fabric will merge the fields defined in the policies and apply the following settings to the `foo` HTTPRoute:
109+
110+
```yaml
111+
retries: 10
112+
timeout: 60s
113+
```
114+
115+
However, if both policies had the `retries` field set, then the policies cannot be merged. In this case, NGINX Gateway Fabric will choose which policy to configure based on the following criteria (continuing on ties):
116+
117+
1. The oldest policy by creation timestamp
118+
1. The policy appearing first in alphabetical order by "{namespace}/{name}"
119+
120+
If a policy conflicts with a configured policy, NGINX Gateway Fabric will set the policy `Accepted` status to false with a reason of `Conflicted`. See [Policy Status](#policy-status) for more details.
121+
122+
## Policy Status
123+
124+
NGINX Gateway Fabric sets the [PolicyStatus](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1alpha2.PolicyStatus) on all policies.
125+
126+
`PolicyStatus` fields:
127+
128+
- `ancestors`: describes the status of a route with respect to the ancestor.
129+
- `ancestorRef`: the object that the policy targets in `spec.targetRef`.
130+
- `controllerName`: the controller name of NGINX Gateway Fabric.
131+
- `conditions`: (Condition/Status/Reason):
132+
- `Accepted/True/Accepted`: the policy is accepted by the ancestor.
133+
- `Accepted/False/Invalid`: the policy is not accepted because it is semantically or syntactically invalid.
134+
- `Accepted/False/Conflicted`: the policy is not accepted because it conflicts with another policy.
135+
- `Accepted/False/TargetNotFound`: the policy is not accepted because it targets a resource that is invalid or does not exist.
136+
- `Accepted/False/NginxProxyNotSet`: the policy is not accepted because it relies on the NginxProxy configuration which is missing or invalid.
137+
138+
To check the status of a policy, use `kubectl describe`. This example checks the status of the `foo` ObservabilityPolicy, which is accepted:
139+
140+
```shell
141+
kubectl describe observabilitypolicies.gateway.nginx.org foo -n default
142+
```
143+
144+
```text
145+
Status:
146+
Ancestors:
147+
Ancestor Ref:
148+
Group: gateway.networking.k8s.io
149+
Kind: HTTPRoute
150+
Name: foo
151+
Namespace: default
152+
Conditions:
153+
Last Transition Time: 2024-05-23T18:13:03Z
154+
Message: Policy is accepted
155+
Observed Generation: 1
156+
Reason: Accepted
157+
Status: True
158+
Type: Accepted
159+
Controller Name: gateway.nginx.org/nginx-gateway-controller
160+
```

site/content/overview/gateway-api-compatibility.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ docs: "DOCS-1412"
1111
{{< bootstrap-table "table table-striped table-bordered" >}}
1212
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
1313
| ------------------------------------- | ------------------- | ---------------------- | ------------------------------------- | ----------- |
14-
| [GatewayClass](#gatewayclass) | Supported | Not supported | Not supported | v1 |
15-
| [Gateway](#gateway) | Supported | Not supported | Not supported | v1 |
14+
| [GatewayClass](#gatewayclass) | Supported | Not supported | Supported | v1 |
15+
| [Gateway](#gateway) | Supported | Partially supported | Not supported | v1 |
1616
| [HTTPRoute](#httproute) | Supported | Partially supported | Not supported | v1 |
1717
| [ReferenceGrant](#referencegrant) | Supported | N/A | Not supported | v1beta1 |
18-
| [GRPCRoute](#grpcroute) | Partially Supported | Not supported | Not supported | v1 |
18+
| [GRPCRoute](#grpcroute) | Partially Supported | Partially supported | Not supported | v1 |
1919
| [TLSRoute](#tlsroute) | Not supported | Not supported | Not supported | N/A |
2020
| [TCPRoute](#tcproute) | Not supported | Not supported | Not supported | N/A |
2121
| [UDPRoute](#udproute) | Not supported | Not supported | Not supported | N/A |
2222
| [BackendTLSPolicy](#backendtlspolicy) | Supported | Supported | Not supported | v1alpha3 |
23-
| [Custom policies](#custom-policies) | Not supported | N/A | Not supported | N/A |
23+
| [Custom policies](#custom-policies) | N/A | N/A | Supported | N/A |
2424
{{< /bootstrap-table >}}
2525

2626
---
@@ -48,9 +48,9 @@ For a description of each field, visit the [Gateway API documentation](https://g
4848
### GatewayClass
4949

5050
{{< bootstrap-table "table table-striped table-bordered" >}}
51-
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
52-
| ------------ | ------------------ | ---------------------- | ------------------------------------- | ----------- |
53-
| GatewayClass | Supported | Not supported | Not supported | v1 |
51+
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level| API Version |
52+
| ------------ | ------------------ | ---------------------- | ----------------------------------- | ----------- |
53+
| GatewayClass | Supported | Not supported | Supported | v1 |
5454
{{< /bootstrap-table >}}
5555

5656
NGINX Gateway Fabric supports a single GatewayClass resource configured with the `--gatewayclass` flag of the [static-mode]({{< relref "/reference/cli-help.md#static-mode">}}) command.
@@ -76,9 +76,9 @@ NGINX Gateway Fabric supports a single GatewayClass resource configured with the
7676
### Gateway
7777

7878
{{< bootstrap-table "table table-striped table-bordered" >}}
79-
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
80-
| -------- | ------------------ | ---------------------- | ------------------------------------- | ----------- |
81-
| Gateway | Supported | Not supported | Not supported | v1 |
79+
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
80+
| -------- | ------------------ | -----------------------------| ------------------------------------- | ----------- |
81+
| Gateway | Supported | Partially supported | Not supported | v1 |
8282
{{< /bootstrap-table >}}
8383

8484
NGINX Gateway Fabric supports a single Gateway resource. The Gateway resource must reference NGINX Gateway Fabric's corresponding GatewayClass.
@@ -185,9 +185,9 @@ See the [static-mode]({{< relref "/reference/cli-help.md#static-mode">}}) comman
185185
### GRPCRoute
186186

187187
{{< bootstrap-table "table table-striped table-bordered" >}}
188-
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
189-
| --------- | ------------------- | ---------------------- | ------------------------------------- | ----------- |
190-
| GRPCRoute | Supported | Not supported | Not supported | v1 |
188+
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
189+
| --------- | ------------------- | -----------------------------| ------------------------------------- | ----------- |
190+
| GRPCRoute | Supported | Partially supported | Not supported | v1 |
191191
{{< /bootstrap-table >}}
192192

193193
**Fields**:
@@ -315,9 +315,10 @@ Fields:
315315
{{< bootstrap-table "table table-striped table-bordered" >}}
316316
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
317317
| --------------- | ------------------ | ---------------------- | ------------------------------------- | ----------- |
318-
| Custom policies | Not supported | N/A | Not supported | N/A |
318+
| Custom policies | N/A | N/A | Supported | N/A |
319319
{{< /bootstrap-table >}}
320320

321-
Custom policies will be NGINX Gateway Fabric-specific CRDs (Custom Resource Definitions) that will support features such as timeouts, load-balancing methods, authentication, etc. These important data-plane features are not part of the Gateway API specifications.
322-
321+
Custom policies are NGINX Gateway Fabric-specific CRDs (Custom Resource Definitions) that support features such as tracing, and client connection settings. These important data-plane features are not part of the Gateway API specifications.
323322
While these CRDs are not part of the Gateway API, the mechanism to attach them to Gateway API resources is part of the Gateway API. See the [Policy Attachment documentation](https://gateway-api.sigs.k8s.io/references/policy-attachment/).
323+
324+
See the [custom policies]({{< relref "overview/custom-policies.md" >}}) document for more information.
12.3 KB
Loading

site/static/img/hierarchy.png

15.7 KB
Loading
72.6 KB
Loading

0 commit comments

Comments
 (0)