Don't consider empty array as "empty"

This commit is contained in:
Donny Xia
2020-07-10 16:54:07 -07:00
parent 5c3bd83252
commit 236ae29e9a
2 changed files with 10 additions and 5 deletions

View File

@@ -16,3 +16,8 @@ exclude (
github.com/russross/blackfriday v2.0.0+incompatible github.com/russross/blackfriday v2.0.0+incompatible
sigs.k8s.io/kustomize/api v0.2.0 sigs.k8s.io/kustomize/api v0.2.0
) )
replace (
sigs.k8s.io/kustomize/api => ../api
sigs.k8s.io/kustomize/kyaml => ../kyaml
)

View File

@@ -35,18 +35,18 @@ func IsMissingOrNull(node *RNode) bool {
} }
// IsEmpty returns true if the RNode is MissingOrNull, or is either a MappingNode with // IsEmpty returns true if the RNode is MissingOrNull, or is either a MappingNode with
// no fields, or a SequenceNode with no elements. // no fields.
func IsEmpty(node *RNode) bool { func IsEmpty(node *RNode) bool {
if node == nil || node.YNode() == nil || node.YNode().Tag == NullNodeTag { if IsMissingOrNull(node) {
return true return true
} }
// Empty sequence is a special case and temporarily not considered as empty here.
// Some users may want to keep empty sequence for compatibility reason.
// For example, use JSON 6902 patch.
if node.YNode().Kind == yaml.MappingNode && len(node.YNode().Content) == 0 { if node.YNode().Kind == yaml.MappingNode && len(node.YNode().Content) == 0 {
return true return true
} }
if node.YNode().Kind == yaml.SequenceNode && len(node.YNode().Content) == 0 {
return true
}
return false return false
} }