Skip to content

Commit

Permalink
remove executor pool
Browse files Browse the repository at this point in the history
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
  • Loading branch information
nikpivkin committed Nov 12, 2024
1 parent 29d4eb4 commit fff6927
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 138 deletions.
18 changes: 6 additions & 12 deletions pkg/iac/scanners/terraform/executor/executor.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package executor

import (
"context"
"fmt"
"runtime"
"sort"

"github.com/zclconf/go-cty/cty"
Expand Down Expand Up @@ -35,22 +35,16 @@ func New(options ...Option) *Executor {
return s
}

func (e *Executor) Execute(modules terraform.Modules) (scan.Results, error) {
func (e *Executor) Execute(ctx context.Context, modules terraform.Modules, basePath string) (scan.Results, error) {

e.logger.Debug("Adapting modules...")
infra := adapter.Adapt(modules)
e.logger.Debug("Adapted module(s) into state data.", log.Int("count", len(modules)))

threads := runtime.NumCPU()
if threads > 1 {
threads--
}

e.logger.Debug("Using max routines", log.Int("count", threads))

pool := NewPool(threads, modules, infra, e.regoScanner)

results, err := pool.Run()
results, err := e.regoScanner.ScanInput(ctx, rego.Input{
Contents: infra.ToRego(),
Path: basePath,
})
if err != nil {
return nil, err
}
Expand Down
124 changes: 0 additions & 124 deletions pkg/iac/scanners/terraform/executor/pool.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/iac/scanners/terraform/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func BenchmarkCalculate(b *testing.B) {
if err != nil {
b.Fatal(err)
}
executor.New().Execute(modules)
executor.New().Execute(context.TODO(), modules, "project")
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/iac/scanners/terraform/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *Scanner) ScanFS(ctx context.Context, target fs.FS, dir string) (scan.Re
s.execLock.RLock()
e := executor.New(s.executorOpt...)
s.execLock.RUnlock()
results, err := e.Execute(module.childs)
results, err := e.Execute(ctx, module.childs, module.rootPath)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit fff6927

Please sign in to comment.