From 7ae2d3646b9ce27b2d1faa5934e73c07446281be Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Fri, 7 Mar 2025 17:39:38 +0100 Subject: [PATCH] override default worker pool size with KUBESCAPE_WORKERS Signed-off-by: Matthias Bertschy --- core/pkg/hostsensorutils/hostsensorworkerpool.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/pkg/hostsensorutils/hostsensorworkerpool.go b/core/pkg/hostsensorutils/hostsensorworkerpool.go index 22b94e1d..4ed58836 100644 --- a/core/pkg/hostsensorutils/hostsensorworkerpool.go +++ b/core/pkg/hostsensorutils/hostsensorworkerpool.go @@ -6,6 +6,7 @@ import ( "github.com/kubescape/go-logger" "github.com/kubescape/go-logger/helpers" + "github.com/kubescape/kubescape/v3/core/cautils" "github.com/kubescape/opa-utils/objectsenvelopes/hostsensor" ) @@ -27,18 +28,19 @@ type workerPool struct { func newWorkerPool() workerPool { wp := workerPool{} - wp.noOfWorkers = noOfWorkers + wp.noOfWorkers, _ = cautils.ParseIntEnvVar("KUBESCAPE_WORKERS", noOfWorkers) wp.init() return wp } func (wp *workerPool) init(noOfPods ...int) { - if len(noOfPods) > 0 && noOfPods[0] < noOfWorkers { + if len(noOfPods) > 0 && noOfPods[0] < wp.noOfWorkers { wp.noOfWorkers = noOfPods[0] } + logger.L().Debug("Initializing worker pool", helpers.Int("noOfWorkers", wp.noOfWorkers)) // init the channels - wp.jobs = make(chan job, noOfWorkers) - wp.results = make(chan hostsensor.HostSensorDataEnvelope, noOfWorkers) + wp.jobs = make(chan job, wp.noOfWorkers) + wp.results = make(chan hostsensor.HostSensorDataEnvelope, wp.noOfWorkers) wp.done = make(chan bool) } @@ -57,7 +59,7 @@ func (wp *workerPool) hostSensorWorker(ctx context.Context, hsh *HostSensorHandl } func (wp *workerPool) createWorkerPool(ctx context.Context, hsh *HostSensorHandler, wg *sync.WaitGroup, log *LogsMap) { - for i := 0; i < noOfWorkers; i++ { + for i := 0; i < wp.noOfWorkers; i++ { wg.Add(1) go wp.hostSensorWorker(ctx, hsh, wg, log) }