Skip to content

Commit b968639

Browse files
authored
Watch UpstreamSettingsPolicies and translate into dataplane configuration (#2887)
Problem: As a userI want NGF to take my configuration for an UpstreamSettingsPolicy and transform it into data plane configuration within NGF, so that NGF can then translate those settings into NGINX configuration, and so that NGF maintains an abstraction layer between data plane configuration and the specific data plane NGF uses. Solution: Add controller to watch UpstreamSettingsPolicies, and store them in the cluster state as generic NGF Policies. Update the graph to validate and process these policies and attach them to the relevant Services. When building the dataplane configuration, store the policies on the relevant http upstreams.
1 parent eabc8c9 commit b968639

File tree

38 files changed

+1883
-238
lines changed

38 files changed

+1883
-238
lines changed

charts/nginx-gateway-fabric/templates/clusterrole.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ rules:
104104
- nginxproxies
105105
- clientsettingspolicies
106106
- observabilitypolicies
107+
- upstreamsettingspolicies
107108
{{- if .Values.nginxGateway.snippetsFilters.enable }}
108109
- snippetsfilters
109110
{{- end }}
@@ -116,6 +117,7 @@ rules:
116117
- nginxgateways/status
117118
- clientsettingspolicies/status
118119
- observabilitypolicies/status
120+
- upstreamsettingspolicies/status
119121
{{- if .Values.nginxGateway.snippetsFilters.enable }}
120122
- snippetsfilters/status
121123
{{- end }}

config/crd/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ resources:
55
- bases/gateway.nginx.org_nginxgateways.yaml
66
- bases/gateway.nginx.org_nginxproxies.yaml
77
- bases/gateway.nginx.org_observabilitypolicies.yaml
8+
- bases/gateway.nginx.org_snippetsfilters.yaml
9+
- bases/gateway.nginx.org_upstreamsettingspolicies.yaml

deploy/aws-nlb/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ rules:
9898
- nginxproxies
9999
- clientsettingspolicies
100100
- observabilitypolicies
101+
- upstreamsettingspolicies
101102
verbs:
102103
- list
103104
- watch
@@ -107,6 +108,7 @@ rules:
107108
- nginxgateways/status
108109
- clientsettingspolicies/status
109110
- observabilitypolicies/status
111+
- upstreamsettingspolicies/status
110112
verbs:
111113
- update
112114
- apiGroups:

deploy/azure/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ rules:
9898
- nginxproxies
9999
- clientsettingspolicies
100100
- observabilitypolicies
101+
- upstreamsettingspolicies
101102
verbs:
102103
- list
103104
- watch
@@ -107,6 +108,7 @@ rules:
107108
- nginxgateways/status
108109
- clientsettingspolicies/status
109110
- observabilitypolicies/status
111+
- upstreamsettingspolicies/status
110112
verbs:
111113
- update
112114
- apiGroups:

deploy/crds.yaml

Lines changed: 633 additions & 0 deletions
Large diffs are not rendered by default.

deploy/default/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ rules:
9898
- nginxproxies
9999
- clientsettingspolicies
100100
- observabilitypolicies
101+
- upstreamsettingspolicies
101102
verbs:
102103
- list
103104
- watch
@@ -107,6 +108,7 @@ rules:
107108
- nginxgateways/status
108109
- clientsettingspolicies/status
109110
- observabilitypolicies/status
111+
- upstreamsettingspolicies/status
110112
verbs:
111113
- update
112114
- apiGroups:

deploy/experimental-nginx-plus/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ rules:
111111
- nginxproxies
112112
- clientsettingspolicies
113113
- observabilitypolicies
114+
- upstreamsettingspolicies
114115
verbs:
115116
- list
116117
- watch
@@ -120,6 +121,7 @@ rules:
120121
- nginxgateways/status
121122
- clientsettingspolicies/status
122123
- observabilitypolicies/status
124+
- upstreamsettingspolicies/status
123125
verbs:
124126
- update
125127
- apiGroups:

deploy/experimental/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ rules:
103103
- nginxproxies
104104
- clientsettingspolicies
105105
- observabilitypolicies
106+
- upstreamsettingspolicies
106107
verbs:
107108
- list
108109
- watch
@@ -112,6 +113,7 @@ rules:
112113
- nginxgateways/status
113114
- clientsettingspolicies/status
114115
- observabilitypolicies/status
116+
- upstreamsettingspolicies/status
115117
verbs:
116118
- update
117119
- apiGroups:

deploy/nginx-plus/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ rules:
106106
- nginxproxies
107107
- clientsettingspolicies
108108
- observabilitypolicies
109+
- upstreamsettingspolicies
109110
verbs:
110111
- list
111112
- watch
@@ -115,6 +116,7 @@ rules:
115116
- nginxgateways/status
116117
- clientsettingspolicies/status
117118
- observabilitypolicies/status
119+
- upstreamsettingspolicies/status
118120
verbs:
119121
- update
120122
- apiGroups:

deploy/nodeport/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ rules:
9898
- nginxproxies
9999
- clientsettingspolicies
100100
- observabilitypolicies
101+
- upstreamsettingspolicies
101102
verbs:
102103
- list
103104
- watch
@@ -107,6 +108,7 @@ rules:
107108
- nginxgateways/status
108109
- clientsettingspolicies/status
109110
- observabilitypolicies/status
111+
- upstreamsettingspolicies/status
110112
verbs:
111113
- update
112114
- apiGroups:

deploy/openshift/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ rules:
9898
- nginxproxies
9999
- clientsettingspolicies
100100
- observabilitypolicies
101+
- upstreamsettingspolicies
101102
verbs:
102103
- list
103104
- watch
@@ -107,6 +108,7 @@ rules:
107108
- nginxgateways/status
108109
- clientsettingspolicies/status
109110
- observabilitypolicies/status
111+
- upstreamsettingspolicies/status
110112
verbs:
111113
- update
112114
- apiGroups:

deploy/snippets-filters-nginx-plus/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ rules:
106106
- nginxproxies
107107
- clientsettingspolicies
108108
- observabilitypolicies
109+
- upstreamsettingspolicies
109110
- snippetsfilters
110111
verbs:
111112
- list
@@ -116,6 +117,7 @@ rules:
116117
- nginxgateways/status
117118
- clientsettingspolicies/status
118119
- observabilitypolicies/status
120+
- upstreamsettingspolicies/status
119121
- snippetsfilters/status
120122
verbs:
121123
- update

deploy/snippets-filters/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ rules:
9898
- nginxproxies
9999
- clientsettingspolicies
100100
- observabilitypolicies
101+
- upstreamsettingspolicies
101102
- snippetsfilters
102103
verbs:
103104
- list
@@ -108,6 +109,7 @@ rules:
108109
- nginxgateways/status
109110
- clientsettingspolicies/status
110111
- observabilitypolicies/status
112+
- upstreamsettingspolicies/status
111113
- snippetsfilters/status
112114
verbs:
113115
- update
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: coffee
5+
spec:
6+
parentRefs:
7+
- name: gateway
8+
sectionName: http
9+
hostnames:
10+
- "cafe.example.com"
11+
rules:
12+
- matches:
13+
- path:
14+
type: PathPrefix
15+
value: /coffee
16+
backendRefs:
17+
- name: coffee
18+
port: 80
19+
---
20+
apiVersion: gateway.networking.k8s.io/v1
21+
kind: HTTPRoute
22+
metadata:
23+
name: tea
24+
spec:
25+
parentRefs:
26+
- name: gateway
27+
sectionName: http
28+
hostnames:
29+
- "cafe.example.com"
30+
rules:
31+
- matches:
32+
- path:
33+
type: Exact
34+
value: /tea
35+
backendRefs:
36+
- name: tea
37+
port: 80
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: coffee
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: coffee
10+
template:
11+
metadata:
12+
labels:
13+
app: coffee
14+
spec:
15+
containers:
16+
- name: coffee
17+
image: nginxdemos/nginx-hello:plain-text
18+
ports:
19+
- containerPort: 8080
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: coffee
25+
spec:
26+
ports:
27+
- port: 80
28+
targetPort: 8080
29+
protocol: TCP
30+
name: http
31+
selector:
32+
app: coffee
33+
---
34+
apiVersion: apps/v1
35+
kind: Deployment
36+
metadata:
37+
name: tea
38+
spec:
39+
replicas: 1
40+
selector:
41+
matchLabels:
42+
app: tea
43+
template:
44+
metadata:
45+
labels:
46+
app: tea
47+
spec:
48+
containers:
49+
- name: tea
50+
image: nginxdemos/nginx-hello:plain-text
51+
ports:
52+
- containerPort: 8080
53+
---
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: tea
58+
spec:
59+
ports:
60+
- port: 80
61+
targetPort: 8080
62+
protocol: TCP
63+
name: http
64+
selector:
65+
app: tea
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway
5+
spec:
6+
gatewayClassName: nginx
7+
listeners:
8+
- name: http
9+
port: 80
10+
protocol: HTTP
11+
hostname: "*.example.com"

examples/upstream-settings-policy/upstream-settings-policy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
targetRefs:
88
- group: core
99
kind: Service
10-
name: service
10+
name: coffee
1111
keepAlive:
1212
connections: 32
1313
requests: 1001

internal/framework/kinds/kinds.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111

1212
// Gateway API Kinds.
1313
const (
14-
// Gateway is the Gateway Kind.
14+
// Gateway is the Gateway kind.
1515
Gateway = "Gateway"
16-
// GatewayClass is the GatewayClass Kind.
16+
// GatewayClass is the GatewayClass kind.
1717
GatewayClass = "GatewayClass"
1818
// HTTPRoute is the HTTPRoute kind.
1919
HTTPRoute = "HTTPRoute"
@@ -23,6 +23,12 @@ const (
2323
TLSRoute = "TLSRoute"
2424
)
2525

26+
// Core API Kinds.
27+
const (
28+
// Service is the Service kind.
29+
Service = "Service"
30+
)
31+
2632
// NGINX Gateway Fabric kinds.
2733
const (
2834
// ClientSettingsPolicy is the ClientSettingsPolicy kind.
@@ -33,6 +39,8 @@ const (
3339
NginxProxy = "NginxProxy"
3440
// SnippetsFilter is the SnippetsFilter kind.
3541
SnippetsFilter = "SnippetsFilter"
42+
// UpstreamSettingsPolicy is the UpstreamSettingsPolicy kind.
43+
UpstreamSettingsPolicy = "UpstreamSettingsPolicy"
3644
)
3745

3846
// MustExtractGVK is a function that extracts the GroupVersionKind (GVK) of a client.object.

internal/mode/static/manager.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/policies"
5353
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/clientsettings"
5454
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/observability"
55+
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/upstreamsettings"
5556
ngxvalidation "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/validation"
5657
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/file"
5758
ngxruntime "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime"
@@ -311,6 +312,10 @@ func createPolicyManager(
311312
GVK: mustExtractGVK(&ngfAPI.ObservabilityPolicy{}),
312313
Validator: observability.NewValidator(validator),
313314
},
315+
{
316+
GVK: mustExtractGVK(&ngfAPI.UpstreamSettingsPolicy{}),
317+
Validator: upstreamsettings.NewValidator(validator),
318+
},
314319
}
315320

316321
return policies.NewManager(mustExtractGVK, cfgs...)
@@ -492,6 +497,12 @@ func registerControllers(
492497
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
493498
},
494499
},
500+
{
501+
objectType: &ngfAPI.UpstreamSettingsPolicy{},
502+
options: []controller.Option{
503+
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
504+
},
505+
},
495506
}
496507

497508
if cfg.ExperimentalFeatures {
@@ -728,6 +739,7 @@ func prepareFirstEventBatchPreparerArgs(cfg config.Config) ([]client.Object, []c
728739
&gatewayv1.GRPCRouteList{},
729740
&ngfAPI.ClientSettingsPolicyList{},
730741
&ngfAPI.ObservabilityPolicyList{},
742+
&ngfAPI.UpstreamSettingsPolicyList{},
731743
partialObjectMetadataList,
732744
}
733745

0 commit comments

Comments
 (0)