mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +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 {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ metadata:
|
|||
`),
|
||||
},
|
||||
Status: validator.Valid,
|
||||
Err: nil,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
`{
|
||||
|
|
@ -71,9 +71,8 @@ metadata:
|
|||
`),
|
||||
},
|
||||
Status: validator.Valid,
|
||||
Err: nil,
|
||||
Err: nil,
|
||||
},
|
||||
|
||||
},
|
||||
`{
|
||||
"resources": [
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ metadata:
|
|||
`),
|
||||
},
|
||||
Status: validator.Valid,
|
||||
Err: nil,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
"Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0\n",
|
||||
|
|
@ -61,9 +61,8 @@ metadata:
|
|||
`),
|
||||
},
|
||||
Status: validator.Valid,
|
||||
Err: nil,
|
||||
Err: nil,
|
||||
},
|
||||
|
||||
},
|
||||
`deployment.yml - Deployment my-app is valid
|
||||
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue