Skip to content
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

lock auditor caching #199

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auditor/auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (a *Auditor) auditAllResourcesAndSendData(constraintIds []string, triggerTy
if len(errs) > 0 {
logger.Errorw("error while getting all resources", "error", errs)
}

for _, resources := range resourcesByGvrk {
for idx := range resources {
resource := resources[idx]
Expand Down
5 changes: 5 additions & 0 deletions auditor/opa-auditor/opa-auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package opa_auditor

import (
"fmt"
"sync"
"time"

"github.com/MagalixCorp/magalix-agent/v3/agent"
Expand All @@ -17,6 +18,8 @@ const (
PolicyQuery = "violation"
)

var lock sync.Mutex

type Template struct {
Id string
Name string
Expand Down Expand Up @@ -186,6 +189,8 @@ func (a *OpaAuditor) CheckResourceStatusWithConstraint(constraintId string, reso
return !found || oldStatus != currentStatus
}
func (a *OpaAuditor) UpdateCache(results []*agent.AuditResult) {
lock.Lock()
defer lock.Unlock()
for i := range results {
result := results[i]
namespace := ""
Expand Down