Skip to content

Commit

Permalink
refactor: override logic and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KevFan committed Apr 19, 2024
1 parent 155c69f commit 721e1cd
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 276 deletions.
2 changes: 1 addition & 1 deletion controllers/authpolicy_authconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *AuthPolicyReconciler) desiredAuthConfig(ctx context.Context, ap *api.Au
if ok {
logger.V(1).Info("targeted gateway has authpolicy with atomic overrides, skipping authorino authconfig for the HTTPRoute authpolicy")
utils.TagObjectToDelete(authConfig)
r.OverriddenPolicyMap.SetOverriddenPolicy(ap)
r.OverriddenPolicyMap.SetOverriddenPolicy(ap, []client.ObjectKey{})
return authConfig, nil
}
route = obj
Expand Down
4 changes: 2 additions & 2 deletions controllers/authpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *AuthPolicyReconciler) enforcedCondition(ctx context.Context, policy *ap
// Introducing a goroutine in this flow could break this assumption and lead to unexpected behavior.
if r.OverriddenPolicyMap.IsPolicyOverridden(policy) {
logger.V(1).Info("Gateway Policy is overridden")
return r.handleGatewayPolicyOverride(logger, policy, targetNetworkObject)
return r.handleGatewayPolicyOverride(policy, targetNetworkObject)
}

// Check if the AuthConfig is ready
Expand Down Expand Up @@ -131,7 +131,7 @@ func (r *AuthPolicyReconciler) isAuthConfigReady(ctx context.Context, policy *ap

// handleGatewayPolicyOverride handles the case where the Gateway Policy is overridden by filtering policy references
// and creating a corresponding error condition.
func (r *AuthPolicyReconciler) handleGatewayPolicyOverride(logger logr.Logger, policy *api.AuthPolicy, targetNetworkObject client.Object) *metav1.Condition {
func (r *AuthPolicyReconciler) handleGatewayPolicyOverride(policy *api.AuthPolicy, targetNetworkObject client.Object) *metav1.Condition {
obj := targetNetworkObject.(*gatewayapiv1.Gateway)
gatewayWrapper := kuadrant.GatewayWrapper{Gateway: obj, Referrer: policy}
refs := gatewayWrapper.PolicyRefs()
Expand Down
25 changes: 15 additions & 10 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ func testRLPIsEnforced(rlpKey client.ObjectKey) func() bool {
return testRLPIsConditionTrue(rlpKey, string(kuadrant.PolicyConditionEnforced))
}

func testRLPEnforcedCondition(rlpKey client.ObjectKey, reason gatewayapiv1alpha2.PolicyConditionReason, message string) bool {
p := &kuadrantv1beta2.RateLimitPolicy{}
if err := k8sClient.Get(context.Background(), rlpKey, p); err != 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
}

func testRLPIsNotAccepted(rlpKey client.ObjectKey) func() bool {
return func() bool {
existingRLP := &kuadrantv1beta2.RateLimitPolicy{}
Expand All @@ -424,16 +438,7 @@ func testRLPIsConditionTrue(rlpKey client.ObjectKey, condition string) func() bo
return func() bool {
existingRLP := &kuadrantv1beta2.RateLimitPolicy{}
err := k8sClient.Get(context.Background(), rlpKey, existingRLP)
if err != nil {
logf.Log.V(1).Info("ratelimitpolicy not read", "rlp", rlpKey, "error", err)
return false
}
if !meta.IsStatusConditionTrue(existingRLP.Status.Conditions, condition) {
logf.Log.V(1).Info("ratelimitpolicy not available", "rlp", rlpKey)
return false
}

return true
return err == nil && meta.IsStatusConditionTrue(existingRLP.Status.Conditions, condition)
}
}

Expand Down
Loading

0 comments on commit 721e1cd

Please sign in to comment.