Skip to content

Commit

Permalink
Merge pull request #20 from garethr/windows-multi-file
Browse files Browse the repository at this point in the history
Fix issue with multi-resource files on Windows
  • Loading branch information
garethr authored Aug 3, 2017
2 parents dd168ed + a7be7e1 commit d03fe25
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kubeval/kubeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strings"
"runtime"

"github.com/hashicorp/go-multierror"
"github.com/xeipuuv/gojsonschema"
Expand Down Expand Up @@ -37,6 +38,14 @@ type ValidationResult struct {
Errors []gojsonschema.ResultError
}

// lineBreak returns the relevant platform specific line ending
func lineBreak() string {
if runtime.GOOS == "windows" {
return "\r\n"
}
return "\n"
}

func determineSchema(kind string) string {
// We have both the upstream Kubernetes schemas and the OpenShift schemas available
// the tool can toggle between then using the --openshift boolean flag and here we
Expand Down Expand Up @@ -122,14 +131,14 @@ func Validate(config []byte, fileName string) ([]ValidationResult, error) {
return nil, errors.New("The document " + fileName + " appears to be empty")
}

bits := bytes.Split(config, []byte("---\n"))
bits := bytes.Split(config, []byte("---" + lineBreak()))

results := make([]ValidationResult, len(bits))
results := make([]ValidationResult, 0)
var errors *multierror.Error
for i, element := range bits {
for _, element := range bits {
if len(element) > 0 {
result, err := validateResource(element, fileName)
results[i] = result
results = append(results, result)
if err != nil {
errors = multierror.Append(errors, err)
}
Expand Down

0 comments on commit d03fe25

Please sign in to comment.