@@ -49,21 +49,12 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
49
49
})
50
50
51
51
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
+ }
58
55
59
56
BeforeAll (func () {
60
57
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" )
67
58
})
68
59
69
60
AfterAll (func () {
@@ -86,22 +77,33 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
86
77
87
78
Context ("verify working traffic" , func () {
88
79
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
+
89
86
Eventually (
90
87
func () error {
91
88
return expectRequestToSucceed (baseURL , address , "URI: /coffee" )
92
89
}).
93
- WithTimeout (timeoutConfig .CreateTimeout ).
94
- WithPolling (5 * time .Second ).
90
+ WithTimeout (timeoutConfig .RequestTimeout ).
91
+ WithPolling (500 * time .Millisecond ).
95
92
Should (Succeed ())
96
93
})
97
94
})
98
95
99
96
Context ("nginx directives" , func () {
100
97
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 )
105
107
106
108
BeforeAll (func () {
107
109
podNames , err := framework .GetReadyNGFPodNames (k8sClient , ngfNamespace , releaseName , timeoutConfig .GetTimeout )
@@ -121,70 +123,70 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
121
123
}
122
124
},
123
125
Entry ("HTTPRoute" , []framework.ExpectedNginxField {
126
+ {
127
+ Directive : "worker_priority" ,
128
+ Value : "0" ,
129
+ File : fmt .Sprintf ("%s%s" , mainContext , httpRouteSuffix ),
130
+ },
124
131
{
125
132
Directive : "aio" ,
126
133
Value : "on" ,
127
- File : fmt .Sprintf ("%s%shttp_% s" , filePrefix , snippetsFilterPrefix , httpRoutePrefix ),
134
+ File : fmt .Sprintf ("%s%s" , httpContext , httpRouteSuffix ),
128
135
},
129
136
{
130
137
Directive : "auth_delay" ,
131
138
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 ),
143
140
},
144
141
{
145
142
Directive : "include" ,
146
- Value : fmt .Sprintf ("%s%shttp.server_% s" , filePrefix , snippetsFilterPrefix , httpRoutePrefix ),
143
+ Value : fmt .Sprintf ("%s%s" , httpServerContext , httpRouteSuffix ),
147
144
Servers : []string {"cafe.example.com" },
148
145
File : "http.conf" ,
149
146
},
150
147
{
151
148
Directive : "include" ,
152
- Value : fmt .Sprintf ("%s%shttp.server.location_% s" , filePrefix , snippetsFilterPrefix , httpRoutePrefix ),
149
+ Value : fmt .Sprintf ("%s%s" , httpServerLocationContext , httpRouteSuffix ),
153
150
File : "http.conf" ,
154
151
Location : "/coffee" ,
155
152
Servers : []string {"cafe.example.com" },
156
153
},
154
+ {
155
+ Directive : "keepalive_time" ,
156
+ Value : "10s" ,
157
+ File : fmt .Sprintf ("%s%s" , httpServerLocationContext , httpRouteSuffix ),
158
+ },
157
159
}),
158
160
Entry ("GRPCRoute" , []framework.ExpectedNginxField {
159
161
{
160
162
Directive : "worker_shutdown_timeout" ,
161
163
Value : "120s" ,
162
- File : fmt .Sprintf ("%s%smain_% s" , filePrefix , snippetsFilterPrefix , grpcRoutePrefix ),
164
+ File : fmt .Sprintf ("%s%s" , mainContext , grpcRouteSuffix ),
163
165
},
164
166
{
165
167
Directive : "types_hash_bucket_size" ,
166
168
Value : "64" ,
167
- File : fmt .Sprintf ("%s%shttp_% s" , filePrefix , snippetsFilterPrefix , grpcRoutePrefix ),
169
+ File : fmt .Sprintf ("%s%s" , httpContext , grpcRouteSuffix ),
168
170
},
169
171
{
170
172
Directive : "server_tokens" ,
171
173
Value : "on" ,
172
- File : fmt .Sprintf ("%s%shttp.server_% s" , filePrefix , snippetsFilterPrefix , grpcRoutePrefix ),
174
+ File : fmt .Sprintf ("%s%s" , httpServerContext , grpcRouteSuffix ),
173
175
},
174
176
{
175
177
Directive : "tcp_nodelay" ,
176
178
Value : "on" ,
177
- File : fmt .Sprintf ("%s%shttp.server.location_% s" , filePrefix , snippetsFilterPrefix , grpcRoutePrefix ),
179
+ File : fmt .Sprintf ("%s%s" , httpServerLocationContext , grpcRouteSuffix ),
178
180
},
179
181
{
180
182
Directive : "include" ,
181
- Value : fmt .Sprintf ("%s%shttp.server_% s" , filePrefix , snippetsFilterPrefix , grpcRoutePrefix ),
183
+ Value : fmt .Sprintf ("%s%s" , httpServerContext , grpcRouteSuffix ),
182
184
Servers : []string {"*.example.com" },
183
185
File : "http.conf" ,
184
186
},
185
187
{
186
188
Directive : "include" ,
187
- Value : fmt .Sprintf ("%s%shttp.server.location_% s" , filePrefix , snippetsFilterPrefix , grpcRoutePrefix ),
189
+ Value : fmt .Sprintf ("%s%s" , httpServerLocationContext , grpcRouteSuffix ),
188
190
File : "http.conf" ,
189
191
Location : "/helloworld.Greeter/SayHello" ,
190
192
Servers : []string {"*.example.com" },
@@ -219,19 +221,15 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
219
221
})
220
222
})
221
223
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 )
224
226
defer cancel ()
225
227
226
228
GinkgoWriter .Printf (
227
229
"Waiting for HTTPRoute %q to have the condition Accepted/True/GatewayNotProgrammed\n " ,
228
- httpRouteNsNames ,
230
+ httpRouteNsName ,
229
231
)
230
232
231
- return waitForHTTPRouteStatus (ctx , httpRouteNsNames )
232
- }
233
-
234
- func waitForHTTPRouteStatus (ctx context.Context , httpRouteNsNames types.NamespacedName ) error {
235
233
return wait .PollUntilContextCancel (
236
234
ctx ,
237
235
time .Second * 3 ,
@@ -240,12 +238,12 @@ func waitForHTTPRouteStatus(ctx context.Context, httpRouteNsNames types.Namespac
240
238
var hr v1.HTTPRoute
241
239
var err error
242
240
243
- if err = k8sClient .Get (ctx , httpRouteNsNames , & hr ); err != nil {
241
+ if err = k8sClient .Get (ctx , httpRouteNsName , & hr ); err != nil {
244
242
return false , err
245
243
}
246
244
247
245
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 )
249
247
250
248
return false , nil
251
249
}
@@ -285,20 +283,6 @@ func waitForSnippetsFilterToBeAccepted(snippetsFilterNsNames types.NamespacedNam
285
283
snippetsFilterNsNames ,
286
284
)
287
285
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 {
302
286
return wait .PollUntilContextCancel (
303
287
ctx ,
304
288
1000 * time .Millisecond ,
@@ -331,12 +315,16 @@ func waitForSnippetsFilterStatus(
331
315
return false , fmt .Errorf ("expected condition type to be Accepted, got %s" , condition .Type )
332
316
}
333
317
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 )
336
320
}
337
321
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
+ )
340
328
}
341
329
342
330
return err == nil , err
0 commit comments