mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-16 08:27:01 +00:00
Small clean-up
This commit is contained in:
parent
b571b18f8d
commit
ab4745ddf0
3 changed files with 10 additions and 7 deletions
|
|
@ -244,7 +244,7 @@ resetCacheFolder() {
|
||||||
[ "${lines[2]}" == '1..1' ]
|
[ "${lines[2]}" == '1..1' ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Pass when parsing a file containing multiple a List" {
|
@test "Pass when parsing a file containing a List" {
|
||||||
run bin/kubeconform -summary fixtures/list_valid.yaml
|
run bin/kubeconform -summary fixtures/list_valid.yaml
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "Summary: 6 resources found in 1 file - Valid: 6, Invalid: 0, Errors: 0, Skipped: 0" ]
|
[ "$output" = "Summary: 6 resources found in 1 file - Valid: 6, Invalid: 0, Errors: 0, Skipped: 0" ]
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,11 @@ func findFilesInFolders(ctx context.Context, paths []string, ignoreFilePatterns
|
||||||
}
|
}
|
||||||
|
|
||||||
func findResourcesInReader(p string, f io.Reader, resources chan<- Resource, errors chan<- error, buf []byte) {
|
func findResourcesInReader(p string, f io.Reader, resources chan<- Resource, errors chan<- error, buf []byte) {
|
||||||
|
maxBufSize := 256 * 1024 * 1024
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
// We start with a buf that is 4MB, scanner will resize it up to 256MB if needed
|
// We start with a buf that is 4MB, scanner will resize it up to 256MB if needed
|
||||||
// https://github.com/golang/go/blob/aeea5bacbf79fb945edbeac6cd7630dd70c4d9ce/src/bufio/scan.go#L191
|
// https://github.com/golang/go/blob/aeea5bacbf79fb945edbeac6cd7630dd70c4d9ce/src/bufio/scan.go#L191
|
||||||
scanner.Buffer(buf, 256*1024*1024)
|
scanner.Buffer(buf, maxBufSize)
|
||||||
scanner.Split(SplitYAMLDocument)
|
scanner.Split(SplitYAMLDocument)
|
||||||
nRes := 0
|
nRes := 0
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
|
@ -129,8 +130,8 @@ func FromFiles(ctx context.Context, paths []string, ignoreFilePatterns []string)
|
||||||
files, errors := findFilesInFolders(ctx, paths, ignoreFilePatterns)
|
files, errors := findFilesInFolders(ctx, paths, ignoreFilePatterns)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
maxResourceSize := 4 * 1024 * 1024 // This is the initial size - scanner will resize if needed
|
initialBufSize := 4 * 1024 * 1024 // This is the initial size - scanner will resize if needed
|
||||||
buf := make([]byte, maxResourceSize) // We reuse the same buffer to avoid multiple large memory allocations
|
buf := make([]byte, initialBufSize) // We reuse the same buffer to avoid multiple large memory allocations
|
||||||
|
|
||||||
for p := range files {
|
for p := range files {
|
||||||
findResourcesInFile(p, resources, errors, buf)
|
findResourcesInFile(p, resources, errors, buf)
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,12 @@ func FromStream(ctx context.Context, path string, r io.Reader) (<-chan Resource,
|
||||||
errors := make(chan error)
|
errors := make(chan error)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
const initialBufSize = 4 * 1024 * 1024 // Start with 4MB
|
||||||
|
const maxBufSize = 256 * 1024 * 1024 // Start with 4MB
|
||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
const maxResourceSize = 4 * 1024 * 1024 // Start with 4MB
|
buf := make([]byte, initialBufSize)
|
||||||
buf := make([]byte, maxResourceSize)
|
scanner.Buffer(buf, maxBufSize) // Resize up to 256MB
|
||||||
scanner.Buffer(buf, 256*1024*1024) // Resize up to 256MB
|
|
||||||
scanner.Split(SplitYAMLDocument)
|
scanner.Split(SplitYAMLDocument)
|
||||||
|
|
||||||
SCAN:
|
SCAN:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue