Skip to content

Commit

Permalink
Merge pull request #152 from kubescape/mem
Browse files Browse the repository at this point in the history
reduce memory preallocation for GetResourceExceptions
  • Loading branch information
matthyx authored Apr 25, 2024
2 parents d0cb0db + 4e34a54 commit 343b8c3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions exceptions/exceptionprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func alertObjectToWorkloads(obj *reporthandling.AlertObject) []workloadinterface

// GetResourceException get exceptions of single resource
func (p *Processor) GetResourceExceptions(ruleExceptions []armotypes.PostureExceptionPolicy, workload workloadinterface.IMetadata, clusterName string) []armotypes.PostureExceptionPolicy {
postureExceptionPolicy := make([]armotypes.PostureExceptionPolicy, 0, len(ruleExceptions))
// no pre-allocation since most of the time it's empty or has only one element
var postureExceptionPolicy []armotypes.PostureExceptionPolicy

for _, ruleException := range ruleExceptions {
for _, resourceToPin := range ruleException.Resources {
Expand All @@ -151,7 +152,7 @@ func (p *Processor) GetResourceExceptions(ruleExceptions []armotypes.PostureExce
}
}

return postureExceptionPolicy[:len(postureExceptionPolicy):len(postureExceptionPolicy)] // shrink capacity
return postureExceptionPolicy
}

// compareMetadata - compare namespace and kind
Expand Down

0 comments on commit 343b8c3

Please sign in to comment.