Skip to content

Commit

Permalink
chore: cleanup duplicated filter logic
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Pan <[email protected]>
  • Loading branch information
panpan0000 committed May 16, 2023
1 parent 493c684 commit 3816bc5
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions pkg/analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,41 +154,25 @@ func (a *Analysis) RunAnalysis() {
wg.Wait()
return
}
semaphore = make(chan struct{}, a.MaxConcurrency)
var filtersCandidate []string
// if the filters flag is specified
if len(a.Filters) != 0 {
var wg sync.WaitGroup
var mutex sync.Mutex
for _, filter := range a.Filters {
if analyzer, ok := analyzerMap[filter]; ok {
semaphore <- struct{}{}
wg.Add(1)
go func(analyzer common.IAnalyzer, filter string) {
defer wg.Done()
results, err := analyzer.Analyze(analyzerConfig)
if err != nil {
mutex.Lock()
a.Errors = append(a.Errors, fmt.Sprintf("[%s] %s", filter, err))
mutex.Unlock()
}
mutex.Lock()
a.Results = append(a.Results, results...)
mutex.Unlock()
<-semaphore
}(analyzer, filter)
if _, ok := analyzerMap[filter]; ok {
filtersCandidate = append(filtersCandidate, filter)
} else {
a.Errors = append(a.Errors, fmt.Sprintf("\"%s\" filter does not exist. Please run k8sgpt filters list.", filter))
}
}
wg.Wait()
return
} else {
filtersCandidate = activeFilters
}

var wg sync.WaitGroup
var mutex sync.Mutex
semaphore = make(chan struct{}, a.MaxConcurrency)
// use active_filters
for _, filter := range activeFilters {
// filtersCandidate = active_filters (if any) + filters flag (if any)
for _, filter := range filtersCandidate {
if analyzer, ok := analyzerMap[filter]; ok {
semaphore <- struct{}{}
wg.Add(1)
Expand Down

0 comments on commit 3816bc5

Please sign in to comment.