@@ -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,44 +357,53 @@ 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 }
362
- Consistently (
363
- func () bool {
364
- return waitForUSPolicyToHaveAncestor (
365
- nsname ,
366
- ) != nil
367
- }).WithTimeout (timeoutConfig .GetTimeout ).
368
- WithPolling (500 * time .Millisecond ).
369
- Should (BeTrue ())
376
+ uspolicyNsName := types.NamespacedName {Name : "usps-target-not-found" , Namespace : namespace }
377
+ ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .GetStatusTimeout )
378
+ defer cancel ()
379
+
380
+ err := wait .PollUntilContextCancel (
381
+ ctx ,
382
+ 1000 * time .Millisecond ,
383
+ true , /* poll immediately */
384
+ func (ctx context.Context ) (bool , error ) {
385
+ return usPolicyHasNoAncestors (ctx , uspolicyNsName )
386
+ })
387
+
388
+ Expect (errors .Is (err , context .DeadlineExceeded )).To (BeTrue ())
370
389
371
390
Expect (resourceManager .DeleteFromFiles (files , namespace )).To (Succeed ())
372
391
})
373
392
})
374
393
375
394
When ("UpstreamSettingsPolicy targets a Service that is owned by an invalid Gateway" , func () {
376
- Specify ("upstreamSettingsPolicy has no condition set " , func () {
395
+ Specify ("upstreamSettingsPolicy is not Accepted with the reason TargetNotFound " , func () {
377
396
// delete existing gateway
378
397
gatewayFileName := "upstream-settings-policy/gateway.yaml"
379
398
Expect (resourceManager .DeleteFromFiles ([]string {gatewayFileName }, namespace )).To (Succeed ())
380
399
381
400
files := []string {"upstream-settings-policy/invalid-target-usps.yaml" }
382
401
Expect (resourceManager .ApplyFromFiles (files , namespace )).To (Succeed ())
383
402
384
- nsname := types.NamespacedName {Name : "soda-svc-usp" , Namespace : namespace }
403
+ uspolicyNsName := types.NamespacedName {Name : "soda-svc-usp" , Namespace : namespace }
385
404
gatewayName = "gateway-not-valid"
386
405
Expect (waitForUSPolicyStatus (
387
- nsname ,
406
+ uspolicyNsName ,
388
407
gatewayName ,
389
408
metav1 .ConditionFalse ,
390
409
v1alpha2 .PolicyReasonTargetNotFound ,
@@ -395,30 +414,17 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
395
414
})
396
415
})
397
416
398
- func waitForUSPolicyToHaveAncestor (usPolicyNsName types.NamespacedName ) error {
399
- ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .GetStatusTimeout )
400
- defer cancel ()
401
-
402
- GinkgoWriter .Printf ("Polling for UpstreamSettings Policy %q to not have a condition" , usPolicyNsName )
417
+ func usPolicyHasNoAncestors (ctx context.Context , usPolicyNsName types.NamespacedName ) (bool , error ) {
418
+ GinkgoWriter .Printf ("Checking that UpstreamSettingsPolicy %q has no ancestors in status\n " , usPolicyNsName )
403
419
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
- }
420
+ var usPolicy ngfAPI.UpstreamSettingsPolicy
421
+ var err error
422
+ if err = k8sClient .Get (ctx , usPolicyNsName , & usPolicy ); err != nil {
423
+ GinkgoWriter .Printf ("Failed to get UpstreamSettingsPolicy %q: %s" , usPolicyNsName , err .Error ())
424
+ return false , err
425
+ }
418
426
419
- return errors .Is (err , context .DeadlineExceeded ), nil
420
- },
421
- )
427
+ return len (usPolicy .Status .Ancestors ) != 0 , nil
422
428
}
423
429
424
430
func waitForUSPolicyStatus (
0 commit comments