@@ -201,6 +201,11 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
201201 },
202202 }),
203203 Entry ("GRPC upstreams" , []framework.ExpectedNginxField {
204+ {
205+ Directive : "upstream" ,
206+ Value : "uspolicy_grpc-backend_8080" ,
207+ File : "http.conf" ,
208+ },
204209 {
205210 Directive : "zone" ,
206211 Value : "uspolicy_grpc-backend_8080 64k" ,
@@ -251,8 +256,8 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
251256
252257 DescribeTable ("upstreamSettingsPolicy status is set as expected" ,
253258 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 ())
256261 },
257262 Entry ("uspolicy merge-usp-1" , "merge-usp-1" , metav1 .ConditionTrue , v1alpha2 .PolicyReasonAccepted ),
258263 Entry ("uspolicy merge-usp-2" , "merge-usp-2" , metav1 .ConditionTrue , v1alpha2 .PolicyReasonAccepted ),
@@ -309,6 +314,11 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
309314 }
310315 },
311316 Entry ("Coffee upstream" , []framework.ExpectedNginxField {
317+ {
318+ Directive : "upstream" ,
319+ Value : "uspolicy_coffee_80" ,
320+ File : "http.conf" ,
321+ },
312322 {
313323 Directive : "zone" ,
314324 Value : "uspolicy_coffee_80 512k" ,
@@ -347,6 +357,11 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
347357 Upstream : "uspolicy_tea_80" ,
348358 File : "http.conf" ,
349359 },
360+ {
361+ Directive : "upstream" ,
362+ Value : "uspolicy_tea_80" ,
363+ File : "http.conf" ,
364+ },
350365 }),
351366 )
352367 })
@@ -358,12 +373,10 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
358373
359374 Expect (resourceManager .ApplyFromFiles (files , namespace )).To (Succeed ())
360375
361- nsname := types.NamespacedName {Name : "usps-target-not-found" , Namespace : namespace }
376+ uspolicyNsName := types.NamespacedName {Name : "usps-target-not-found" , Namespace : namespace }
362377 Consistently (
363378 func () bool {
364- return waitForUSPolicyToHaveAncestor (
365- nsname ,
366- ) != nil
379+ return USPolicyHasNoAncestors (uspolicyNsName )
367380 }).WithTimeout (timeoutConfig .GetTimeout ).
368381 WithPolling (500 * time .Millisecond ).
369382 Should (BeTrue ())
@@ -373,18 +386,18 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
373386 })
374387
375388 When ("UpstreamSettingsPolicy targets a Service that is owned by an invalid Gateway" , func () {
376- Specify ("upstreamSettingsPolicy has no condition set " , func () {
389+ Specify ("upstreamSettingsPolicy is not Accepted with the reason TargetNotFound " , func () {
377390 // delete existing gateway
378391 gatewayFileName := "upstream-settings-policy/gateway.yaml"
379392 Expect (resourceManager .DeleteFromFiles ([]string {gatewayFileName }, namespace )).To (Succeed ())
380393
381394 files := []string {"upstream-settings-policy/invalid-target-usps.yaml" }
382395 Expect (resourceManager .ApplyFromFiles (files , namespace )).To (Succeed ())
383396
384- nsname := types.NamespacedName {Name : "soda-svc-usp" , Namespace : namespace }
397+ uspolicyNsName := types.NamespacedName {Name : "soda-svc-usp" , Namespace : namespace }
385398 gatewayName = "gateway-not-valid"
386399 Expect (waitForUSPolicyStatus (
387- nsname ,
400+ uspolicyNsName ,
388401 gatewayName ,
389402 metav1 .ConditionFalse ,
390403 v1alpha2 .PolicyReasonTargetNotFound ,
@@ -395,30 +408,20 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
395408 })
396409})
397410
398- func waitForUSPolicyToHaveAncestor (usPolicyNsName types.NamespacedName ) error {
411+ func USPolicyHasNoAncestors (usPolicyNsName types.NamespacedName ) bool {
412+ GinkgoWriter .Printf ("Checking that UpstreamSettingsPolicy %q has no ancestors in status\n " , usPolicyNsName )
413+
399414 ctx , cancel := context .WithTimeout (context .Background (), timeoutConfig .GetStatusTimeout )
400415 defer cancel ()
401416
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- }
417+ var usPolicy ngfAPI.UpstreamSettingsPolicy
418+ var err error
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+ }
418423
419- return errors .Is (err , context .DeadlineExceeded ), nil
420- },
421- )
424+ return len (usPolicy .Status .Ancestors ) == 0
422425}
423426
424427func waitForUSPolicyStatus (
0 commit comments