Skip to content

Commit bb4b406

Browse files
authored
Merge branch 'main' into chore/more-linters
2 parents 21c8c82 + b3e7d39 commit bb4b406

File tree

16 files changed

+322
-35
lines changed

16 files changed

+322
-35
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
114114

115115
- name: Build Docker Image
116-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
116+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
117117
with:
118118
file: build/Dockerfile${{ inputs.image == 'nginx' && '.nginx' || '' }}${{ inputs.image == 'plus' && '.nginxplus' || '' }}
119119
context: "."

.github/workflows/conformance.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ jobs:
8080
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
8181
with:
8282
version: latest
83-
args: build --snapshot --clean
83+
args: build --single-target --snapshot --clean
8484
env:
8585
TELEMETRY_ENDPOINT: "" # disables sending telemetry
8686
TELEMETRY_ENDPOINT_INSECURE: "false"
8787

8888
- name: Build NGF Docker Image
89-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
89+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
9090
with:
9191
file: build/Dockerfile
9292
tags: ${{ steps.ngf-meta.outputs.tags }}
@@ -97,7 +97,7 @@ jobs:
9797
pull: true
9898

9999
- name: Build NGINX Docker Image
100-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
100+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
101101
with:
102102
file: build/Dockerfile${{ inputs.image == 'nginx' && '.nginx' || '' }}${{ inputs.image == 'plus' && '.nginxplus' || ''}}
103103
tags: ${{ steps.nginx-meta.outputs.tags }}
@@ -116,7 +116,7 @@ jobs:
116116
working-directory: ./tests
117117

118118
- name: Build Test Docker Image
119-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
119+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
120120
with:
121121
file: tests/conformance/Dockerfile
122122
tags: conformance-test-runner:${{ github.sha }}

.github/workflows/functional.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ jobs:
6868
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
6969
with:
7070
version: latest
71-
args: build --snapshot --clean
71+
args: build --single-target --snapshot --clean
7272
env:
7373
TELEMETRY_ENDPOINT: otel-collector-opentelemetry-collector.collector.svc.cluster.local:4317
7474
TELEMETRY_ENDPOINT_INSECURE: "true"
7575

7676
- name: Build NGF Docker Image
77-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
77+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
7878
with:
7979
file: build/Dockerfile
8080
tags: ${{ steps.ngf-meta.outputs.tags }}
@@ -85,7 +85,7 @@ jobs:
8585
target: goreleaser
8686

8787
- name: Build NGINX Docker Image
88-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
88+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
8989
with:
9090
file: build/Dockerfile${{ inputs.image == 'nginx' && '.nginx' || '' }}${{ inputs.image == 'plus' && '.nginxplus' || ''}}
9191
tags: ${{ steps.nginx-meta.outputs.tags }}
@@ -98,6 +98,14 @@ jobs:
9898
NGINX_CONF_DIR=internal/mode/static/nginx/conf
9999
BUILD_AGENT=gha
100100
101+
- name: Install cloud-provider-kind
102+
run: |
103+
curl -fsSL -O https://github.com/kubernetes-sigs/cloud-provider-kind/releases/download/v0.2.0/cloud-provider-kind_0.2.0_linux_amd64.tar.gz
104+
tar -xvf cloud-provider-kind_0.2.0_linux_amd64.tar.gz
105+
106+
- name: Run cloud-provider-kind
107+
run: ./cloud-provider-kind & > cloud-provider-kind.log 2>&1
108+
101109
- name: Deploy Kubernetes
102110
id: k8s
103111
run: |
@@ -108,12 +116,12 @@ jobs:
108116
run: |
109117
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
110118
ngf_tag=${{ steps.ngf-meta.outputs.version }}
111-
make test${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag} GINKGO_LABEL=telemetry
119+
make test${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag} GINKGO_LABEL=telemetry GW_SERVICE_TYPE=LoadBalancer
112120
working-directory: ./tests
113121

114122
- name: Run functional tests
115123
run: |
116124
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
117125
ngf_tag=${{ steps.ngf-meta.outputs.version }}
118-
make test${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
126+
make test${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag} GW_SERVICE_TYPE=LoadBalancer
119127
working-directory: ./tests

.github/workflows/helm.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
6161
6262
- name: Build NGF Docker Image
63-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
63+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
6464
with:
6565
file: build/Dockerfile
6666
tags: ${{ steps.ngf-meta.outputs.tags }}
@@ -71,7 +71,7 @@ jobs:
7171
pull: true
7272

7373
- name: Build NGINX Docker Image
74-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
74+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
7575
with:
7676
file: build/Dockerfile${{ inputs.image == 'nginx' && '.nginx' || '' }}${{ inputs.image == 'plus' && '.nginxplus' || ''}}
7777
tags: ${{ steps.nginx-meta.outputs.tags }}

.github/workflows/nfr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989

9090
- name: Build NGINX Plus Docker Image
9191
if: ${{ inputs.nginx_plus == true }}
92-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
92+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
9393
with:
9494
file: build/Dockerfile.nginxplus
9595
tags: ${{ steps.nginx-meta.outputs.tags }}

build/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN make build
1111

1212
FROM golang:1.22 as ca-certs-provider
1313

14-
FROM alpine:3.19 as capabilizer
14+
FROM alpine:3.20 as capabilizer
1515
RUN apk add --no-cache libcap
1616

1717
FROM capabilizer as local-capabilizer

build/Dockerfile.nginxplus

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM scratch as nginx-files
55
ADD --link --chown=101:1001 https://cs.nginx.com/static/keys/nginx_signing.rsa.pub nginx_signing.rsa.pub
66

77

8-
FROM alpine:3.19
8+
FROM alpine:3.20
99

1010
ARG NGINX_PLUS_VERSION=R32
1111
ARG NJS_DIR

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

+4
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

+5-1
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.
+160
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+
```

0 commit comments

Comments
 (0)