Skip to content

Functional Tests for SnippetsFilter #2664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/framework/ngf.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func InstallNGF(cfg InstallationConfig, extraArgs ...string) ([]byte, error) {
"--namespace", cfg.Namespace,
"--wait",
"--set", "nginxGateway.productTelemetry.enable=false",
"--set", "nginxGateway.snippetsFilters.enable=true",
}
if cfg.ChartVersion != "" {
args = append(args, "--version", cfg.ChartVersion)
Expand Down Expand Up @@ -96,6 +97,7 @@ func UpgradeNGF(cfg InstallationConfig, extraArgs ...string) ([]byte, error) {
"--wait",
"--set", "nginxGateway.productTelemetry.enable=false",
"--set", "nginxGateway.config.logging.level=debug",
"--set", "nginxGateway.snippetsFilter.enable=true",
}
if cfg.ChartVersion != "" {
args = append(args, "--version", cfg.ChartVersion)
Expand Down
98 changes: 98 additions & 0 deletions tests/suite/manifests/snippets-filter/cafe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: coffee
spec:
replicas: 1
selector:
matchLabels:
app: coffee
template:
metadata:
labels:
app: coffee
spec:
containers:
- name: coffee
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: coffee
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: coffee
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tea
spec:
replicas: 1
selector:
matchLabels:
app: tea
template:
metadata:
labels:
app: tea
spec:
containers:
- name: tea
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: tea
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: tea
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: soda
spec:
replicas: 1
selector:
matchLabels:
app: soda
template:
metadata:
labels:
app: soda
spec:
containers:
- name: soda
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: soda
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: soda
11 changes: 11 additions & 0 deletions tests/suite/manifests/snippets-filter/gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
hostname: "*.example.com"
39 changes: 39 additions & 0 deletions tests/suite/manifests/snippets-filter/grpc-backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: Service
metadata:
name: grpc-backend
spec:
selector:
app: grpc-backend
ports:
- protocol: TCP
port: 8080
targetPort: 50051
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: grpc-backend
labels:
app: grpc-backend
spec:
replicas: 1
selector:
matchLabels:
app: grpc-backend
template:
metadata:
labels:
app: grpc-backend
spec:
containers:
- name: grpc-backend
image: ghcr.io/nginxinc/kic-test-grpc-server:0.2.2
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
resources:
requests:
cpu: 10m
37 changes: 37 additions & 0 deletions tests/suite/manifests/snippets-filter/invalid-context-sf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: gateway.nginx.org/v1alpha1
kind: SnippetsFilter
metadata:
name: invalid-context
spec:
snippets:
- context: http
value: aio on;
- context: http.server
value: worker_priority 0; # wrong context for the directive, should be main.
- context: http.server.location
value: keepalive_time 10s;
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: soda
spec:
parentRefs:
- name: gateway
sectionName: http
hostnames:
- "cafe.example.com"
rules:
- matches:
- path:
type: Exact
value: /soda
filters:
- type: ExtensionRef
extensionRef:
group: gateway.nginx.org
kind: SnippetsFilter
name: invalid-context
backendRefs:
- name: soda
port: 80
39 changes: 39 additions & 0 deletions tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: gateway.nginx.org/v1alpha1
kind: SnippetsFilter
metadata:
name: duplicate-directive
spec:
snippets:
- context: main
value: worker_processes auto; # already present in the configuration
- context: http
value: aio on;
- context: http.server
value: auth_delay 10s;
- context: http.server.location
value: keepalive_time 10s;
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: tea
spec:
parentRefs:
- name: gateway

Check failure on line 22 in tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml

View workflow job for this annotation

GitHub Actions / YAML lint

[yamllint] reported by reviewdog 🐶 [error] wrong indentation: expected 4 but found 2 (indentation) Raw Output: ./tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml:22:3: [error] wrong indentation: expected 4 but found 2 (indentation)
sectionName: http
hostnames:
- "cafe.example.com"

Check failure on line 25 in tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml

View workflow job for this annotation

GitHub Actions / YAML lint

[yamllint] reported by reviewdog 🐶 [error] wrong indentation: expected 4 but found 2 (indentation) Raw Output: ./tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml:25:3: [error] wrong indentation: expected 4 but found 2 (indentation)
rules:
- matches:

Check failure on line 27 in tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml

View workflow job for this annotation

GitHub Actions / YAML lint

[yamllint] reported by reviewdog 🐶 [error] wrong indentation: expected 4 but found 2 (indentation) Raw Output: ./tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml:27:3: [error] wrong indentation: expected 4 but found 2 (indentation)
- path:

Check failure on line 28 in tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml

View workflow job for this annotation

GitHub Actions / YAML lint

[yamllint] reported by reviewdog 🐶 [error] wrong indentation: expected 6 but found 4 (indentation) Raw Output: ./tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml:28:5: [error] wrong indentation: expected 6 but found 4 (indentation)
type: Exact
value: /tea
filters:
- type: ExtensionRef
extensionRef:
group: gateway.nginx.org
kind: SnippetsFilter
name: duplicate-directive
backendRefs:
- name: tea

Check failure on line 38 in tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml

View workflow job for this annotation

GitHub Actions / YAML lint

[yamllint] reported by reviewdog 🐶 [error] wrong indentation: expected 6 but found 4 (indentation) Raw Output: ./tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml:38:5: [error] wrong indentation: expected 6 but found 4 (indentation)
port: 80
77 changes: 77 additions & 0 deletions tests/suite/manifests/snippets-filter/valid-sf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: gateway.nginx.org/v1alpha1
kind: SnippetsFilter
metadata:
name: all-contexts
spec:
snippets:
- context: main
value: worker_priority 0;
- context: http
value: aio on;
- context: http.server
value: auth_delay 10s;
- context: http.server.location
value: keepalive_time 10s;
---
apiVersion: gateway.nginx.org/v1alpha1
kind: SnippetsFilter
metadata:
name: grpc-all-contexts
spec:
snippets:
- context: main
value: worker_shutdown_timeout 120s;
- context: http
value: types_hash_bucket_size 64;
- context: http.server
value: server_tokens on;
- context: http.server.location
value: tcp_nodelay on;
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: coffee
spec:
parentRefs:
- name: gateway
sectionName: http
hostnames:
- "cafe.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /coffee
filters:
- type: ExtensionRef
extensionRef:
group: gateway.nginx.org
kind: SnippetsFilter
name: all-contexts
backendRefs:
- name: coffee
port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: grpc-route
spec:
parentRefs:
- name: gateway
sectionName: http
rules:
- matches:
- method:
service: helloworld.Greeter
method: SayHello
filters:
- type: ExtensionRef
extensionRef:
group: gateway.nginx.org
kind: SnippetsFilter
name: grpc-all-contexts
backendRefs:
- name: grpc-backend
port: 8080
Loading