@@ -201,6 +201,11 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
201
201
},
202
202
}),
203
203
Entry ("GRPC upstreams" , []framework.ExpectedNginxField {
204
+ {
205
+ Directive : "upstream" ,
206
+ Value : "uspolicy_grpc-backend_8080" ,
207
+ File : "http.conf" ,
208
+ },
204
209
{
205
210
Directive : "zone" ,
206
211
Value : "uspolicy_grpc-backend_8080 64k" ,
@@ -251,8 +256,8 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
251
256
252
257
DescribeTable ("upstreamSettingsPolicy status is set as expected" ,
253
258
func (name string , status metav1.ConditionStatus , condReason v1alpha2.PolicyConditionReason ) {
254
- nsname := types.NamespacedName {Name : name , Namespace : namespace }
255
- Expect (waitForUSPolicyStatus (nsname , gatewayName , status , condReason )).To (Succeed ())
259
+ uspolicyNsName := types.NamespacedName {Name : name , Namespace : namespace }
260
+ Expect (waitForUSPolicyStatus (uspolicyNsName , gatewayName , status , condReason )).To (Succeed ())
256
261
},
257
262
Entry ("uspolicy merge-usp-1" , "merge-usp-1" , metav1 .ConditionTrue , v1alpha2 .PolicyReasonAccepted ),
258
263
Entry ("uspolicy merge-usp-2" , "merge-usp-2" , metav1 .ConditionTrue , v1alpha2 .PolicyReasonAccepted ),
@@ -309,6 +314,11 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
309
314
}
310
315
},
311
316
Entry ("Coffee upstream" , []framework.ExpectedNginxField {
317
+ {
318
+ Directive : "upstream" ,
319
+ Value : "uspolicy_coffee_80" ,
320
+ File : "http.conf" ,
321
+ },
312
322
{
313
323
Directive : "zone" ,
314
324
Value : "uspolicy_coffee_80 512k" ,
@@ -347,23 +357,27 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
347
357
Upstream : "uspolicy_tea_80" ,
348
358
File : "http.conf" ,
349
359
},
360
+ {
361
+ Directive : "upstream" ,
362
+ Value : "uspolicy_tea_80" ,
363
+ File : "http.conf" ,
364
+ },
350
365
}),
351
366
)
352
367
})
353
368
})
354
369
355
- When ("UpstreamSettingsPolicy targets a Service that does not exists " , func () {
370
+ When ("UpstreamSettingsPolicy targets a Service that does not exist " , func () {
356
371
Specify ("upstreamSettingsPolicy sets no condition" , func () {
357
372
files := []string {"upstream-settings-policy/invalid-svc-usps.yaml" }
358
373
359
374
Expect (resourceManager .ApplyFromFiles (files , namespace )).To (Succeed ())
360
375
361
- nsname := types.NamespacedName {Name : "usps-target-not-found" , Namespace : namespace }
376
+ uspolicyNsName := types.NamespacedName {Name : "usps-target-not-found" , Namespace : namespace }
377
+
362
378
Consistently (
363
379
func () bool {
364
- return waitForUSPolicyToHaveAncestor (
365
- nsname ,
366
- ) != nil
380
+ return usPolicyHasNoAncestors (uspolicyNsName )
367
381
}).WithTimeout (timeoutConfig .GetTimeout ).
368
382
WithPolling (500 * time .Millisecond ).
369
383
Should (BeTrue ())
@@ -373,18 +387,18 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
373
387
})
374
388
375
389
When ("UpstreamSettingsPolicy targets a Service that is owned by an invalid Gateway" , func () {
376
- Specify ("upstreamSettingsPolicy has no condition set " , func () {
390
+ Specify ("upstreamSettingsPolicy is not Accepted with the reason TargetNotFound " , func () {
377
391
// delete existing gateway
378
392
gatewayFileName := "upstream-settings-policy/gateway.yaml"
379
393
Expect (resourceManager .DeleteFromFiles ([]string {gatewayFileName }, namespace )).To (Succeed ())
380
394
381
395
files := []string {"upstream-settings-policy/invalid-target-usps.yaml" }
382
396
Expect (resourceManager .ApplyFromFiles (files , namespace )).To (Succeed ())
383
397
384
- nsname := types.NamespacedName {Name : "soda-svc-usp" , Namespace : namespace }
398
+ uspolicyNsName := types.NamespacedName {Name : "soda-svc-usp" , Namespace : namespace }
385
399
gatewayName = "gateway-not-valid"
386
400
Expect (waitForUSPolicyStatus (
387
- nsname ,
401
+ uspolicyNsName ,
388
402
gatewayName ,
389
403
metav1 .ConditionFalse ,
390
404
v1alpha2 .PolicyReasonTargetNotFound ,
@@ -395,30 +409,19 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
395
409
})
396
410
})
397
411
398
- func waitForUSPolicyToHaveAncestor (usPolicyNsName types.NamespacedName ) error {
412
+ func usPolicyHasNoAncestors (usPolicyNsName types.NamespacedName ) bool {
413
+ GinkgoWriter .Printf ("Checking that UpstreamSettingsPolicy %q has no ancestors in status" , usPolicyNsName )
414
+
399
415
ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .GetStatusTimeout )
400
416
defer cancel ()
401
417
402
- GinkgoWriter .Printf ("Polling for UpstreamSettings Policy %q to not have a condition" , usPolicyNsName )
403
-
404
- return wait .PollUntilContextCancel (
405
- ctx ,
406
- timeoutConfig .GetStatusTimeout ,
407
- true , /* poll immediately */
408
- func (ctx context.Context ) (bool , error ) {
409
- var usPolicy ngfAPI.UpstreamSettingsPolicy
410
- var err error
411
- if err = k8sClient .Get (ctx , usPolicyNsName , & usPolicy ); err != nil {
412
- return false , err
413
- }
414
-
415
- if len (usPolicy .Status .Ancestors ) == 0 {
416
- return false , nil
417
- }
418
+ var usPolicy ngfAPI.UpstreamSettingsPolicy
419
+ if err := k8sClient .Get (ctx , usPolicyNsName , & usPolicy ); err != nil {
420
+ GinkgoWriter .Printf ("Failed to get UpstreamSettingsPolicy %q: %s" , usPolicyNsName , err .Error ())
421
+ return false
422
+ }
418
423
419
- return errors .Is (err , context .DeadlineExceeded ), nil
420
- },
421
- )
424
+ return len (usPolicy .Status .Ancestors ) == 0
422
425
}
423
426
424
427
func waitForUSPolicyStatus (
0 commit comments