diff --git a/pkg/parser/fsreader.go b/pkg/parser/fsreader.go index a9c7cd40d..40bf2d404 100644 --- a/pkg/parser/fsreader.go +++ b/pkg/parser/fsreader.go @@ -119,12 +119,14 @@ func (r *FsReadCloser) Read(p []byte) (n int, err error) { r.index++ r.position = 0 r.wroteBreak = false + n = copy(p, "\n---\n") + return n, nil } if r.index == len(r.paths) { return 0, io.EOF } if r.writeBreak { - n = copy(p, "\n---\n") + n = copy(p, "\n...\n") r.writeBreak = false r.wroteBreak = true return n, nil diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index 13a3ea2ec..97bbf2b85 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -23,6 +23,7 @@ import ( "io" "io/ioutil" "strings" + "unicode" "github.com/pkg/errors" "github.com/spf13/afero" @@ -114,6 +115,18 @@ func (p *PackageParser) Parse(ctx context.Context, reader io.ReadCloser) (*Packa if err != nil { o, _, err := do.Decode(bytes, nil, nil) if err != nil { + empty := true + for _, b := range bytes { + if !unicode.IsSpace(rune(b)) { + empty = false + break + } + } + // If the YAML document only contains Unicode White Space we + // ignore and do not return an error. + if empty { + continue + } if anno, ok := reader.(AnnotatedReadCloser); ok { return pkg, errors.Wrap(err, fmt.Sprintf("%+v", anno.Annotate())) } diff --git a/pkg/parser/parser_test.go b/pkg/parser/parser_test.go index dc97c0cbf..e750996cf 100644 --- a/pkg/parser/parser_test.go +++ b/pkg/parser/parser_test.go @@ -35,6 +35,21 @@ var _ Parser = &PackageParser{} var ( crdBytes = []byte(`apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition +metadata: + name: test`) + + whitespaceBytes = []byte(`--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: test +--- + +--- + +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition metadata: name: test`) @@ -53,6 +68,7 @@ func TestParser(t *testing.T) { allBytes := bytes.Join([][]byte{crdBytes, deployBytes}, []byte("\n---\n")) fs := afero.NewMemMapFs() _ = afero.WriteFile(fs, "crd.yaml", crdBytes, 0o644) + _ = afero.WriteFile(fs, "whitespace.yaml", whitespaceBytes, 0o644) _ = afero.WriteFile(fs, "deployment.yaml", deployBytes, 0o644) _ = afero.WriteFile(fs, "some/nested/dir/crd.yaml", crdBytes, 0o644) _ = afero.WriteFile(fs, ".crossplane/bad.yaml", crdBytes, 0o644) @@ -109,7 +125,7 @@ func TestParser(t *testing.T) { backend: NewFsBackend(fs, FsDir("."), FsFilters(SkipDirs(), SkipNotYAML(), SkipPath(".crossplane/*"))), pkg: &Package{ meta: []runtime.Object{deploy}, - objects: []runtime.Object{crd, crd}, + objects: []runtime.Object{crd, crd, crd, crd}, }, }, "FsBackendAll": {