mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-19 18:07:02 +00:00
move file finding to own function
This commit is contained in:
parent
c82866923c
commit
7db0febbd1
1 changed files with 39 additions and 36 deletions
75
main.go
75
main.go
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/xeipuuv/gojsonschema"
|
"github.com/xeipuuv/gojsonschema"
|
||||||
|
"github.com/yannh/kubeconform/pkg/fsutils"
|
||||||
"github.com/yannh/kubeconform/pkg/output"
|
"github.com/yannh/kubeconform/pkg/output"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -14,7 +15,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/yannh/kubeconform/pkg/cache"
|
"github.com/yannh/kubeconform/pkg/cache"
|
||||||
"github.com/yannh/kubeconform/pkg/fsutils"
|
|
||||||
"github.com/yannh/kubeconform/pkg/registry"
|
"github.com/yannh/kubeconform/pkg/registry"
|
||||||
"github.com/yannh/kubeconform/pkg/resource"
|
"github.com/yannh/kubeconform/pkg/resource"
|
||||||
"github.com/yannh/kubeconform/pkg/validator"
|
"github.com/yannh/kubeconform/pkg/validator"
|
||||||
|
|
@ -177,6 +177,43 @@ func processResults(o output.Output, validationResults chan []validationResult,
|
||||||
result <- success
|
result <- success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFiles(files []string, fileBatches chan []string, validationResults chan []validationResult) {
|
||||||
|
for _, filename := range files {
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
validationResults <- []validationResult{{
|
||||||
|
filename: filename,
|
||||||
|
err: err,
|
||||||
|
skipped: false,
|
||||||
|
}}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
fi, err := file.Stat()
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
validationResults <- []validationResult{{
|
||||||
|
filename: filename,
|
||||||
|
err: err,
|
||||||
|
skipped: false,
|
||||||
|
}}
|
||||||
|
|
||||||
|
case fi.IsDir():
|
||||||
|
if err := fsutils.FindYamlInDir(filename, fileBatches, 10); err != nil {
|
||||||
|
validationResults <- []validationResult{{
|
||||||
|
filename: filename,
|
||||||
|
err: err,
|
||||||
|
skipped: false,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
fileBatches <- []string{filename}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func realMain() int {
|
func realMain() int {
|
||||||
var schemas arrayParam
|
var schemas arrayParam
|
||||||
var skipKindsCSV, k8sVersion, outputFormat string
|
var skipKindsCSV, k8sVersion, outputFormat string
|
||||||
|
|
@ -221,41 +258,7 @@ func realMain() int {
|
||||||
|
|
||||||
fileBatches := make(chan []string)
|
fileBatches := make(chan []string)
|
||||||
go func() {
|
go func() {
|
||||||
for _, filename := range files {
|
getFiles(files, fileBatches, validationResults)
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
validationResults <- []validationResult{{
|
|
||||||
filename: filename,
|
|
||||||
err: err,
|
|
||||||
skipped: false,
|
|
||||||
}}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
fi, err := file.Stat()
|
|
||||||
switch {
|
|
||||||
case err != nil:
|
|
||||||
validationResults <- []validationResult{{
|
|
||||||
filename: filename,
|
|
||||||
err: err,
|
|
||||||
skipped: false,
|
|
||||||
}}
|
|
||||||
|
|
||||||
case fi.IsDir():
|
|
||||||
if err := fsutils.FindYamlInDir(filename, fileBatches, 10); err != nil {
|
|
||||||
validationResults <- []validationResult{{
|
|
||||||
filename: filename,
|
|
||||||
err: err,
|
|
||||||
skipped: false,
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
fileBatches <- []string{filename}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fileBatches)
|
close(fileBatches)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue