Skip to content

Commit

Permalink
Do not process empty yaml objects (fixes #222)
Browse files Browse the repository at this point in the history
  • Loading branch information
epicfilemcnulty committed Mar 14, 2019
1 parent dc91c48 commit 567532d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions pkg/deploy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ func checksum(bytes []byte) string {
return hex.EncodeToString(d[:])
}

func isEmptyYaml(yaml []byte) bool {
isEmpty := true
lines := bytes.Split(yaml, []byte("\n"))
for _, k := range lines {
if string(k) != "---" && !bytes.HasPrefix(k, []byte("#")) && string(k) != "" {
isEmpty = false
}
}
return isEmpty
}

func yamlToObjects(in io.Reader) ([]runtime.Object, error) {
var result []runtime.Object
reader := yamlDecoder.NewYAMLReader(bufio.NewReaderSize(in, 4096))
Expand All @@ -263,12 +274,14 @@ func yamlToObjects(in io.Reader) ([]runtime.Object, error) {
return nil, err
}

obj, err := toObjects(raw)
if err != nil {
return nil, err
}
if !isEmptyYaml(raw) {
obj, err := toObjects(raw)
if err != nil {
return nil, err
}

result = append(result, obj...)
result = append(result, obj...)
}
}

return result, nil
Expand All @@ -279,6 +292,7 @@ func toObjects(bytes []byte) ([]runtime.Object, error) {
if err != nil {
return nil, err
}

obj, _, err := unstructured.UnstructuredJSONScheme.Decode(bytes, nil, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit 567532d

Please sign in to comment.