mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Make seq indent configurable and add retain seq indent functionality
This commit is contained in:
@@ -97,6 +97,7 @@ func (w ByteWriter) Write(inputNodes []*yaml.RNode) error {
|
||||
// don't wrap the elements
|
||||
if w.WrappingKind == "" {
|
||||
for i := range nodes {
|
||||
setSeqIndent(nodes[i], encoder)
|
||||
if err := encoder.Encode(nodes[i].Document()); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -134,6 +135,25 @@ func (w ByteWriter) Write(inputNodes []*yaml.RNode) error {
|
||||
return encoder.Encode(doc)
|
||||
}
|
||||
|
||||
// setSeqIndent reads the SeqIndentAnnotation from node and sets the sequence indentation
|
||||
// in the encoder
|
||||
// if the resource doesn't have SeqIndentAnnotation it will use CompactSeqIndent
|
||||
func setSeqIndent(node *yaml.RNode, encoder *yaml.Encoder) {
|
||||
anno := node.GetAnnotations()
|
||||
seqIndent := anno[kioutil.SeqIndentAnnotation]
|
||||
if seqIndent == yaml.WideSequenceStyle {
|
||||
encoder.DefaultSeqIndent()
|
||||
} else {
|
||||
encoder.CompactSeqIndent()
|
||||
}
|
||||
if err := node.PipeE(yaml.ClearAnnotation(kioutil.SeqIndentAnnotation)); err != nil {
|
||||
return
|
||||
}
|
||||
if err := yaml.ClearEmptyAnnotations(node); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func copyRNodes(in []*yaml.RNode) []*yaml.RNode {
|
||||
out := make([]*yaml.RNode, len(in))
|
||||
for i := range in {
|
||||
|
||||
Reference in New Issue
Block a user