@@ -3,6 +3,7 @@ package controller
33import (
44 "context"
55 "fmt"
6+ "math/rand"
67 "strings"
78 "time"
89
@@ -33,6 +34,8 @@ const (
3334
3435 // vulnerabilityJitter defines the random jitter duration added to vulnerability processing to prevent synchronized operations.
3536 vulnerabilityJitter = 2 * time .Minute
37+
38+ reportChunkSize = 15
3639)
3740
3841// VulnerabilityReportReconciler reconciles a Trivy VulnerabilityReport resource.
@@ -188,13 +191,18 @@ func (r *VulnerabilityReportReconciler) SetupWithManager(mgr ctrl.Manager) error
188191 err := helpers .BackgroundPollUntilContextCancel (r .Ctx , reportUploadInterval , false , true , func (_ context.Context ) (done bool , err error ) {
189192 if ! r .reports .IsEmpty () {
190193 apiReports := algorithms .Map (lo .Values (r .reports .Items ()), func (s console.VulnerabilityReportAttributes ) * console.VulnerabilityReportAttributes { return & s })
191- if _ , err := r .ConsoleClient .UpsertVulnerabilityReports (apiReports ); err != nil {
192- logger .Error (err , "unable to upsert vulnerability reports" )
193- } else {
194- // Clear the reports map and allow dangling elements to be garbage collected
195- r .reports .Clear ()
196- r .reports = cmap .New [console.VulnerabilityReportAttributes ]()
197- logger .Info ("upsert vulnerability reports" )
194+
195+ for _ , chunk := range lo .Chunk (apiReports , reportChunkSize ) {
196+ if _ , err := r .ConsoleClient .UpsertVulnerabilityReports (chunk ); err != nil {
197+ logger .Error (err , "unable to upsert vulnerability reports" )
198+ } else {
199+ // Clear the reports map and allow dangling elements to be garbage collected
200+ r .reports .Clear ()
201+ r .reports = cmap .New [console.VulnerabilityReportAttributes ]()
202+ logger .Info ("upsert vulnerability reports" )
203+ }
204+
205+ time .Sleep (time .Duration (rand .Int63n (int64 (500 * time .Millisecond ))))
198206 }
199207 }
200208 return false , nil
0 commit comments