RNode copier

This commit is contained in:
jregan
2020-08-21 17:58:26 -07:00
parent 9b4d4c9d46
commit 24beeb429d
4 changed files with 106 additions and 0 deletions

View File

@@ -12,6 +12,23 @@ import (
"sigs.k8s.io/kustomize/kyaml/sets"
)
// CopyYNode returns a distinct copy of its argument.
// Use https://github.com/jinzhu/copier instead?
func CopyYNode(n *yaml.Node) *yaml.Node {
if n == nil {
return nil
}
c := *n
if len(n.Content) > 0 {
// Using Go 'copy' here doesn't yield independent slices.
c.Content = make([]*Node, len(n.Content))
for i, item := range n.Content {
c.Content[i] = CopyYNode(item)
}
}
return &c
}
// IsYNodeTaggedNull returns true if the node is explicitly tagged Null.
func IsYNodeTaggedNull(n *yaml.Node) bool {
return n != nil && n.Tag == NodeTagNull