mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Kyaml api cleanup
This commit is contained in:
@@ -176,12 +176,6 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) {
|
|||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEmptyDocument(node *yaml.Node) bool {
|
|
||||||
// node is a Document with no content -- e.g. "---\n---"
|
|
||||||
return node.Kind == yaml.DocumentNode &&
|
|
||||||
node.Content[0].Tag == yaml.NodeTagNull
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ByteReader) decode(index int, decoder *yaml.Decoder) (*yaml.RNode, error) {
|
func (r *ByteReader) decode(index int, decoder *yaml.Decoder) (*yaml.RNode, error) {
|
||||||
node := &yaml.Node{}
|
node := &yaml.Node{}
|
||||||
err := decoder.Decode(node)
|
err := decoder.Decode(node)
|
||||||
@@ -192,7 +186,7 @@ func (r *ByteReader) decode(index int, decoder *yaml.Decoder) (*yaml.RNode, erro
|
|||||||
return nil, errors.Wrap(err)
|
return nil, errors.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isEmptyDocument(node) {
|
if yaml.IsYNodeEmptyDoc(node) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func MakeNullNode() *RNode {
|
|||||||
|
|
||||||
// IsMissingOrNull returns true if the RNode is nil or contains and explicitly null value.
|
// IsMissingOrNull returns true if the RNode is nil or contains and explicitly null value.
|
||||||
func IsMissingOrNull(node *RNode) bool {
|
func IsMissingOrNull(node *RNode) bool {
|
||||||
return node == nil || node.YNode() == nil || node.YNode().Tag == NodeTagNull
|
return IsNil(node) || node.YNode().Tag == NodeTagNull
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEmpty returns true if the RNode is MissingOrNull
|
// IsEmpty returns true if the RNode is MissingOrNull
|
||||||
@@ -48,12 +48,16 @@ func IsEmptyMap(node *RNode) bool {
|
|||||||
if IsEmpty(node) {
|
if IsEmpty(node) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
return IsYNodeEmptyMap(node.YNode())
|
||||||
|
}
|
||||||
|
|
||||||
return node.YNode().Kind == yaml.MappingNode && len(node.YNode().Content) == 0
|
// IsNil return true if the node is nil, or its underlying YNode is nil.
|
||||||
|
func IsNil(node *RNode) bool {
|
||||||
|
return node == nil || node.YNode() == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsNull(node *RNode) bool {
|
func IsNull(node *RNode) bool {
|
||||||
return node != nil && node.YNode() != nil && node.YNode().Tag == NodeTagNull
|
return !IsNil(node) && node.YNode().Tag == NodeTagNull
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsFieldEmpty(node *MapNode) bool {
|
func IsFieldEmpty(node *MapNode) bool {
|
||||||
@@ -61,15 +65,26 @@ func IsFieldEmpty(node *MapNode) bool {
|
|||||||
node.Value.YNode().Tag == NodeTagNull {
|
node.Value.YNode().Tag == NodeTagNull {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
return IsYNodeEmptyMap(node.Value.YNode()) ||
|
||||||
if node.Value.YNode().Kind == yaml.MappingNode && len(node.Value.YNode().Content) == 0 {
|
IsYNodeEmptySeq(node.Value.YNode())
|
||||||
return true
|
|
||||||
}
|
|
||||||
if node.Value.YNode().Kind == yaml.SequenceNode && len(node.Value.YNode().Content) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
func IsYNodeEmptyMap(n *yaml.Node) bool {
|
||||||
|
return n.Kind == yaml.MappingNode && len(n.Content) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsYNodeEmptySeq(n *yaml.Node) bool {
|
||||||
|
return n.Kind == yaml.SequenceNode && len(n.Content) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsYNodeEmptyDoc is true if the node is a Document with no content.
|
||||||
|
// E.g.: "---\n---"
|
||||||
|
func IsYNodeEmptyDoc(n *yaml.Node) bool {
|
||||||
|
return n.Kind == yaml.DocumentNode && n.Content[0].Tag == NodeTagNull
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsYNodeString(n *yaml.Node) bool {
|
||||||
|
return n.Kind == yaml.ScalarNode && n.Tag == NodeTagString
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValue returns underlying yaml.Node Value field
|
// GetValue returns underlying yaml.Node Value field
|
||||||
|
|||||||
Reference in New Issue
Block a user