-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return early if the AuthPolicy being filtered is marked for deletion #632
Return early if the AuthPolicy being filtered is marked for deletion #632
Conversation
controllers/authpolicy_authconfig.go
Outdated
affectedPolicies = utils.Filter(affectedPolicies, func(policy kuadrantgatewayapi.Policy) bool { | ||
p, ok := policy.(*api.AuthPolicy) | ||
if !ok { | ||
return false | ||
} | ||
if p.DeletionTimestamp != nil { | ||
return false | ||
} | ||
return kuadrantgatewayapi.IsTargetRefGateway(policy.GetTargetRef()) && | ||
ap.GetUID() != policy.GetUID() && p.IsAtomicOverride() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ap.GetUID() != policy.GetUID() && p.IsAtomicOverride() | |
ap.GetUID() != policy.GetUID() && p.IsAtomicOverride() && p.DeletionTimestamp == nil |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did have it that way to start. My reasoning for not doing it was why do the extra function calls when it can return early if there is a deletion time stamp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it the first condition then?
ap.GetUID() != policy.GetUID() && p.IsAtomicOverride() | |
return p.DeletionTimestamp == nil && | |
kuadrantgatewayapi.IsTargetRefGateway(policy.GetTargetRef()) && | |
ap.GetUID() != policy.GetUID() && | |
p.IsAtomicOverride() |
I'm usually in favour of safeguard clauses but in this case where the return is straightforward, the less if
s the better, no? In fact, if really we want to push it:
ap.GetUID() != policy.GetUID() && p.IsAtomicOverride() | |
return ok && | |
p.DeletionTimestamp == nil && | |
kuadrantgatewayapi.IsTargetRefGateway(policy.GetTargetRef()) && | |
ap.GetUID() != policy.GetUID() && | |
p.IsAtomicOverride() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving the ok
check here makes more sense also. I am kinda unsure about the readability, personally I don't like to have logic in return statements. It makes using a debugger harder. But in this case this might be the cleaner option.
Improves filter function and returns early when searching for AuthPolicies attached to the Gateway.