Skip to content

Commit

Permalink
fix concurrent map write in trivy analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
michael12312 committed Jul 19, 2024
1 parent 391a3cd commit 8437018
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/integration/trivy/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package trivy
import (
"fmt"
"strings"
"sync"

ctrl "sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -29,12 +30,16 @@ type TrivyAnalyzer struct {
configAuditReportAnalysis bool
}

var l sync.RWMutex

func (TrivyAnalyzer) analyzeVulnerabilityReports(a common.Analyzer) ([]common.Result, error) {
// Get all trivy VulnerabilityReports
result := &v1alpha1.VulnerabilityReportList{}

client := a.Client.CtrlClient
l.Lock()
err := v1alpha1.AddToScheme(client.Scheme())
l.Unlock()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -89,7 +94,9 @@ func (t TrivyAnalyzer) analyzeConfigAuditReports(a common.Analyzer) ([]common.Re
result := &v1alpha1.ConfigAuditReportList{}

client := a.Client.CtrlClient
l.Lock()
err := v1alpha1.AddToScheme(client.Scheme())
l.Unlock()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 8437018

Please sign in to comment.