Skip to content

Commit 990cc19

Browse files
committed
add functional tests for snippetsFilter
1 parent 40e5852 commit 990cc19

File tree

13 files changed

+741
-0
lines changed

13 files changed

+741
-0
lines changed

charts/nginx-gateway-fabric/values.schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,20 @@
519519
"required": [],
520520
"title": "securityContext",
521521
"type": "object"
522+
},
523+
"snippetsFilters": {
524+
"properties": {
525+
"enable": {
526+
"default": false,
527+
"description": "Enable SnippetsFilters feature. SnippetsFilters allow inserting NGINX configuration into the generated NGINX\nconfig for HTTPRoute and GRPCRoute resources.",
528+
"required": [],
529+
"title": "enable",
530+
"type": "boolean"
531+
}
532+
},
533+
"required": [],
534+
"title": "snippetsFilters",
535+
"type": "object"
522536
}
523537
},
524538
"required": [

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ subjects:
153153
namespace: nginx-gateway
154154
---
155155
apiVersion: v1
156+
data:
157+
main.conf: |
158+
error_log stderr info;
159+
kind: ConfigMap
160+
metadata:
161+
labels:
162+
app.kubernetes.io/instance: nginx-gateway
163+
app.kubernetes.io/name: nginx-gateway
164+
app.kubernetes.io/version: edge
165+
name: nginx-includes
166+
namespace: nginx-gateway
167+
---
168+
apiVersion: v1
156169
kind: Service
157170
metadata:
158171
labels:
@@ -299,6 +312,33 @@ spec:
299312
name: nginx-cache
300313
- mountPath: /etc/nginx/includes
301314
name: nginx-includes
315+
initContainers:
316+
- command:
317+
- /usr/bin/gateway
318+
- copy
319+
- --source
320+
- /includes/main.conf
321+
- --destination
322+
- /etc/nginx/main-includes/main.conf
323+
image: ghcr.io/nginxinc/nginx-gateway-fabric:edge
324+
imagePullPolicy: Always
325+
name: copy-nginx-config
326+
securityContext:
327+
capabilities:
328+
add:
329+
- KILL
330+
drop:
331+
- ALL
332+
readOnlyRootFilesystem: true
333+
runAsGroup: 1001
334+
runAsUser: 102
335+
seccompProfile:
336+
type: RuntimeDefault
337+
volumeMounts:
338+
- mountPath: /includes
339+
name: nginx-includes-configmap
340+
- mountPath: /etc/nginx/main-includes
341+
name: nginx-main-includes
302342
securityContext:
303343
fsGroup: 1001
304344
runAsNonRoot: true
@@ -320,6 +360,9 @@ spec:
320360
name: nginx-cache
321361
- emptyDir: {}
322362
name: nginx-includes
363+
- configMap:
364+
name: nginx-includes
365+
name: nginx-includes-configmap
323366
---
324367
apiVersion: gateway.networking.k8s.io/v1
325368
kind: GatewayClass

deploy/snippets-filters/deploy.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ subjects:
145145
namespace: nginx-gateway
146146
---
147147
apiVersion: v1
148+
data:
149+
main.conf: |
150+
error_log stderr info;
151+
kind: ConfigMap
152+
metadata:
153+
labels:
154+
app.kubernetes.io/instance: nginx-gateway
155+
app.kubernetes.io/name: nginx-gateway
156+
app.kubernetes.io/version: edge
157+
name: nginx-includes
158+
namespace: nginx-gateway
159+
---
160+
apiVersion: v1
148161
kind: Service
149162
metadata:
150163
labels:
@@ -290,6 +303,33 @@ spec:
290303
name: nginx-cache
291304
- mountPath: /etc/nginx/includes
292305
name: nginx-includes
306+
initContainers:
307+
- command:
308+
- /usr/bin/gateway
309+
- copy
310+
- --source
311+
- /includes/main.conf
312+
- --destination
313+
- /etc/nginx/main-includes/main.conf
314+
image: ghcr.io/nginxinc/nginx-gateway-fabric:edge
315+
imagePullPolicy: Always
316+
name: copy-nginx-config
317+
securityContext:
318+
capabilities:
319+
add:
320+
- KILL
321+
drop:
322+
- ALL
323+
readOnlyRootFilesystem: true
324+
runAsGroup: 1001
325+
runAsUser: 102
326+
seccompProfile:
327+
type: RuntimeDefault
328+
volumeMounts:
329+
- mountPath: /includes
330+
name: nginx-includes-configmap
331+
- mountPath: /etc/nginx/main-includes
332+
name: nginx-main-includes
293333
securityContext:
294334
fsGroup: 1001
295335
runAsNonRoot: true
@@ -311,6 +351,9 @@ spec:
311351
name: nginx-cache
312352
- emptyDir: {}
313353
name: nginx-includes
354+
- configMap:
355+
name: nginx-includes
356+
name: nginx-includes-configmap
314357
---
315358
apiVersion: gateway.networking.k8s.io/v1
316359
kind: GatewayClass

tests/framework/ngf.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func InstallNGF(cfg InstallationConfig, extraArgs ...string) ([]byte, error) {
6767
"--namespace", cfg.Namespace,
6868
"--wait",
6969
"--set", "nginxGateway.productTelemetry.enable=false",
70+
"--set", "nginxGateway.snippetsFilters.enable=true",
7071
}
7172
if cfg.ChartVersion != "" {
7273
args = append(args, "--version", cfg.ChartVersion)
@@ -96,6 +97,7 @@ func UpgradeNGF(cfg InstallationConfig, extraArgs ...string) ([]byte, error) {
9697
"--wait",
9798
"--set", "nginxGateway.productTelemetry.enable=false",
9899
"--set", "nginxGateway.config.logging.level=debug",
100+
"--set", "nginxGateway.snippetsFilter.enable=true",
99101
}
100102
if cfg.ChartVersion != "" {
101103
args = append(args, "--version", cfg.ChartVersion)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
filters:
17+
- type: ExtensionRef
18+
extensionRef:
19+
group: gateway.nginx.org
20+
kind: SnippetsFilter
21+
name: all-contexts
22+
backendRefs:
23+
- name: coffee
24+
port: 80
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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
66+
---
67+
apiVersion: apps/v1
68+
kind: Deployment
69+
metadata:
70+
name: soda
71+
spec:
72+
replicas: 1
73+
selector:
74+
matchLabels:
75+
app: soda
76+
template:
77+
metadata:
78+
labels:
79+
app: soda
80+
spec:
81+
containers:
82+
- name: soda
83+
image: nginxdemos/nginx-hello:plain-text
84+
ports:
85+
- containerPort: 8080
86+
---
87+
apiVersion: v1
88+
kind: Service
89+
metadata:
90+
name: soda
91+
spec:
92+
ports:
93+
- port: 80
94+
targetPort: 8080
95+
protocol: TCP
96+
name: http
97+
selector:
98+
app: soda
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"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: grpc-backend
5+
spec:
6+
selector:
7+
app: grpc-backend
8+
ports:
9+
- protocol: TCP
10+
port: 8080
11+
targetPort: 50051
12+
---
13+
apiVersion: apps/v1
14+
kind: Deployment
15+
metadata:
16+
name: grpc-backend
17+
labels:
18+
app: grpc-backend
19+
spec:
20+
replicas: 1
21+
selector:
22+
matchLabels:
23+
app: grpc-backend
24+
template:
25+
metadata:
26+
labels:
27+
app: grpc-backend
28+
spec:
29+
containers:
30+
- name: grpc-backend
31+
image: ghcr.io/nginxinc/kic-test-grpc-server:0.2.2
32+
env:
33+
- name: POD_NAME
34+
valueFrom:
35+
fieldRef:
36+
fieldPath: metadata.name
37+
resources:
38+
requests:
39+
cpu: 10m
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: GRPCRoute
3+
metadata:
4+
name: grpc-route
5+
spec:
6+
parentRefs:
7+
- name: gateway
8+
sectionName: http
9+
rules:
10+
- matches:
11+
- method:
12+
service: helloworld.Greeter
13+
method: SayHello
14+
filters:
15+
- type: ExtensionRef
16+
extensionRef:
17+
group: gateway.nginx.org
18+
kind: SnippetsFilter
19+
name: grpc-all-contexts
20+
backendRefs:
21+
- name: grpc-backend
22+
port: 8080

0 commit comments

Comments
 (0)