From 9062703d41222df9e7de0fe24ac12a74494b9507 Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Thu, 24 Oct 2024 14:37:44 +0100 Subject: [PATCH] fix: Authorino race condition Signed-off-by: Michael Nairn --- .../kuadrant/apimachinery_status_conditions.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/library/kuadrant/apimachinery_status_conditions.go b/pkg/library/kuadrant/apimachinery_status_conditions.go index 6c98f4bf8..4f605b14f 100644 --- a/pkg/library/kuadrant/apimachinery_status_conditions.go +++ b/pkg/library/kuadrant/apimachinery_status_conditions.go @@ -55,17 +55,28 @@ func (o *AffectedPolicyMap) RemoveAffectedPolicy(p Policy) { // IsPolicyAffected checks if the provided Policy is affected based on the tracking map maintained. func (o *AffectedPolicyMap) IsPolicyAffected(p Policy) bool { + o.mu.Lock() + defer o.mu.Unlock() + return o.policies[p.GetUID()] != nil } // IsPolicyOverridden checks if the provided Policy is affected based on the tracking map maintained. // It is overridden if there is policies affecting it func (o *AffectedPolicyMap) IsPolicyOverridden(p Policy) bool { - return o.IsPolicyAffected(p) && len(o.policies[p.GetUID()]) > 0 + pAffected := o.IsPolicyAffected(p) + + o.mu.Lock() + defer o.mu.Unlock() + + return pAffected && len(o.policies[p.GetUID()]) > 0 } // PolicyAffectedBy returns the clients keys that a policy is Affected by func (o *AffectedPolicyMap) PolicyAffectedBy(p Policy) []client.ObjectKey { + o.mu.Lock() + defer o.mu.Unlock() + return o.policies[p.GetUID()] }