Skip to content

Commit b4c4663

Browse files
committed
functional tests for upstreamSettingsPolicy
1 parent 91c4ff4 commit b4c4663

File tree

8 files changed

+371
-111
lines changed

8 files changed

+371
-111
lines changed

Diff for: tests/framework/crossplane.go

+17
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type ExpectedNginxField struct {
3030
Location string
3131
// Servers are the server names that the directive should exist in.
3232
Servers []string
33+
// Upstream are the upstream names that the directive should exist in.
34+
Upstreams []string
3335
// ValueSubstringAllowed allows the expected value to be a substring of the real value.
3436
// This makes it easier for cases when real values are complex file names or contain things we
3537
// don't care about, and we just want to check if a substring exists.
@@ -64,6 +66,8 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
6466
}
6567
}
6668
}
69+
70+
return validateUpstreamDirectives(expFieldCfg, directive)
6771
}
6872
}
6973

@@ -75,6 +79,19 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
7579
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, string(b))
7680
}
7781

82+
func validateUpstreamDirectives(expFieldCfg ExpectedNginxField, directive *Directive) error {
83+
for _, upstreamName := range expFieldCfg.Upstreams {
84+
if directive.Directive == "upstream" && directive.Args[0] == upstreamName {
85+
for _, upstreamDirective := range directive.Block {
86+
if expFieldCfg.fieldFound(upstreamDirective) {
87+
return nil
88+
}
89+
}
90+
}
91+
}
92+
return nil
93+
}
94+
7895
func getServerName(serverBlock Directives) string {
7996
for _, directive := range serverBlock {
8097
if directive.Directive == "server_name" {

Diff for: tests/suite/manifests/upstream-settings-policy/cafe.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ spec:
6363
name: http
6464
selector:
6565
app: tea
66-
---
66+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway-httproute-allowed
5+
spec:
6+
gatewayClassName: nginx
7+
listeners:
8+
- name: http
9+
port: 80
10+
protocol: HTTP
11+
hostname: "soda.example.com"
12+
allowedRoutes:
13+
namespaces:
14+
from: All
15+
kinds:
16+
kind: GRPCRoute
17+
---
18+
apiVersion: apps/v1
19+
kind: Deployment
20+
metadata:
21+
name: soda
22+
spec:
23+
replicas: 1
24+
selector:
25+
matchLabels:
26+
app: soda
27+
template:
28+
metadata:
29+
labels:
30+
app: soda
31+
spec:
32+
containers:
33+
- name: soda
34+
image: nginxdemos/nginx-hello:plain-text
35+
ports:
36+
- containerPort: 8080
37+
---
38+
apiVersion: v1
39+
kind: Service
40+
metadata:
41+
name: soda
42+
spec:
43+
ports:
44+
- port: 80
45+
targetPort: 8080
46+
protocol: TCP
47+
name: http
48+
selector:
49+
app: soda
50+
---
51+
apiVersion: gateway.networking.k8s.io/v1
52+
kind: HTTPRoute
53+
metadata:
54+
name: soda
55+
spec:
56+
parentRefs:
57+
- name: gateway-httproute-allowed
58+
sectionName: http
59+
hostnames:
60+
- "soda.example.com"
61+
rules:
62+
- matches:
63+
- path:
64+
type: Exact
65+
value: /soda
66+
backendRefs:
67+
- name: soda
68+
port: 80
69+
---
70+
apiVersion: gateway.nginx.org/v1alpha1
71+
kind: UpstreamSettingsPolicy
72+
metadata:
73+
name: soda-svc-usp
74+
spec:
75+
zoneSize: 512k
76+
targetRefs:
77+
- group: core
78+
kind: Service
79+
name: soda
80+
keepAlive:
81+
connections: 10
82+
requests: 3
83+
time: 10s
84+
timeout: 50s

Diff for: tests/suite/manifests/upstream-settings-policy/routes.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ spec:
3232
method: SayHello
3333
backendRefs:
3434
- name: grpc-backend
35-
port: 8080
35+
port: 8080
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: gateway.nginx.org/v1alpha1
2+
kind: UpstreamSettingsPolicy
3+
metadata:
4+
name: coffee-svc-usp-1
5+
spec:
6+
zoneSize: 64k
7+
targetRefs:
8+
- group: core
9+
kind: Service
10+
name: coffee
11+
---
12+
apiVersion: gateway.nginx.org/v1alpha1
13+
kind: UpstreamSettingsPolicy
14+
metadata:
15+
name: coffee-svc-usp-2
16+
spec:
17+
targetRefs:
18+
- group: core
19+
kind: Service
20+
name: coffee
21+
keepAlive:
22+
connections: 100
23+
requests: 55
24+
time: 1m
25+
timeout: 5h
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: gateway.nginx.org/v1alpha1
2+
kind: UpstreamSettingsPolicy
3+
metadata:
4+
name: coffee-svc-usp-1
5+
spec:
6+
zoneSize: 64k
7+
targetRefs:
8+
- group: core
9+
kind: Service
10+
name: coffee
11+
---
12+
apiVersion: gateway.nginx.org/v1alpha1
13+
kind: UpstreamSettingsPolicy
14+
metadata:
15+
name: coffee-svc-usp-2
16+
spec:
17+
zoneSize: 128k
18+
targetRefs:
19+
- group: core
20+
kind: Service
21+
name: coffee

Diff for: tests/suite/manifests/upstream-settings-policy/valid-usps.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kind: UpstreamSettingsPolicy
1919
metadata:
2020
name: tea-multiple-svc-usp
2121
spec:
22-
zoneSize: 512k
22+
zoneSize: 128k
2323
targetRefs:
2424
- group: core
2525
kind: Service
@@ -28,10 +28,10 @@ spec:
2828
kind: Service
2929
name: coffee
3030
keepAlive:
31-
connections: 10
32-
requests: 3
33-
time: 10s
34-
timeout: 50s
31+
connections: 12
32+
requests: 31
33+
time: 20s
34+
timeout: 40s
3535
---
3636
apiVersion: gateway.nginx.org/v1alpha1
3737
kind: UpstreamSettingsPolicy

0 commit comments

Comments
 (0)