Skip to content

Commit

Permalink
fix: isAuthPolicyEnforcedCondition failing in eventually (#629)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KevFan authored May 7, 2024
1 parent c12bce9 commit 3f69ffb
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3f69ffb

Please sign in to comment.