From 3f69ffbc358e432ee10c1dafc5aae4049c6df7ff Mon Sep 17 00:00:00 2001 From: Kevin Fan Date: Tue, 7 May 2024 16:40:03 +0100 Subject: [PATCH] fix: isAuthPolicyEnforcedCondition failing in eventually (#629) The test "Route and Gateway AuthPolicies exist. Gateway AuthPolicy updated to remove overrides." is flaky since isAuthPolicyEnforcedCondition preveiously was not a function that can be executed continuously in an Eventually block so sometimes the AuthPolicy may not be enforced by the time the condition is checked. Since previously it was only checked once, it will always timeout even if the AuthPolicy eventually transitions to the expected status condition. Changing the function to return func() bool should fix this. --- controllers/authpolicy_controller_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/controllers/authpolicy_controller_test.go b/controllers/authpolicy_controller_test.go index 33b72d60c..2bba584c5 100644 --- a/controllers/authpolicy_controller_test.go +++ b/controllers/authpolicy_controller_test.go @@ -2044,18 +2044,20 @@ func isAuthPolicyEnforced(ctx context.Context, policy *api.AuthPolicy) func() bo return isAuthPolicyConditionTrue(ctx, policy, string(kuadrant.PolicyConditionEnforced)) } -func isAuthPolicyEnforcedCondition(ctx context.Context, key client.ObjectKey, reason gatewayapiv1alpha2.PolicyConditionReason, message string) bool { - p := &api.AuthPolicy{} - if err := k8sClient.Get(ctx, key, p); err != nil { - return false - } +func isAuthPolicyEnforcedCondition(ctx context.Context, key client.ObjectKey, reason gatewayapiv1alpha2.PolicyConditionReason, message string) func() bool { + return func() bool { + p := &api.AuthPolicy{} + if err := k8sClient.Get(ctx, key, p); err != nil { + return false + } - cond := meta.FindStatusCondition(p.Status.Conditions, string(kuadrant.PolicyConditionEnforced)) - if cond == nil { - return false - } + cond := meta.FindStatusCondition(p.Status.Conditions, string(kuadrant.PolicyConditionEnforced)) + if cond == nil { + return false + } - return cond.Reason == string(reason) && cond.Message == message + return cond.Reason == string(reason) && cond.Message == message + } } func isAuthPolicyConditionTrue(ctx context.Context, policy *api.AuthPolicy, condition string) func() bool {