Also read up to 256MB from stdin

This commit is contained in:
Yann Hamon 2021-09-26 17:45:27 +02:00
parent 4a8aace275
commit b5c823d6b5
3 changed files with 10 additions and 4 deletions

View file

@ -293,4 +293,10 @@ resetCacheFolder() {
run bin/kubeconform -summary fixtures/valid_large.yaml
[ "$status" -eq 0 ]
[ "$output" = 'Summary: 100000 resources found in 1 file - Valid: 100000, Invalid: 0, Errors: 0, Skipped: 0' ]
}
}
@test "Should support very long streams from stdin" {
run bash -c "cat fixtures/valid_large.yaml | bin/kubeconform -summary"
[ "$status" -eq 0 ]
[ "$output" = 'Summary: 100000 resources found parsing stdin - Valid: 100000, Invalid: 0, Errors: 0, Skipped: 0' ]
}

View file

@ -91,7 +91,7 @@ func findResourcesInReader(p string, f io.Reader, resources chan<- Resource, err
scanner := bufio.NewScanner(f)
// 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
scanner.Buffer(buf, 256*1024*1024*1024)
scanner.Buffer(buf, 256*1024*1024)
scanner.Split(SplitYAMLDocument)
nRes := 0
for scanner.Scan() {

View file

@ -48,9 +48,9 @@ func FromStream(ctx context.Context, path string, r io.Reader) (<-chan Resource,
go func() {
scanner := bufio.NewScanner(r)
const maxResourceSize = 4 * 1024 * 1024 // 4MB ought to be enough for everybody
const maxResourceSize = 4 * 1024 * 1024 // Start with 4MB
buf := make([]byte, maxResourceSize)
scanner.Buffer(buf, maxResourceSize)
scanner.Buffer(buf, 256*1024*1024) // Resize up to 256MB
scanner.Split(SplitYAMLDocument)
SCAN: