mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 22:19:25 +00:00
make logging non-concurrent, remove mutexes from output pkg
This commit is contained in:
parent
05da409a0a
commit
d94b0abf64
2 changed files with 20 additions and 9 deletions
25
main.go
25
main.go
|
|
@ -21,9 +21,9 @@ import (
|
|||
)
|
||||
|
||||
type validationResult struct {
|
||||
kind, version string
|
||||
err error
|
||||
skipped bool
|
||||
filename, kind, version string
|
||||
err error
|
||||
skipped bool
|
||||
}
|
||||
|
||||
// filter returns true if the file should be skipped
|
||||
|
|
@ -171,6 +171,18 @@ func realMain() int {
|
|||
close(fileBatches)
|
||||
}()
|
||||
|
||||
validationResults := make(chan []validationResult)
|
||||
var logWG sync.WaitGroup
|
||||
logWG.Add(1)
|
||||
go func() {
|
||||
defer logWG.Done()
|
||||
for results := range validationResults {
|
||||
for _, result := range results {
|
||||
o.Write(result.filename, result.kind, result.version, result.err, result.skipped)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
c := cache.NewSchemaCache()
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < nWorkers; i++ {
|
||||
|
|
@ -189,9 +201,10 @@ func realMain() int {
|
|||
res := validateFile(f, registries, k8sVersion, c, filter)
|
||||
f.Close()
|
||||
|
||||
for _, resourceValidation := range res {
|
||||
o.Write(filename, resourceValidation.kind, resourceValidation.version, resourceValidation.err, resourceValidation.skipped)
|
||||
for i, _ := range res {
|
||||
res[i].filename = filename
|
||||
}
|
||||
validationResults <- res
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
@ -199,6 +212,8 @@ func realMain() int {
|
|||
|
||||
wg.Wait()
|
||||
o.Flush()
|
||||
close(validationResults)
|
||||
logWG.Wait()
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package output
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type result struct {
|
||||
|
|
@ -15,7 +14,6 @@ type result struct {
|
|||
}
|
||||
|
||||
type JSONOutput struct {
|
||||
sync.Mutex
|
||||
withSummary bool
|
||||
quiet bool
|
||||
results []result
|
||||
|
|
@ -35,8 +33,6 @@ func NewJSONOutput(withSummary bool, quiet bool) Output {
|
|||
}
|
||||
|
||||
func (o *JSONOutput) Write(filename, kind, version string, err error, skipped bool) {
|
||||
o.Lock()
|
||||
defer o.Unlock()
|
||||
msg, st := "", ""
|
||||
|
||||
s := status(err, skipped)
|
||||
|
|
|
|||
Loading…
Reference in a new issue