Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#1272 from justinsb/refactor_sp…
Browse files Browse the repository at this point in the history
…lityaml

Refactor: rewrite SplitYAML to be more conventional
  • Loading branch information
google-oss-prow[bot] authored Feb 21, 2024
2 parents 919e064 + 1177fcd commit 46a80be
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions operator/scripts/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ func SplitYAML(yamlBytes []byte) ([][]byte, error) {
r := bytes.NewReader(yamlBytes)
dec := goyaml.NewDecoder(r)
results := make([][]byte, 0)
var value map[string]interface{}
for eof := dec.Decode(&value); errors.Is(eof, io.EOF); eof = dec.Decode(&value) {
if eof != nil {
return nil, eof
for {
var value map[string]interface{}
err := dec.Decode(&value)
if err != nil {
if errors.Is(err, io.EOF) {
break
}
return nil, fmt.Errorf("error decoding yaml: %w", err)
}

bytes, err := goyaml.Marshal(value)
if err != nil {
return nil, fmt.Errorf("error marshalling '%v' to YAML: %w", value, err)
Expand Down

0 comments on commit 46a80be

Please sign in to comment.