Skip to content

Commit 722bf2a

Browse files
committed
add directives check
1 parent 6e267ea commit 722bf2a

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

Diff for: tests/suite/upstream_settings_test.go

+43-37
Original file line numberDiff line numberDiff line change
@@ -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,44 +357,53 @@ 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
})
353368
})
354369

355-
When("UpstreamSettingsPolicy targets a Service that does not exists", func() {
370+
When("UpstreamSettingsPolicy targets a Service that does not exist", func() {
356371
Specify("upstreamSettingsPolicy sets no condition", func() {
357372
files := []string{"upstream-settings-policy/invalid-svc-usps.yaml"}
358373

359374
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
360375

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())
370389

371390
Expect(resourceManager.DeleteFromFiles(files, namespace)).To(Succeed())
372391
})
373392
})
374393

375394
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() {
377396
// delete existing gateway
378397
gatewayFileName := "upstream-settings-policy/gateway.yaml"
379398
Expect(resourceManager.DeleteFromFiles([]string{gatewayFileName}, namespace)).To(Succeed())
380399

381400
files := []string{"upstream-settings-policy/invalid-target-usps.yaml"}
382401
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
383402

384-
nsname := types.NamespacedName{Name: "soda-svc-usp", Namespace: namespace}
403+
uspolicyNsName := types.NamespacedName{Name: "soda-svc-usp", Namespace: namespace}
385404
gatewayName = "gateway-not-valid"
386405
Expect(waitForUSPolicyStatus(
387-
nsname,
406+
uspolicyNsName,
388407
gatewayName,
389408
metav1.ConditionFalse,
390409
v1alpha2.PolicyReasonTargetNotFound,
@@ -395,30 +414,17 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
395414
})
396415
})
397416

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)
403419

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+
}
418426

419-
return errors.Is(err, context.DeadlineExceeded), nil
420-
},
421-
)
427+
return len(usPolicy.Status.Ancestors) != 0, nil
422428
}
423429

424430
func waitForUSPolicyStatus(

0 commit comments

Comments
 (0)