Skip to content

Commit f8f86a5

Browse files
committed
update based on reviews
1 parent ab03f69 commit f8f86a5

File tree

9 files changed

+108
-116
lines changed

9 files changed

+108
-116
lines changed

tests/suite/manifests/snippets-filter/cafe-routes.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/suite/manifests/snippets-filter/cafe.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ spec:
9595
protocol: TCP
9696
name: http
9797
selector:
98-
app: soda
98+
app: soda

tests/suite/manifests/snippets-filter/gateway.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ spec:
99
port: 80
1010
protocol: HTTP
1111
hostname: "*.example.com"
12+

tests/suite/manifests/snippets-filter/grpc-backend.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ spec:
3737
resources:
3838
requests:
3939
cpu: 10m
40+

tests/suite/manifests/snippets-filter/grpc-route.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/suite/manifests/snippets-filter/invalid-context-sf.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
- context: http
88
value: aio on;
99
- context: http.server
10-
value: wrker_priority 0; # wrong context for the directive, should be main.
10+
value: worker_priority 0; # wrong context for the directive, should be main.
1111
- context: http.server.location
1212
value: keepalive_time 10s;
1313
---
@@ -34,4 +34,4 @@ spec:
3434
name: invalid-context
3535
backendRefs:
3636
- name: soda
37-
port: 80
37+
port: 80

tests/suite/manifests/snippets-filter/invalid-duplicate-sf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ spec:
3636
name: duplicate-directive
3737
backendRefs:
3838
- name: tea
39-
port: 80
39+
port: 80

tests/suite/manifests/snippets-filter/valid-sf.yaml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,52 @@ spec:
2626
- context: http.server
2727
value: server_tokens on;
2828
- context: http.server.location
29-
value: tcp_nodelay on;
29+
value: tcp_nodelay on;
30+
---
31+
apiVersion: gateway.networking.k8s.io/v1
32+
kind: HTTPRoute
33+
metadata:
34+
name: coffee
35+
spec:
36+
parentRefs:
37+
- name: gateway
38+
sectionName: http
39+
hostnames:
40+
- "cafe.example.com"
41+
rules:
42+
- matches:
43+
- path:
44+
type: PathPrefix
45+
value: /coffee
46+
filters:
47+
- type: ExtensionRef
48+
extensionRef:
49+
group: gateway.nginx.org
50+
kind: SnippetsFilter
51+
name: all-contexts
52+
backendRefs:
53+
- name: coffee
54+
port: 80
55+
---
56+
apiVersion: gateway.networking.k8s.io/v1
57+
kind: GRPCRoute
58+
metadata:
59+
name: grpc-route
60+
spec:
61+
parentRefs:
62+
- name: gateway
63+
sectionName: http
64+
rules:
65+
- matches:
66+
- method:
67+
service: helloworld.Greeter
68+
method: SayHello
69+
filters:
70+
- type: ExtensionRef
71+
extensionRef:
72+
group: gateway.nginx.org
73+
kind: SnippetsFilter
74+
name: grpc-all-contexts
75+
backendRefs:
76+
- name: grpc-backend
77+
port: 8080

tests/suite/snippets_filter_test.go

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,12 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
4949
})
5050

5151
When("SnippetsFilters are applied to the resources", func() {
52-
var (
53-
snippetsFilter = []string{
54-
"snippets-filter/valid-sf.yaml",
55-
}
56-
baseURL string
57-
)
52+
snippetsFilter := []string{
53+
"snippets-filter/valid-sf.yaml",
54+
}
5855

5956
BeforeAll(func() {
6057
Expect(resourceManager.ApplyFromFiles(snippetsFilter, namespace)).To(Succeed())
61-
62-
port := 80
63-
if portFwdPort != 0 {
64-
port = portFwdPort
65-
}
66-
baseURL = fmt.Sprintf("http://cafe.example.com:%d%s", port, "/coffee")
6758
})
6859

6960
AfterAll(func() {
@@ -86,22 +77,33 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
8677

8778
Context("verify working traffic", func() {
8879
It("should return a 200 response for HTTPRoute", func() {
80+
port := 80
81+
if portFwdPort != 0 {
82+
port = portFwdPort
83+
}
84+
baseURL := fmt.Sprintf("http://cafe.example.com:%d%s", port, "/coffee")
85+
8986
Eventually(
9087
func() error {
9188
return expectRequestToSucceed(baseURL, address, "URI: /coffee")
9289
}).
93-
WithTimeout(timeoutConfig.CreateTimeout).
94-
WithPolling(5 * time.Second).
90+
WithTimeout(timeoutConfig.RequestTimeout).
91+
WithPolling(500 * time.Millisecond).
9592
Should(Succeed())
9693
})
9794
})
9895

9996
Context("nginx directives", func() {
10097
var conf *framework.Payload
101-
snippetsFilterPrefix := "SnippetsFilter_"
102-
filePrefix := "/etc/nginx/includes/"
103-
httpRoutePrefix := fmt.Sprintf("%s_all-contexts.conf", namespace)
104-
grpcRoutePrefix := fmt.Sprintf("%s_grpc-all-contexts.conf", namespace)
98+
snippetsFilterFilePrefix := "/etc/nginx/includes/SnippetsFilter_"
99+
100+
mainContext := fmt.Sprintf("%ssmain_", snippetsFilterFilePrefix)
101+
httpContext := fmt.Sprintf("%shttp_", snippetsFilterFilePrefix)
102+
httpServerContext := fmt.Sprintf("%shttp.server_", snippetsFilterFilePrefix)
103+
httpServerLocationContext := fmt.Sprintf("%shttp.server.location_", snippetsFilterFilePrefix)
104+
105+
httpRouteSuffix := fmt.Sprintf("%s_all-contexts.conf", namespace)
106+
grpcRouteSuffix := fmt.Sprintf("%s_grpc-all-contexts.conf", namespace)
105107

106108
BeforeAll(func() {
107109
podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
@@ -121,70 +123,70 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
121123
}
122124
},
123125
Entry("HTTPRoute", []framework.ExpectedNginxField{
126+
{
127+
Directive: "worker_priority",
128+
Value: "0",
129+
File: fmt.Sprintf("%s%s", mainContext, httpRouteSuffix),
130+
},
124131
{
125132
Directive: "aio",
126133
Value: "on",
127-
File: fmt.Sprintf("%s%shttp_%s", filePrefix, snippetsFilterPrefix, httpRoutePrefix),
134+
File: fmt.Sprintf("%s%s", httpContext, httpRouteSuffix),
128135
},
129136
{
130137
Directive: "auth_delay",
131138
Value: "10s",
132-
File: fmt.Sprintf("%s%shttp.server_%s", filePrefix, snippetsFilterPrefix, httpRoutePrefix),
133-
},
134-
{
135-
Directive: "keepalive_time",
136-
Value: "10s",
137-
File: fmt.Sprintf("%s%shttp.server.location_%s", filePrefix, snippetsFilterPrefix, httpRoutePrefix),
138-
},
139-
{
140-
Directive: "worker_priority",
141-
Value: "0",
142-
File: fmt.Sprintf("%s%smain_%s", filePrefix, snippetsFilterPrefix, httpRoutePrefix),
139+
File: fmt.Sprintf("%s%s", httpServerContext, httpRouteSuffix),
143140
},
144141
{
145142
Directive: "include",
146-
Value: fmt.Sprintf("%s%shttp.server_%s", filePrefix, snippetsFilterPrefix, httpRoutePrefix),
143+
Value: fmt.Sprintf("%s%s", httpServerContext, httpRouteSuffix),
147144
Servers: []string{"cafe.example.com"},
148145
File: "http.conf",
149146
},
150147
{
151148
Directive: "include",
152-
Value: fmt.Sprintf("%s%shttp.server.location_%s", filePrefix, snippetsFilterPrefix, httpRoutePrefix),
149+
Value: fmt.Sprintf("%s%s", httpServerLocationContext, httpRouteSuffix),
153150
File: "http.conf",
154151
Location: "/coffee",
155152
Servers: []string{"cafe.example.com"},
156153
},
154+
{
155+
Directive: "keepalive_time",
156+
Value: "10s",
157+
File: fmt.Sprintf("%s%s", httpServerLocationContext, httpRouteSuffix),
158+
},
157159
}),
158160
Entry("GRPCRoute", []framework.ExpectedNginxField{
159161
{
160162
Directive: "worker_shutdown_timeout",
161163
Value: "120s",
162-
File: fmt.Sprintf("%s%smain_%s", filePrefix, snippetsFilterPrefix, grpcRoutePrefix),
164+
File: fmt.Sprintf("%s%s", mainContext, grpcRouteSuffix),
163165
},
164166
{
165167
Directive: "types_hash_bucket_size",
166168
Value: "64",
167-
File: fmt.Sprintf("%s%shttp_%s", filePrefix, snippetsFilterPrefix, grpcRoutePrefix),
169+
File: fmt.Sprintf("%s%s", httpContext, grpcRouteSuffix),
168170
},
169171
{
170172
Directive: "server_tokens",
171173
Value: "on",
172-
File: fmt.Sprintf("%s%shttp.server_%s", filePrefix, snippetsFilterPrefix, grpcRoutePrefix),
174+
File: fmt.Sprintf("%s%s", httpServerContext, grpcRouteSuffix),
173175
},
174176
{
175177
Directive: "tcp_nodelay",
176178
Value: "on",
177-
File: fmt.Sprintf("%s%shttp.server.location_%s", filePrefix, snippetsFilterPrefix, grpcRoutePrefix),
179+
File: fmt.Sprintf("%s%s", httpServerLocationContext, grpcRouteSuffix),
178180
},
179181
{
180182
Directive: "include",
181-
Value: fmt.Sprintf("%s%shttp.server_%s", filePrefix, snippetsFilterPrefix, grpcRoutePrefix),
183+
Value: fmt.Sprintf("%s%s", httpServerContext, grpcRouteSuffix),
182184
Servers: []string{"*.example.com"},
183185
File: "http.conf",
184186
},
185187
{
186188
Directive: "include",
187-
Value: fmt.Sprintf("%s%shttp.server.location_%s", filePrefix, snippetsFilterPrefix, grpcRoutePrefix),
189+
Value: fmt.Sprintf("%s%s", httpServerLocationContext, grpcRouteSuffix),
188190
File: "http.conf",
189191
Location: "/helloworld.Greeter/SayHello",
190192
Servers: []string{"*.example.com"},
@@ -219,19 +221,15 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
219221
})
220222
})
221223

222-
func waitForHTTPRouteToHaveGatewayNotProgrammedCond(httpRouteNsNames types.NamespacedName) error {
223-
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.CreateTimeout*2)
224+
func waitForHTTPRouteToHaveGatewayNotProgrammedCond(httpRouteNsName types.NamespacedName) error {
225+
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetStatusTimeout)
224226
defer cancel()
225227

226228
GinkgoWriter.Printf(
227229
"Waiting for HTTPRoute %q to have the condition Accepted/True/GatewayNotProgrammed\n",
228-
httpRouteNsNames,
230+
httpRouteNsName,
229231
)
230232

231-
return waitForHTTPRouteStatus(ctx, httpRouteNsNames)
232-
}
233-
234-
func waitForHTTPRouteStatus(ctx context.Context, httpRouteNsNames types.NamespacedName) error {
235233
return wait.PollUntilContextCancel(
236234
ctx,
237235
time.Second*3,
@@ -240,12 +238,12 @@ func waitForHTTPRouteStatus(ctx context.Context, httpRouteNsNames types.Namespac
240238
var hr v1.HTTPRoute
241239
var err error
242240

243-
if err = k8sClient.Get(ctx, httpRouteNsNames, &hr); err != nil {
241+
if err = k8sClient.Get(ctx, httpRouteNsName, &hr); err != nil {
244242
return false, err
245243
}
246244

247245
if len(hr.Status.Parents) == 0 {
248-
GinkgoWriter.Printf("HTTPRoute %q does not have a status yet\n", httpRouteNsNames)
246+
GinkgoWriter.Printf("HTTPRoute %q does not have a status yet\n", httpRouteNsName)
249247

250248
return false, nil
251249
}
@@ -285,20 +283,6 @@ func waitForSnippetsFilterToBeAccepted(snippetsFilterNsNames types.NamespacedNam
285283
snippetsFilterNsNames,
286284
)
287285

288-
return waitForSnippetsFilterStatus(
289-
ctx,
290-
snippetsFilterNsNames,
291-
metav1.ConditionTrue,
292-
ngfAPI.SnippetsFilterConditionReasonAccepted,
293-
)
294-
}
295-
296-
func waitForSnippetsFilterStatus(
297-
ctx context.Context,
298-
snippetsFilterNsNames types.NamespacedName,
299-
condStatus metav1.ConditionStatus,
300-
condReason ngfAPI.SnippetsFilterConditionReason,
301-
) error {
302286
return wait.PollUntilContextCancel(
303287
ctx,
304288
1000*time.Millisecond,
@@ -331,12 +315,16 @@ func waitForSnippetsFilterStatus(
331315
return false, fmt.Errorf("expected condition type to be Accepted, got %s", condition.Type)
332316
}
333317

334-
if status.Conditions[0].Status != condStatus {
335-
return false, fmt.Errorf("expected condition status to be %s, got %s", condStatus, condition.Status)
318+
if status.Conditions[0].Status != metav1.ConditionTrue {
319+
return false, fmt.Errorf("expected condition status to be %s, got %s", metav1.ConditionTrue, condition.Status)
336320
}
337321

338-
if status.Conditions[0].Reason != string(condReason) {
339-
return false, fmt.Errorf("expected condition reason to be %s, got %s", condReason, condition.Reason)
322+
if status.Conditions[0].Reason != string(ngfAPI.SnippetsFilterConditionReasonAccepted) {
323+
return false, fmt.Errorf(
324+
"expected condition reason to be %s, got %s",
325+
ngfAPI.SnippetsFilterConditionReasonAccepted,
326+
condition.Reason,
327+
)
340328
}
341329

342330
return err == nil, err

0 commit comments

Comments
 (0)