mirror of https://github.com/k3s-io/k3s
Merge pull request #229 from epicfilemcnulty/Skip-empty-yaml-objects
Do not process empty yaml objects (fixes #222)pull/244/head
commit
8649243d34
|
@ -251,6 +251,18 @@ func checksum(bytes []byte) string {
|
||||||
return hex.EncodeToString(d[:])
|
return hex.EncodeToString(d[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isEmptyYaml(yaml []byte) bool {
|
||||||
|
isEmpty := true
|
||||||
|
lines := bytes.Split(yaml, []byte("\n"))
|
||||||
|
for _, l := range lines {
|
||||||
|
s := bytes.TrimSpace(l)
|
||||||
|
if string(s) != "---" && !bytes.HasPrefix(s, []byte("#")) && string(s) != "" {
|
||||||
|
isEmpty = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
func yamlToObjects(in io.Reader) ([]runtime.Object, error) {
|
func yamlToObjects(in io.Reader) ([]runtime.Object, error) {
|
||||||
var result []runtime.Object
|
var result []runtime.Object
|
||||||
reader := yamlDecoder.NewYAMLReader(bufio.NewReaderSize(in, 4096))
|
reader := yamlDecoder.NewYAMLReader(bufio.NewReaderSize(in, 4096))
|
||||||
|
@ -263,12 +275,14 @@ func yamlToObjects(in io.Reader) ([]runtime.Object, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := toObjects(raw)
|
if !isEmptyYaml(raw) {
|
||||||
if err != nil {
|
obj, err := toObjects(raw)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
result = append(result, obj...)
|
result = append(result, obj...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
@ -279,6 +293,7 @@ func toObjects(bytes []byte) ([]runtime.Object, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, _, err := unstructured.UnstructuredJSONScheme.Decode(bytes, nil, nil)
|
obj, _, err := unstructured.UnstructuredJSONScheme.Decode(bytes, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue