mirror of
https://github.com/yannh/kubeconform.git
synced 2026-04-12 07:44:17 +00:00
use different pattern for processResults
This commit is contained in:
parent
81c097f1bb
commit
dfb80055fe
3 changed files with 24 additions and 19 deletions
|
|
@ -85,18 +85,26 @@ func ValidateResources(resources <-chan resource.Resource, validationResults cha
|
|||
}
|
||||
}
|
||||
|
||||
func processResults(o output.Output, validationResults <-chan validator.Result, result chan<- bool) {
|
||||
func processResults(o output.Output, validationResults <-chan validator.Result) <-chan bool {
|
||||
success := true
|
||||
for res := range validationResults {
|
||||
if res.Err != nil {
|
||||
success = false
|
||||
}
|
||||
if err := o.Write(res); err != nil {
|
||||
fmt.Fprint(os.Stderr, "failed writing log\n")
|
||||
}
|
||||
}
|
||||
result := make(chan bool)
|
||||
|
||||
result <- success
|
||||
go func() {
|
||||
for res := range validationResults {
|
||||
if res.Status == validator.Error || res.Status == validator.Invalid {
|
||||
success = false
|
||||
}
|
||||
if o != nil {
|
||||
if err := o.Write(res); err != nil {
|
||||
fmt.Fprint(os.Stderr, "failed writing log\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
result <- success
|
||||
close(result)
|
||||
}()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func realMain() int {
|
||||
|
|
@ -135,9 +143,8 @@ func realMain() int {
|
|||
var resourcesChan <-chan resource.Resource
|
||||
var errors <-chan error
|
||||
validationResults := make(chan validator.Result)
|
||||
res := make(chan bool)
|
||||
|
||||
go processResults(o, validationResults, res)
|
||||
successChan := processResults(o, validationResults)
|
||||
|
||||
if isStdin {
|
||||
resourcesChan, errors = resource.FromStream("stdin", os.Stdin)
|
||||
|
|
@ -170,7 +177,7 @@ func realMain() int {
|
|||
wg.Wait()
|
||||
|
||||
close(validationResults)
|
||||
success := <-res
|
||||
success := <-successChan
|
||||
o.Flush()
|
||||
|
||||
if !success {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue